diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/CONTRIBUTING.md b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/CONTRIBUTING.md index 1d3ff05d1..7ff3d7ae6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/CONTRIBUTING.md +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/CONTRIBUTING.md @@ -261,7 +261,7 @@ These files containing derived exchange classes are transpiled from JS into PHP: These PHP base classes and files are not transpiled: -- `php/base/*` +- `php/Exchange.php php/ExchangeError.php php/Precise.php ... #### Typescript @@ -385,7 +385,7 @@ async fetchTicker (symbol, params = {}) { #### Parsing Symbols -When sending requests to the exchange unified symbols have to be _"converted"_ to exchange-specific market-`id`s like shown above. The same is true on the other side – when receiving an exchange response it has an exchange-specific market-`id` inside it that has to be _"converted back"_ to a unified CCXT symbol. +When sending requests to the exchange unified symbols have to be _"converted"_ to exchange-specific market-`id`s like shown above. The same is true on the other end – when receiving an exchange response it has an exchange-specific market-`id` inside it that has to be _"converted back"_ to a unified CCXT symbol. **We don't put exchange-specific market-`id`s in unified structures directly!** We can't freely interchange symbols with ids! There is a significant difference between an *exchange-specific market-ids* and *unified symbols*! This is explained in the Manual, here: @@ -444,7 +444,7 @@ In JavaScript, dictionary keys can be accessed in two notations: Both work almost identically, and one is implicitly converted to another upon executing the JavaScript code. -While the above does work in JavaScript, it will not work in Python or PHP. In most languages, associative dictionary keys are not treated in the same way as properties. Therefore, in Python `object.key` is not the same as `object['key']`. In PHP `$object->key` is not the same as `$object['key']` as well. Languages that differentiate between associative keys and properties use different notations for the two. +While the above does work in JavaScript, **it will not work in Python or PHP**. In most languages, associative dictionary keys are not treated in the same way as properties. Therefore, in Python `object.key` is not the same as `object['key']`. In PHP `$object->key` is not the same as `$object['key']` as well. Languages that differentiate between associative keys and properties use different notations for the two. To keep the code transpileable, please, remember this simple rule: *always use the single-quoted string key notation `object['key']` for accessing all associative dictionary keys in all languages everywhere throughout this library!* @@ -572,7 +572,7 @@ The `hmac()` method also supports `'base64'` for the `digest` argument. This is #### Timestamps -**All timestamps throughout all unified structures within this library are integer timestamp _in milliseconds_!** +**All timestamps throughout all unified structures within this library are integer UTC timestamps _in milliseconds_!** In order to convert to milliseconds timestamps, CCXT implements the following methods: diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/README.md b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/README.md index 3f8dfeea4..7ec80167e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/README.md +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/README.md @@ -1,6 +1,6 @@ # CCXT – CryptoCurrency eXchange Trading Library -[![Build Status](https://travis-ci.com/ccxt/ccxt.svg?branch=master)](https://travis-ci.com/ccxt/ccxt) [![npm](https://img.shields.io/npm/v/ccxt.svg)](https://npmjs.com/package/ccxt) [![PyPI](https://img.shields.io/pypi/v/ccxt.svg)](https://pypi.python.org/pypi/ccxt) [![NPM Downloads](https://img.shields.io/npm/dy/ccxt.svg)](https://www.npmjs.com/package/ccxt) [![Discord](https://img.shields.io/discord/690203284119617602?logo=discord&logoColor=white)](https://discord.gg/dhzSKYU) [![Supported Exchanges](https://img.shields.io/badge/exchanges-126-blue.svg)](https://github.com/ccxt/ccxt/wiki/Exchange-Markets) [![Open Collective](https://opencollective.com/ccxt/backers/badge.svg)](https://opencollective.com/ccxt) +[![Build Status](https://travis-ci.com/ccxt/ccxt.svg?branch=master)](https://travis-ci.com/ccxt/ccxt) [![npm](https://img.shields.io/npm/v/ccxt.svg)](https://npmjs.com/package/ccxt) [![PyPI](https://img.shields.io/pypi/v/ccxt.svg)](https://pypi.python.org/pypi/ccxt) [![NPM Downloads](https://img.shields.io/npm/dy/ccxt.svg)](https://www.npmjs.com/package/ccxt) [![Discord](https://img.shields.io/discord/690203284119617602?logo=discord&logoColor=white)](https://discord.gg/dhzSKYU) [![Supported Exchanges](https://img.shields.io/badge/exchanges-121-blue.svg)](https://github.com/ccxt/ccxt/wiki/Exchange-Markets) [![Open Collective](https://opencollective.com/ccxt/backers/badge.svg)](https://opencollective.com/ccxt) [![Twitter Follow](https://img.shields.io/twitter/follow/ccxt_official.svg?style=social&label=CCXT)](https://twitter.com/ccxt_official) A JavaScript / Python / PHP library for cryptocurrency trading and e-commerce with support for many bitcoin/ether/altcoin exchange markets and merchant APIs. @@ -25,10 +25,10 @@ Current feature list: ## See Also -- [![Quadency](https://user-images.githubusercontent.com/1294454/69334382-a0618100-0c6b-11ea-9ba9-40aa97440cfa.png)](https://quadency.com?utm_source=ccxt)  **[Quadency](https://quadency.com?utm_source=ccxt)** — trading automation terminal for leading exchanges with streaming APIs + Python IDE. - [![TabTrader](https://user-images.githubusercontent.com/1294454/66755907-9c3e8880-eea1-11e9-846e-0bff349ceb87.png)](https://tab-trader.com/?utm_source=ccxt)  **[TabTrader](https://tab-trader.com/?utm_source=ccxt)** — trading on all exchanges in one app. Avaliable on [Android](https://play.google.com/store/apps/details?id=com.tabtrader.android&referrer=utm_source%3Dccxt) and [iOS](https://itunes.apple.com/app/apple-store/id1095716562?mt=8). - [![Pionex](https://user-images.githubusercontent.com/1294454/106112806-c2ec0580-615e-11eb-870c-0b7aef021db2.png)](https://www.pionex.com/en-US/sign?r=8wSFCbNk&utm_source=ad&utm_medium=banner&utm_campaign=ccxt-2)  **[Pionex](https://www.pionex.com/en-US/sign?r=8wSFCbNk&utm_source=ad&utm_medium=banner&utm_campaign=ccxt-2)** — 6 grid bots, spot-futures arb bot, smart trade and DCA bots. Free for [Android](https://play.google.com/store/apps/details?id=com.pionex.client&referrer=utm_source%3Dccxt) and [iOS](https://apps.apple.com/us/app/pionex/id1485348891?pt=ccxt&ct=inline)! - [![AAX](https://user-images.githubusercontent.com/1294454/106509642-ef957980-64de-11eb-92e0-8323cda7874e.png)](https://www.aaxpro.com/en-US/ad-sign-up/?utm_source=ccxt&utm_medium=one-liner&utm_campaign=futures)  **[AAX](https://www.aaxpro.com/en-US/ad-sign-up/?utm_source=ccxt&utm_medium=one-liner&utm_campaign=futures)** — trade bitcoin futures with fees as low as 0.02% and up to 100x leverage! +- [![Freqtrade](https://user-images.githubusercontent.com/1294454/114340585-8e35fa80-9b60-11eb-860f-4379125e2db6.png)](https://www.freqtrade.io)  **[Freqtrade](https://www.freqtrade.io)** — leading opensource cryptocurrency algorithmic trading software! ## Certified Cryptocurrency Exchanges @@ -52,13 +52,13 @@ Current feature list: ## Supported Cryptocurrency Exchange Markets -The CCXT library currently supports the following 126 cryptocurrency exchange markets and trading APIs: +The CCXT library currently supports the following 121 cryptocurrency exchange markets and trading APIs: | logo | id | name | ver | doc | certified | pro | |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|-----------------------------------------------------------------------------------------|:---:|:-------------------------------------------------------------------------------------------:|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------| | [![aax](https://user-images.githubusercontent.com/1294454/104140087-a27f2580-53c0-11eb-87c1-5d9e81208fe9.jpg)](https://www.aaxpro.com/invite/sign-up?inviteCode=JXGm5Fy7R2MB) | aax | [AAX](https://www.aaxpro.com/invite/sign-up?inviteCode=JXGm5Fy7R2MB) | 2 | [API](https://www.aaxpro.com/apidoc/index.html) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | -| [![acx](https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg)](https://acx.io) | acx | [ACX](https://acx.io) | 2 | [API](https://acx.io/documents/api_v2) | | | | [![aofex](https://user-images.githubusercontent.com/51840849/77670271-056d1080-6f97-11ea-9ac2-4268e9ed0c1f.jpg)](https://aofex.com/#/register?key=9763840) | aofex | [AOFEX](https://aofex.com/#/register?key=9763840) | * | [API](https://aofex.zendesk.com/hc/en-us/sections/360005576574-API) | | | +| [![ascendex](https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg)](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | ascendex | [AscendEX](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | 1 | [API](https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation) | | | | [![bequant](https://user-images.githubusercontent.com/1294454/55248342-a75dfe00-525a-11e9-8aa2-05e9dca943c6.jpg)](https://bequant.io) | bequant | [Bequant](https://bequant.io) | 2 | [API](https://api.bequant.io/) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bibox](https://user-images.githubusercontent.com/51840849/77257418-3262b000-6c85-11ea-8fb8-20bdf20b3592.jpg)](https://w2.bibox365.com/login/register?invite_code=05Kj3I) | bibox | [Bibox](https://w2.bibox365.com/login/register?invite_code=05Kj3I) | 1 | [API](https://biboxcom.github.io/en/) | | | | [![bigone](https://user-images.githubusercontent.com/1294454/69354403-1d532180-0c91-11ea-88ed-44c06cefdf87.jpg)](https://b1.run/users/new?code=D3LLBVFT) | bigone | [BigONE](https://b1.run/users/new?code=D3LLBVFT) | 3 | [API](https://open.big.one/docs/api.html) | | | @@ -76,7 +76,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bithumb](https://user-images.githubusercontent.com/1294454/30597177-ea800172-9d5e-11e7-804c-b9d4fa9b56b0.jpg)](https://www.bithumb.com) | bithumb | [Bithumb](https://www.bithumb.com) | * | [API](https://apidocs.bithumb.com) | | | | [![bitkk](https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg)](https://www.bitkk.com) | bitkk | [bitkk](https://www.bitkk.com) | 1 | [API](https://www.bitkk.com/i/developer) | | | | [![bitmart](https://user-images.githubusercontent.com/1294454/61835713-a2662f80-ae85-11e9-9d00-6442919701fd.jpg)](http://www.bitmart.com/?r=rQCFLh) | bitmart | [BitMart](http://www.bitmart.com/?r=rQCFLh) | 1 | [API](https://developer-pro.bitmart.com/) | | | -| [![bitmax](https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg)](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | bitmax | [BitMax](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | 1 | [API](https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation) | | | | [![bitmex](https://user-images.githubusercontent.com/1294454/27766319-f653c6e6-5ed4-11e7-933d-f0bc3699ae8f.jpg)](https://www.bitmex.com/register/upZpOX) | bitmex | [BitMEX](https://www.bitmex.com/register/upZpOX) | 1 | [API](https://www.bitmex.com/app/apiOverview) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bitpanda](https://user-images.githubusercontent.com/51840849/87591171-9a377d80-c6f0-11ea-94ac-97a126eac3bc.jpg)](https://www.bitpanda.com/en/pro) | bitpanda | [Bitpanda Pro](https://www.bitpanda.com/en/pro) | 1 | [API](https://developers.bitpanda.com/exchange/) | | | | [![bitso](https://user-images.githubusercontent.com/51840849/87295554-11f98280-c50e-11ea-80d6-15b3bafa8cbf.jpg)](https://bitso.com/?ref=itej) | bitso | [Bitso](https://bitso.com/?ref=itej) | 3 | [API](https://bitso.com/api_info) | | | @@ -84,7 +83,7 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bitstamp1](https://user-images.githubusercontent.com/1294454/27786377-8c8ab57e-5fe9-11e7-8ea4-2b05b6bcceec.jpg)](https://www.bitstamp.net) | bitstamp1 | [Bitstamp](https://www.bitstamp.net) | 1 | [API](https://www.bitstamp.net/api) | | | | [![bittrex](https://user-images.githubusercontent.com/51840849/87153921-edf53180-c2c0-11ea-96b9-f2a9a95a455b.jpg)](https://bittrex.com/Account/Register?referralCode=1ZE-G0G-M3B) | bittrex | [Bittrex](https://bittrex.com/Account/Register?referralCode=1ZE-G0G-M3B) | 3 | [API](https://bittrex.github.io/api/v3) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bitvavo](https://user-images.githubusercontent.com/1294454/83165440-2f1cf200-a116-11ea-9046-a255d09fb2ed.jpg)](https://bitvavo.com/?a=24F34952F7) | bitvavo | [Bitvavo](https://bitvavo.com/?a=24F34952F7) | 2 | [API](https://docs.bitvavo.com/) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![bitz](https://user-images.githubusercontent.com/51840849/87443304-fec5e000-c5fd-11ea-98f8-ba8e67f7eaff.jpg)](https://u.bitz.com/register?invite_code=1429193) | bitz | [Bit-Z](https://u.bitz.com/register?invite_code=1429193) | 2 | [API](https://apidoc.bitz.com/en/) | | | +| [![bitz](https://user-images.githubusercontent.com/51840849/87443304-fec5e000-c5fd-11ea-98f8-ba8e67f7eaff.jpg)](https://u.bitz.com/register?invite_code=1429193) | bitz | [Bit-Z](https://u.bitz.com/register?invite_code=1429193) | 2 | [API](https://apidocv2.bitz.plus/en/) | | | | [![bl3p](https://user-images.githubusercontent.com/1294454/28501752-60c21b82-6feb-11e7-818b-055ee6d0e754.jpg)](https://bl3p.eu) | bl3p | [BL3P](https://bl3p.eu) | 1 | [API](https://github.com/BitonicNL/bl3p-api/tree/master/docs) | | | | [![bleutrade](https://user-images.githubusercontent.com/1294454/30303000-b602dbe6-976d-11e7-956d-36c5049c01e7.jpg)](https://bleutrade.com) | bleutrade | [Bleutrade](https://bleutrade.com) | * | [API](https://app.swaggerhub.com/apis-docs/bleu/white-label/3.0.0) | | | | [![braziliex](https://user-images.githubusercontent.com/1294454/34703593-c4498674-f504-11e7-8d14-ff8e44fb78c1.jpg)](https://braziliex.com/?ref=5FE61AB6F6D67DA885BC98BA27223465) | braziliex | [Braziliex](https://braziliex.com/?ref=5FE61AB6F6D67DA885BC98BA27223465) | * | [API](https://braziliex.com/exchange/api.php) | | | @@ -99,7 +98,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bytetrade](https://user-images.githubusercontent.com/1294454/67288762-2f04a600-f4e6-11e9-9fd6-c60641919491.jpg)](https://www.byte-trade.com) | bytetrade | [ByteTrade](https://www.byte-trade.com) | * | [API](https://docs.byte-trade.com/#description) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | | [![cdax](https://user-images.githubusercontent.com/1294454/102157692-fd406280-3e90-11eb-8d46-4511b617cd17.jpg)](https://cdax.io/invite?invite_code=esc74) | cdax | [CDAX](https://cdax.io/invite?invite_code=esc74) | 1 | [API](https://github.com/cloudapidoc/API_Docs) | | | | [![cex](https://user-images.githubusercontent.com/1294454/27766442-8ddc33b0-5ed8-11e7-8b98-f786aef0f3c9.jpg)](https://cex.io/r/0/up105393824/0/) | cex | [CEX.IO](https://cex.io/r/0/up105393824/0/) | * | [API](https://cex.io/cex-api) | | | -| [![chilebit](https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg)](https://chilebit.net) | chilebit | [ChileBit](https://chilebit.net) | 1 | [API](https://blinktrade.com/docs) | | | | [![coinbase](https://user-images.githubusercontent.com/1294454/40811661-b6eceae2-653a-11e8-829e-10bfadb078cf.jpg)](https://www.coinbase.com/join/58cbe25a355148797479dbd2) | coinbase | [Coinbase](https://www.coinbase.com/join/58cbe25a355148797479dbd2) | 2 | [API](https://developers.coinbase.com/api/v2) | | | | [![coinbaseprime](https://user-images.githubusercontent.com/1294454/44539184-29f26e00-a70c-11e8-868f-e907fc236a7c.jpg)](https://prime.coinbase.com) | coinbaseprime | [Coinbase Prime](https://prime.coinbase.com) | * | [API](https://docs.prime.coinbase.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![coinbasepro](https://user-images.githubusercontent.com/1294454/41764625-63b7ffde-760a-11e8-996d-a6328fa9347a.jpg)](https://pro.coinbase.com/) | coinbasepro | [Coinbase Pro](https://pro.coinbase.com/) | * | [API](https://docs.pro.coinbase.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | @@ -118,7 +116,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![delta](https://user-images.githubusercontent.com/1294454/99450025-3be60a00-2931-11eb-9302-f4fd8d8589aa.jpg)](https://www.delta.exchange/app/signup/?code=IULYNB) | delta | [Delta Exchange](https://www.delta.exchange/app/signup/?code=IULYNB) | 2 | [API](https://docs.delta.exchange) | | | | [![deribit](https://user-images.githubusercontent.com/1294454/41933112-9e2dd65a-798b-11e8-8440-5bab2959fcb8.jpg)](https://www.deribit.com/reg-1189.4038) | deribit | [Deribit](https://www.deribit.com/reg-1189.4038) | 2 | [API](https://docs.deribit.com/v2) | | | | [![digifinex](https://user-images.githubusercontent.com/51840849/87443315-01283a00-c5fe-11ea-8628-c2a0feaf07ac.jpg)](https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp) | digifinex | [DigiFinex](https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp) | 3 | [API](https://docs.digifinex.com) | | | -| [![dsx](https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg)](https://dsxglobal.com) | dsx | [DSX](https://dsxglobal.com) | 3 | [API](https://dsxglobal.com/developers/publicApi) | | | | [![equos](https://user-images.githubusercontent.com/1294454/107758499-05edd180-6d38-11eb-9e09-0b69602a7a15.jpg)](https://equos.io?referredByCode=zpa8kij4ouvBFup3) | equos | [EQUOS](https://equos.io?referredByCode=zpa8kij4ouvBFup3) | * | [API](https://developer.equos.io) | | | | [![eterbase](https://user-images.githubusercontent.com/1294454/82067900-faeb0f80-96d9-11ea-9f22-0071cfcb9871.jpg)](https://eterbase.exchange/invite/1wjjh4Pe) | eterbase | [Eterbase](https://eterbase.exchange/invite/1wjjh4Pe) | 1 | [API](https://developers.eterbase.exchange) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | | [![exmo](https://user-images.githubusercontent.com/1294454/27766491-1b0ea956-5eda-11e7-9225-40d67b481b8d.jpg)](https://exmo.me/?ref=131685) | exmo | [EXMO](https://exmo.me/?ref=131685) | 1.1 | [API](https://exmo.me/en/api_doc?ref=131685) | | | @@ -133,10 +130,9 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![gopax](https://user-images.githubusercontent.com/1294454/102897212-ae8a5e00-4478-11eb-9bab-91507c643900.jpg)](https://www.gopax.co.kr) | gopax | [GOPAX](https://www.gopax.co.kr) | 1 | [API](https://gopax.github.io/API/index.en.html) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![hbtc](https://user-images.githubusercontent.com/51840849/80134449-70663300-85a7-11ea-8942-e204cdeaab5d.jpg)](https://www.hbtc.com/register/O2S8NS) | hbtc | [HBTC](https://www.hbtc.com/register/O2S8NS) | 1 | [API](https://github.com/bhexopen/BHEX-OpenApi/tree/master/doc) | | | | [![hitbtc](https://user-images.githubusercontent.com/1294454/27766555-8eaec20e-5edc-11e7-9c5b-6dc69fc42f5e.jpg)](https://hitbtc.com/?ref_id=5a5d39a65d466) | hitbtc | [HitBTC](https://hitbtc.com/?ref_id=5a5d39a65d466) | 2 | [API](https://api.hitbtc.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![hollaex](https://user-images.githubusercontent.com/1294454/75841031-ca375180-5ddd-11ea-8417-b975674c23cb.jpg)](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | hollaex | [HollaEx](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | 1 | [API](https://apidocs.hollaex.com) | | | +| [![hollaex](https://user-images.githubusercontent.com/1294454/75841031-ca375180-5ddd-11ea-8417-b975674c23cb.jpg)](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | hollaex | [HollaEx](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | 2 | [API](https://apidocs.hollaex.com) | | | | [![huobijp](https://user-images.githubusercontent.com/1294454/85734211-85755480-b705-11ea-8b35-0b7f1db33a2f.jpg)](https://www.huobi.co.jp/register/?invite_code=znnq3) | huobijp | [Huobi Japan](https://www.huobi.co.jp/register/?invite_code=znnq3) | 1 | [API](https://api-doc.huobi.co.jp) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![huobipro](https://user-images.githubusercontent.com/1294454/76137448-22748a80-604e-11ea-8069-6e389271911d.jpg)](https://www.huobi.com/en-us/topic/invited/?invite_code=rwrd3) | huobipro | [Huobi Pro](https://www.huobi.com/en-us/topic/invited/?invite_code=rwrd3) | 1 | [API](https://huobiapi.github.io/docs/spot/v1/cn/) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![ice3x](https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg)](https://ice3x.com?ref=14341802) | ice3x | [ICE3X](https://ice3x.com?ref=14341802) | 1 | [API](https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017) | | | | [![idex](https://user-images.githubusercontent.com/51840849/94481303-2f222100-01e0-11eb-97dd-bc14c5943a86.jpg)](https://idex.io) | idex | [IDEX](https://idex.io) | 2 | [API](https://docs.idex.io/) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![independentreserve](https://user-images.githubusercontent.com/51840849/87182090-1e9e9080-c2ec-11ea-8e49-563db9a38f37.jpg)](https://www.independentreserve.com) | independentreserve | [Independent Reserve](https://www.independentreserve.com) | * | [API](https://www.independentreserve.com/API) | | | | [![indodax](https://user-images.githubusercontent.com/51840849/87070508-9358c880-c221-11ea-8dc5-5391afbbb422.jpg)](https://indodax.com/ref/testbitcoincoid/1) | indodax | [INDODAX](https://indodax.com/ref/testbitcoincoid/1) | 2.0 | [API](https://github.com/btcid/indodax-official-api-docs) | | | @@ -172,7 +168,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![tidex](https://user-images.githubusercontent.com/1294454/30781780-03149dc4-a12e-11e7-82bb-313b269d24d4.jpg)](https://tidex.com/exchange/?ref=57f5638d9cd7) | tidex | [Tidex](https://tidex.com/exchange/?ref=57f5638d9cd7) | 3 | [API](https://tidex.com/exchange/public-api) | | | | [![timex](https://user-images.githubusercontent.com/1294454/70423869-6839ab00-1a7f-11ea-8f94-13ae72c31115.jpg)](https://timex.io/?refcode=1x27vNkTbP1uwkCck) | timex | [TimeX](https://timex.io/?refcode=1x27vNkTbP1uwkCck) | 1 | [API](https://docs.timex.io) | | | | [![upbit](https://user-images.githubusercontent.com/1294454/49245610-eeaabe00-f423-11e8-9cba-4b0aed794799.jpg)](https://upbit.com) | upbit | [Upbit](https://upbit.com) | 1 | [API](https://docs.upbit.com/docs/%EC%9A%94%EC%B2%AD-%EC%88%98-%EC%A0%9C%ED%95%9C) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![vaultoro](https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg)](https://www.vaultoro.com) | vaultoro | [Vaultoro](https://www.vaultoro.com) | 1 | [API](https://api.vaultoro.com) | | | | [![vbtc](https://user-images.githubusercontent.com/1294454/27991481-1f53d1d8-6481-11e7-884e-21d17e7939db.jpg)](https://vbtc.exchange) | vbtc | [VBTC](https://vbtc.exchange) | 1 | [API](https://blinktrade.com/docs) | | | | [![vcc](https://user-images.githubusercontent.com/1294454/100545356-8427f500-326c-11eb-9539-7d338242d61b.jpg)](https://vcc.exchange?ref=l4xhrH) | vcc | [VCC Exchange](https://vcc.exchange?ref=l4xhrH) | 3 | [API](https://vcc.exchange/api) | | | | [![wavesexchange](https://user-images.githubusercontent.com/1294454/84547058-5fb27d80-ad0b-11ea-8711-78ac8b3c7f31.jpg)](https://waves.exchange) | wavesexchange | [Waves.Exchange](https://waves.exchange) | * | [API](https://docs.waves.exchange) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | @@ -229,13 +224,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.42.77/dist/ccxt.browser.js -* unpkg: https://unpkg.com/ccxt@1.42.77/dist/ccxt.browser.js +* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.47.49/dist/ccxt.browser.js +* unpkg: https://unpkg.com/ccxt@1.47.49/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/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/export-exchanges.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/export-exchanges.js index 580d2cb2c..24ee4806f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/export-exchanges.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/export-exchanges.js @@ -195,7 +195,6 @@ function createMarkdownTable (array, markdownMethod, centeredColumns) { // const columns = underline.split ('|') - for (const i of centeredColumns) { columns[i] = ':' + columns[i].slice (1, columns[i].length - 1) + ':' } @@ -219,51 +218,45 @@ function exportSupportedAndCertifiedExchanges (exchanges, { allExchangesPaths, c const exchangesNotListedInDocs = [ 'hitbtc2' ] const arrayOfExchanges = values (exchanges) + const numExchanges = arrayOfExchanges.length - if (allExchangesPaths) { - + if (allExchangesPaths && numExchanges) { const supportedExchangesMarkdownTable = createMarkdownTable (arrayOfExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , numExchanges = arrayOfExchanges.length , beginning = "The CCXT library currently supports the following " , ending = " cryptocurrency exchange markets and trading APIs:\n\n" , totalString = beginning + numExchanges + ending , allExchangesReplacement = totalString + supportedExchangesMarkdownTable + "$1" , allExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\| logo[^`]+\\|([\n][\n]|[\n]$|$)", 'm') - for (const path of allExchangesPaths) { logExportExchanges (path, allExchangesRegex, allExchangesReplacement) } } - if (proExchangesPaths) { - - const proExchanges = arrayOfExchanges.filter (exchange => exchange.pro) - , proExchangesMarkdownTable = createMarkdownTable (proExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , numExchanges = proExchanges.length + const proExchanges = arrayOfExchanges.filter (exchange => exchange.pro) + const numProExchanges = proExchanges.length + if (proExchangesPaths && numProExchanges) { + const proExchangesMarkdownTable = createMarkdownTable (proExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) , beginning = "The CCXT Pro library currently supports the following " , ending = " cryptocurrency exchange markets and WebSocket trading APIs:\n\n" - , totalString = beginning + numExchanges + ending + , totalString = beginning + numProExchanges + ending , proExchangesReplacement = totalString + proExchangesMarkdownTable + "$1" , proExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\|[^`]+\\|([\n][\n]|[\n]$|$)", 'm') - for (const path of proExchangesPaths) { logExportExchanges (path, proExchangesRegex, proExchangesReplacement) } } - if (certifiedExchangesPaths) { - const certifiedExchanges = arrayOfExchanges.filter (exchange => exchange.certified) - , certifiedExchangesMarkdownTable = createMarkdownTable (certifiedExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , certifiedExchangesReplacement = '$1' + certifiedExchangesMarkdownTable + "\n" - , certifiedExchangesRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm') - + const certifiedExchanges = arrayOfExchanges.filter (exchange => exchange.certified) + if (certifiedExchangesPaths && certifiedExchanges.length) { + const certifiedExchangesMarkdownTable = createMarkdownTable (certifiedExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) + , certifiedExchangesReplacement = '$1' + certifiedExchangesMarkdownTable + "\n" + , certifiedExchangesRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm') for (const path of certifiedExchangesPaths) { logExportExchanges (path, certifiedExchangesRegex, certifiedExchangesReplacement) } } if (exchangesByCountriesPaths) { - const exchangesByCountriesMarkdownTable = createMarkdownTable (arrayOfExchanges, createMarkdownListOfExchangesByCountries, [ 4, 5 ]) const result = "# Exchanges By Country\n\nThe ccxt library currently supports the following cryptocurrency exchange markets and trading APIs:\n\n" + exchangesByCountriesMarkdownTable + "\n\n" for (const path of exchangesByCountriesPaths) { @@ -385,7 +378,7 @@ function exportEverything () { replacement: "exchanges = [\n" + " '" + ids.join ("',\n '") + "'," + "\n]", }, { - file: './php/base/Exchange.php', + file: './php/Exchange.php', regex: /public static \$exchanges \= array\s*\([^\)]+\)/, replacement: "public static $exchanges = array(\n '" + ids.join ("',\n '") + "',\n )", }, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/transpile.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/transpile.js index 948a34c0f..233d15e6c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/transpile.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/build/transpile.js @@ -34,6 +34,7 @@ class Transpiler { [ /\.safeIntegerProduct2\s/g, '.safe_integer_product_2'], [ /\.safeTimestamp2\s/g, '.safe_timestamp_2'], [ /\.safeString2\s/g, '.safe_string_2'], + [ /\.safeNumber2\s/g, '.safe_number_2'], [ /\.safeStringLower2\s/g, '.safe_string_lower_2'], [ /\.safeStringUpper2\s/g, '.safe_string_upper_2'], [ /\.safeValue2\s/g, '.safe_value_2'], @@ -195,6 +196,10 @@ class Transpiler { [ /Number\.MAX_SAFE_INTEGER/g, 'float(\'inf\')'], [ /function\s*(\w+\s*\([^)]+\))\s*{/g, 'def $1:'], [ /assert\s*\((.+)\);/g, 'assert $1'], + [ /Precise\.stringAdd\s/g, 'Precise.string_add' ], + [ /Precise\.stringMul\s/g, 'Precise.string_mul' ], + [ /Precise\.stringDiv\s/g, 'Precise.string_div' ], + [ /Precise\.stringSub\s/g, 'Precise.string_sub' ], // insert common regexes in the middle (critical) ].concat (this.getCommonRegexes ()).concat ([ @@ -227,7 +232,7 @@ class Transpiler { [ /for\s+\(([a-zA-Z0-9_]+)\s*=\s*([^\;\s]+\s*)\;[^\<\>\=]+(?:\<=|\>=|<|>)\s*(.*)\s*\;[^\)]+\)\s*{/g, 'for $1 in range($2, $3):'], [ /\s\|\|\s/g, ' or ' ], [ /\s\&\&\s/g, ' and ' ], - [ /\!([^\='"])/g, 'not $1'], + [ /\!([^\s\='"])/g, 'not $1'], [ /\.push\s*\(([\s\S]+?)\);/g, '.append($1);' ], [ /^(\s*}\s*$)+/gm, '' ], [ /\;(\s+?\/\/.+?)/g, '$1' ], @@ -243,9 +248,6 @@ class Transpiler { [ /parseFloat\s*/g, 'float'], [ /parseInt\s*/g, 'int'], [ /self\[([^\]+]+)\]/g, 'getattr(self, $1)' ], - [ /([^\s]+)\.slice \(([^\,\)]+)\,\s?([^\)]+)\)/g, '$1[$2:$3]' ], - [ /([^\s]+)\.slice \(([^\)\:]+)\)/g, '$1[$2:]' ], - [ /([^\s(:]+)\.length/g, 'len($1)' ], [ /Math\.floor\s*\(([^\)]+)\)/g, 'int(math.floor($1))' ], [ /Math\.abs\s*\(([^\)]+)\)/g, 'abs($1)' ], [ /Math\.pow\s*\(([^\)]+)\)/g, 'math.pow($1)' ], @@ -253,6 +255,9 @@ class Transpiler { [ /Math\.ceil\s*\(([^\)]+)\)/g, 'int(math.ceil($1))' ], [ /Math\.log/g, 'math.log' ], [ /([a-zA-Z0-9_\.]*\([^\)]+\)|[^\s]+)\s+\?\s*([^\:]+)\s+\:\s*([^\n]+)/g, '$2 if $1 else $3'], + [ /([^\s]+)\.slice \(([^\,\)]+)\,\s?([^\)]+)\)/g, '$1[$2:$3]' ], + [ /([^\s]+)\.slice \(([^\)\:]+)\)/g, '$1[$2:]' ], + [ /([^\s(:]+)\.length/g, 'len($1)' ], [ /(^|\s)\/\//g, '$1#' ], [ /([^\n\s]) #/g, '$1 #' ], // PEP8 E261 [ /\.indexOf/g, '.find'], @@ -336,6 +341,10 @@ class Transpiler { [ /(\w+)\.shift\s*\(\)/g, 'array_shift($1)' ], [ /(\w+)\.pop\s*\(\)/g, 'array_pop($1)' ], [ /Number\.MAX_SAFE_INTEGER/g, 'PHP_INT_MAX' ], + [ /Precise\.stringAdd\s/g, 'Precise::string_add' ], + [ /Precise\.stringDiv\s/g, 'Precise::string_div' ], + [ /Precise\.stringMul\s/g, 'Precise::string_mul' ], + [ /Precise\.stringSub\s/g, 'Precise::string_sub' ], // insert common regexes in the middle (critical) ].concat (this.getCommonRegexes ()).concat ([ @@ -404,6 +413,7 @@ class Transpiler { [ /([^\(\s]+)\s+%\s+([^\s\,\;\)]+)/g, 'fmod($1, $2)' ], [ /\(([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\>\=\s*0\)/g, '(mb_strpos($1, $2) !== false)' ], [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\>\=\s*0/g, 'mb_strpos($1, $2) !== false' ], + [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\<\s*0/g, 'mb_strpos($1, $2) === false' ], [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)/g, 'mb_strpos($1, $2)' ], [ /\(([^\s\(]+)\sin\s([^\)]+)\)/g, '(is_array($2) && array_key_exists($1, $2))' ], [ /([^\s]+)\.join\s*\(\s*([^\)]+?)\s*\)/g, 'implode($2, $1)' ], @@ -578,6 +588,9 @@ class Transpiler { precisionImports.push ('from ccxt.base.decimal_to_precision import ' + constant) } } + if (bodyAsString.match (/[\s(]Precise/)) { + precisionImports.push ('from ccxt.base.precise import Precise') + } header = header.concat (libraries, errorImports, precisionImports) @@ -633,7 +646,13 @@ class Transpiler { } } - header = header.concat (errorImports) + const precisionImports = [] + + if (async && bodyAsString.match (/[\s(]Precise/)) { + precisionImports.push ('use \\ccxt\\Precise;') + } + + header = header.concat (errorImports).concat (precisionImports) methods = methods.concat (this.getPHPBaseMethods ()) @@ -1179,7 +1198,7 @@ class Transpiler { function phpMakeErrorClassFile (name, parent) { const useClause = "\nuse " + parent + ";\n" - const requireClause = "\nrequire_once PATH_TO_CCXT_BASE . '" + parent + ".php';\n" + const requireClause = "\nrequire_once PATH_TO_CCXT . '" + parent + ".php';\n" const phpBody = [ '; - createLimitOrder (symbol: string, side: Order['side'], amount: number, price?: number, params?: Params): Promise; + createLimitOrder (symbol: string, side: Order['side'], amount: number, price: number, params?: Params): Promise; + createLimitBuyOrder (symbol: string, amount: number, price: number, params?: Params): Promise; + createLimitSellOrder (symbol: string, amount: number, price: number, params?: Params): Promise; createMarketOrder (symbol: string, side: Order['side'], amount: number, price?: number, params?: Params): Promise; createOrder (symbol: string, type: Order['type'], side: Order['side'], amount: number, price?: number, params?: Params): Promise; decode (str: string): string; @@ -423,8 +425,8 @@ declare module 'ccxt' { /* tslint:disable */ export class aax extends Exchange {} - export class acx extends Exchange {} export class aofex extends Exchange {} + export class ascendex extends Exchange {} export class bequant extends hitbtc {} export class bibox extends Exchange {} export class bigone extends Exchange {} @@ -442,7 +444,6 @@ declare module 'ccxt' { export class bithumb extends Exchange {} export class bitkk extends zb {} export class bitmart extends Exchange {} - export class bitmax extends Exchange {} export class bitmex extends Exchange {} export class bitpanda extends Exchange {} export class bitso extends Exchange {} @@ -465,7 +466,6 @@ declare module 'ccxt' { export class bytetrade extends Exchange {} export class cdax extends huobipro {} export class cex extends Exchange {} - export class chilebit extends foxbit {} export class coinbase extends Exchange {} export class coinbaseprime extends coinbasepro {} export class coinbasepro extends Exchange {} @@ -484,7 +484,6 @@ declare module 'ccxt' { export class delta extends Exchange {} export class deribit extends Exchange {} export class digifinex extends Exchange {} - export class dsx extends Exchange {} export class equos extends Exchange {} export class eterbase extends Exchange {} export class exmo extends Exchange {} @@ -502,14 +501,13 @@ declare module 'ccxt' { export class hollaex extends Exchange {} export class huobijp extends huobipro {} export class huobipro extends Exchange {} - export class ice3x extends Exchange {} export class idex extends Exchange {} export class independentreserve extends Exchange {} export class indodax extends Exchange {} export class itbit extends Exchange {} export class kraken extends Exchange {} export class kucoin extends Exchange {} - export class kuna extends acx {} + export class kuna extends Exchange {} export class lakebtc extends Exchange {} export class latoken extends Exchange {} export class lbank extends Exchange {} @@ -538,7 +536,6 @@ declare module 'ccxt' { export class tidex extends Exchange {} export class timex extends Exchange {} export class upbit extends Exchange {} - export class vaultoro extends Exchange {} export class vbtc extends foxbit {} export class vcc extends Exchange {} export class wavesexchange extends Exchange {} @@ -553,8 +550,8 @@ declare module 'ccxt' { export type ExchangeId = | 'aax' - | 'acx' | 'aofex' + | 'ascendex' | 'bequant' | 'bibox' | 'bigone' @@ -572,7 +569,6 @@ declare module 'ccxt' { | 'bithumb' | 'bitkk' | 'bitmart' - | 'bitmax' | 'bitmex' | 'bitpanda' | 'bitso' @@ -595,7 +591,6 @@ declare module 'ccxt' { | 'bytetrade' | 'cdax' | 'cex' - | 'chilebit' | 'coinbase' | 'coinbaseprime' | 'coinbasepro' @@ -614,7 +609,6 @@ declare module 'ccxt' { | 'delta' | 'deribit' | 'digifinex' - | 'dsx' | 'equos' | 'eterbase' | 'exmo' @@ -632,7 +626,6 @@ declare module 'ccxt' { | 'hollaex' | 'huobijp' | 'huobipro' - | 'ice3x' | 'idex' | 'independentreserve' | 'indodax' @@ -668,7 +661,6 @@ declare module 'ccxt' { | 'tidex' | 'timex' | 'upbit' - | 'vaultoro' | 'vbtc' | 'vcc' | 'wavesexchange' diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/ccxt.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/ccxt.js index 1d5c72642..27dc35101 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/ccxt.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/ccxt.js @@ -35,7 +35,7 @@ const Exchange = require ('./js/base/Exchange') //----------------------------------------------------------------------------- // this is updated by vss.js when building -const version = '1.42.77' +const version = '1.47.49' Exchange.ccxtVersion = version @@ -43,8 +43,8 @@ Exchange.ccxtVersion = version const exchanges = { 'aax': require ('./js/aax.js'), - 'acx': require ('./js/acx.js'), 'aofex': require ('./js/aofex.js'), + 'ascendex': require ('./js/ascendex.js'), 'bequant': require ('./js/bequant.js'), 'bibox': require ('./js/bibox.js'), 'bigone': require ('./js/bigone.js'), @@ -62,7 +62,6 @@ const exchanges = { 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitmart': require ('./js/bitmart.js'), - 'bitmax': require ('./js/bitmax.js'), 'bitmex': require ('./js/bitmex.js'), 'bitpanda': require ('./js/bitpanda.js'), 'bitso': require ('./js/bitso.js'), @@ -85,7 +84,6 @@ const exchanges = { 'bytetrade': require ('./js/bytetrade.js'), 'cdax': require ('./js/cdax.js'), 'cex': require ('./js/cex.js'), - 'chilebit': require ('./js/chilebit.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), @@ -104,7 +102,6 @@ const exchanges = { 'delta': require ('./js/delta.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), - 'dsx': require ('./js/dsx.js'), 'equos': require ('./js/equos.js'), 'eterbase': require ('./js/eterbase.js'), 'exmo': require ('./js/exmo.js'), @@ -122,7 +119,6 @@ const exchanges = { 'hollaex': require ('./js/hollaex.js'), 'huobijp': require ('./js/huobijp.js'), 'huobipro': require ('./js/huobipro.js'), - 'ice3x': require ('./js/ice3x.js'), 'idex': require ('./js/idex.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), @@ -158,7 +154,6 @@ const exchanges = { 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'upbit': require ('./js/upbit.js'), - 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'vcc': require ('./js/vcc.js'), 'wavesexchange': require ('./js/wavesexchange.js'), diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/dist/ccxt.browser.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/dist/ccxt.browser.js index e8b439fb1..334681baa 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/dist/ccxt.browser.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/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.42.77' +const version = '1.47.49' Exchange.ccxtVersion = version @@ -51,8 +51,8 @@ Exchange.ccxtVersion = version const exchanges = { 'aax': require ('./js/aax.js'), - 'acx': require ('./js/acx.js'), 'aofex': require ('./js/aofex.js'), + 'ascendex': require ('./js/ascendex.js'), 'bequant': require ('./js/bequant.js'), 'bibox': require ('./js/bibox.js'), 'bigone': require ('./js/bigone.js'), @@ -70,7 +70,6 @@ const exchanges = { 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitmart': require ('./js/bitmart.js'), - 'bitmax': require ('./js/bitmax.js'), 'bitmex': require ('./js/bitmex.js'), 'bitpanda': require ('./js/bitpanda.js'), 'bitso': require ('./js/bitso.js'), @@ -93,7 +92,6 @@ const exchanges = { 'bytetrade': require ('./js/bytetrade.js'), 'cdax': require ('./js/cdax.js'), 'cex': require ('./js/cex.js'), - 'chilebit': require ('./js/chilebit.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), @@ -112,7 +110,6 @@ const exchanges = { 'delta': require ('./js/delta.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), - 'dsx': require ('./js/dsx.js'), 'equos': require ('./js/equos.js'), 'eterbase': require ('./js/eterbase.js'), 'exmo': require ('./js/exmo.js'), @@ -130,7 +127,6 @@ const exchanges = { 'hollaex': require ('./js/hollaex.js'), 'huobijp': require ('./js/huobijp.js'), 'huobipro': require ('./js/huobipro.js'), - 'ice3x': require ('./js/ice3x.js'), 'idex': require ('./js/idex.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), @@ -166,7 +162,6 @@ const exchanges = { 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'upbit': require ('./js/upbit.js'), - 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'vcc': require ('./js/vcc.js'), 'wavesexchange': require ('./js/wavesexchange.js'), @@ -184,7 +179,7 @@ module.exports = Object.assign ({ version, Exchange, 'exchanges': Object.keys (e //----------------------------------------------------------------------------- -},{"./js/aax.js":3,"./js/acx.js":4,"./js/aofex.js":5,"./js/base/Exchange":6,"./js/base/errors":8,"./js/base/functions":9,"./js/bequant.js":20,"./js/bibox.js":21,"./js/bigone.js":22,"./js/binance.js":23,"./js/binanceus.js":24,"./js/bit2c.js":25,"./js/bitbank.js":26,"./js/bitbay.js":27,"./js/bitcoincom.js":28,"./js/bitfinex.js":29,"./js/bitfinex2.js":30,"./js/bitflyer.js":31,"./js/bitforex.js":32,"./js/bitget.js":33,"./js/bithumb.js":34,"./js/bitkk.js":35,"./js/bitmart.js":36,"./js/bitmax.js":37,"./js/bitmex.js":38,"./js/bitpanda.js":39,"./js/bitso.js":40,"./js/bitstamp.js":41,"./js/bitstamp1.js":42,"./js/bittrex.js":43,"./js/bitvavo.js":44,"./js/bitz.js":45,"./js/bl3p.js":46,"./js/bleutrade.js":47,"./js/braziliex.js":48,"./js/btcalpha.js":49,"./js/btcbox.js":50,"./js/btcmarkets.js":51,"./js/btctradeua.js":52,"./js/btcturk.js":53,"./js/buda.js":54,"./js/bw.js":55,"./js/bybit.js":56,"./js/bytetrade.js":57,"./js/cdax.js":58,"./js/cex.js":59,"./js/chilebit.js":60,"./js/coinbase.js":61,"./js/coinbaseprime.js":62,"./js/coinbasepro.js":63,"./js/coincheck.js":64,"./js/coinegg.js":65,"./js/coinex.js":66,"./js/coinfalcon.js":67,"./js/coinfloor.js":68,"./js/coingi.js":69,"./js/coinmarketcap.js":70,"./js/coinmate.js":71,"./js/coinone.js":72,"./js/coinspot.js":73,"./js/crex24.js":74,"./js/currencycom.js":75,"./js/delta.js":76,"./js/deribit.js":77,"./js/digifinex.js":78,"./js/dsx.js":79,"./js/equos.js":80,"./js/eterbase.js":81,"./js/exmo.js":82,"./js/exx.js":83,"./js/fcoin.js":84,"./js/fcoinjp.js":85,"./js/flowbtc.js":86,"./js/foxbit.js":87,"./js/ftx.js":88,"./js/gateio.js":89,"./js/gemini.js":90,"./js/gopax.js":91,"./js/hbtc.js":92,"./js/hitbtc.js":93,"./js/hollaex.js":94,"./js/huobijp.js":95,"./js/huobipro.js":96,"./js/ice3x.js":97,"./js/idex.js":98,"./js/independentreserve.js":99,"./js/indodax.js":100,"./js/itbit.js":101,"./js/kraken.js":102,"./js/kucoin.js":103,"./js/kuna.js":104,"./js/lakebtc.js":105,"./js/latoken.js":106,"./js/lbank.js":107,"./js/liquid.js":108,"./js/luno.js":109,"./js/lykke.js":110,"./js/mercado.js":111,"./js/mixcoins.js":112,"./js/ndax.js":113,"./js/novadax.js":114,"./js/oceanex.js":115,"./js/okcoin.js":116,"./js/okex.js":117,"./js/paymium.js":118,"./js/phemex.js":119,"./js/poloniex.js":120,"./js/probit.js":121,"./js/qtrade.js":122,"./js/rightbtc.js":123,"./js/ripio.js":124,"./js/southxchange.js":125,"./js/stex.js":166,"./js/surbitcoin.js":167,"./js/therock.js":168,"./js/tidebit.js":169,"./js/tidex.js":170,"./js/timex.js":171,"./js/upbit.js":172,"./js/vaultoro.js":173,"./js/vbtc.js":174,"./js/vcc.js":175,"./js/wavesexchange.js":176,"./js/whitebit.js":177,"./js/xbtce.js":178,"./js/xena.js":179,"./js/yobit.js":180,"./js/zaif.js":181,"./js/zb.js":182}],3:[function(require,module,exports){ +},{"./js/aax.js":3,"./js/aofex.js":4,"./js/ascendex.js":5,"./js/base/Exchange":6,"./js/base/errors":9,"./js/base/functions":10,"./js/bequant.js":21,"./js/bibox.js":22,"./js/bigone.js":23,"./js/binance.js":24,"./js/binanceus.js":25,"./js/bit2c.js":26,"./js/bitbank.js":27,"./js/bitbay.js":28,"./js/bitcoincom.js":29,"./js/bitfinex.js":30,"./js/bitfinex2.js":31,"./js/bitflyer.js":32,"./js/bitforex.js":33,"./js/bitget.js":34,"./js/bithumb.js":35,"./js/bitkk.js":36,"./js/bitmart.js":37,"./js/bitmex.js":38,"./js/bitpanda.js":39,"./js/bitso.js":40,"./js/bitstamp.js":41,"./js/bitstamp1.js":42,"./js/bittrex.js":43,"./js/bitvavo.js":44,"./js/bitz.js":45,"./js/bl3p.js":46,"./js/bleutrade.js":47,"./js/braziliex.js":48,"./js/btcalpha.js":49,"./js/btcbox.js":50,"./js/btcmarkets.js":51,"./js/btctradeua.js":52,"./js/btcturk.js":53,"./js/buda.js":54,"./js/bw.js":55,"./js/bybit.js":56,"./js/bytetrade.js":57,"./js/cdax.js":58,"./js/cex.js":59,"./js/coinbase.js":60,"./js/coinbaseprime.js":61,"./js/coinbasepro.js":62,"./js/coincheck.js":63,"./js/coinegg.js":64,"./js/coinex.js":65,"./js/coinfalcon.js":66,"./js/coinfloor.js":67,"./js/coingi.js":68,"./js/coinmarketcap.js":69,"./js/coinmate.js":70,"./js/coinone.js":71,"./js/coinspot.js":72,"./js/crex24.js":73,"./js/currencycom.js":74,"./js/delta.js":75,"./js/deribit.js":76,"./js/digifinex.js":77,"./js/equos.js":78,"./js/eterbase.js":79,"./js/exmo.js":80,"./js/exx.js":81,"./js/fcoin.js":82,"./js/fcoinjp.js":83,"./js/flowbtc.js":84,"./js/foxbit.js":85,"./js/ftx.js":86,"./js/gateio.js":87,"./js/gemini.js":88,"./js/gopax.js":89,"./js/hbtc.js":90,"./js/hitbtc.js":91,"./js/hollaex.js":92,"./js/huobijp.js":93,"./js/huobipro.js":94,"./js/idex.js":95,"./js/independentreserve.js":96,"./js/indodax.js":97,"./js/itbit.js":98,"./js/kraken.js":99,"./js/kucoin.js":100,"./js/kuna.js":101,"./js/lakebtc.js":102,"./js/latoken.js":103,"./js/lbank.js":104,"./js/liquid.js":105,"./js/luno.js":106,"./js/lykke.js":107,"./js/mercado.js":108,"./js/mixcoins.js":109,"./js/ndax.js":110,"./js/novadax.js":111,"./js/oceanex.js":112,"./js/okcoin.js":113,"./js/okex.js":114,"./js/paymium.js":115,"./js/phemex.js":116,"./js/poloniex.js":117,"./js/probit.js":118,"./js/qtrade.js":119,"./js/rightbtc.js":120,"./js/ripio.js":121,"./js/southxchange.js":122,"./js/stex.js":163,"./js/surbitcoin.js":164,"./js/therock.js":165,"./js/tidebit.js":166,"./js/tidex.js":167,"./js/timex.js":168,"./js/upbit.js":169,"./js/vbtc.js":170,"./js/vcc.js":171,"./js/wavesexchange.js":172,"./js/whitebit.js":173,"./js/xbtce.js":174,"./js/xena.js":175,"./js/yobit.js":176,"./js/zaif.js":177,"./js/zb.js":178}],3:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -192,6 +187,7 @@ module.exports = Object.assign ({ version, Exchange, 'exchanges': Object.keys (e const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, ExchangeNotAvailable, OrderNotFound, InvalidOrder, CancelPending, RateLimitExceeded, InsufficientFunds, BadRequest, BadSymbol, PermissionDenied } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -222,6 +218,7 @@ module.exports = class aax extends Exchange { 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, + 'fetchStatus': true, 'fetchTicker': 'emulated', 'fetchTickers': true, 'fetchTrades': true, @@ -420,6 +417,37 @@ module.exports = class aax extends Exchange { }); } + async fetchStatus (params = {}) { + const response = await this.publicGetAnnouncementMaintenance (params); + // + // { + // "code": 1, + // "data": { + // "startTime":"2020-06-25T02:15:00.000Z", + // "endTime":"2020-06-25T02:45:00.000Z", + // "description":"Spot Trading :UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45),Futures Trading: UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45).We apologize for any inconvenience caused. Thank you for your patience and understanding.Should you have any enquiries, please do not hesitate our live chat support or via email at cs@aax.com." + // }, + // "message":"success", + // "ts":1593043237000 + // } + // + const data = this.safeValue (response, 'data', {}); + const timestamp = this.milliseconds (); + const startTime = this.parse8601 (this.safeString (data, 'startTime')); + const endTime = this.parse8601 (this.safeString (data, 'endTime')); + const update = { + 'updated': this.safeInteger (response, 'ts', timestamp), + }; + if (endTime !== undefined) { + const startTimeIsOk = (startTime === undefined) ? true : (timestamp < startTime); + const isOk = (timestamp > endTime) || startTimeIsOk; + update['eta'] = endTime; + update['status'] = isOk ? 'ok' : 'maintenance'; + } + this.status = this.extend (this.status, update); + return this.status; + } + async fetchMarkets (params = {}) { const response = await this.publicGetInstruments (params); // @@ -505,8 +533,8 @@ module.exports = class aax extends Exchange { const quote = this.safeCurrencyCode (quoteId); const status = this.safeString (market, 'status'); const active = (status === 'enable'); - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); const type = this.safeString (market, 'type'); let inverse = undefined; let linear = undefined; @@ -524,8 +552,8 @@ module.exports = class aax extends Exchange { symbol = base + '/' + quote; } const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; result.push ({ 'id': id, @@ -583,8 +611,8 @@ module.exports = class aax extends Exchange { const timestamp = this.safeInteger (ticker, 't'); const marketId = this.safeString (ticker, 's'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'c'); - const open = this.safeFloat (ticker, 'o'); + const last = this.safeNumber (ticker, 'c'); + const open = this.safeNumber (ticker, 'o'); let change = undefined; let percentage = undefined; let average = undefined; @@ -595,13 +623,13 @@ module.exports = class aax extends Exchange { } average = this.sum (last, open) / 2; } - const quoteVolume = this.safeFloat (ticker, 'v'); + const quoteVolume = this.safeNumber (ticker, 'v'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'h'), - 'low': this.safeFloat (ticker, 'l'), + 'high': this.safeNumber (ticker, 'h'), + 'low': this.safeNumber (ticker, 'l'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -748,8 +776,8 @@ module.exports = class aax extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let price = this.safeFloat2 (trade, 'p', 'filledPrice'); - const amount = this.safeFloat2 (trade, 'q', 'filledQty'); + let priceString = this.safeString2 (trade, 'p', 'filledPrice'); + const amountString = this.safeString2 (trade, 'q', 'filledQty'); const orderId = this.safeString (trade, 'orderID'); const isTaker = this.safeValue (trade, 'taker'); let takerOrMaker = undefined; @@ -763,17 +791,15 @@ module.exports = class aax extends Exchange { side = 'sell'; } if (side === undefined) { - side = (price > 0) ? 'buy' : 'sell'; - } - side = (price > 0) ? 'buy' : 'sell'; - price = Math.abs (price); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; + side = (priceString[0] === '-') ? 'sell' : 'buy'; } + priceString = (priceString[0] === '-') ? priceString.slice (1) : priceString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderType = this.parseOrderType (this.safeString (trade, 'orderType')); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -841,11 +867,11 @@ module.exports = class aax extends Exchange { // return [ this.safeTimestamp (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -930,12 +956,12 @@ module.exports = class aax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'unavailable'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'unavailable'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -963,7 +989,7 @@ module.exports = class aax extends Exchange { request['clOrdID'] = clientOrderId; params = this.omit (params, [ 'clOrdID', 'clientOrderId' ]); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { if ((orderType === 'STOP-LIMIT') || (orderType === 'STOP')) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for ' + orderType + ' orders'); @@ -1081,7 +1107,7 @@ module.exports = class aax extends Exchange { // 'price': this.priceToPrecision (symbol, price), // 'stopPrice': this.priceToPrecision (symbol, stopPrice), }; - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1718,15 +1744,18 @@ module.exports = class aax extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const price = this.safeFloat (order, 'price'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const price = this.safeNumber (order, 'price'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'Post-Only'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeString (order, 'leavesQty'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + let remaining = this.safeNumber (order, 'leavesQty'); + if ((filled === 0) && (remaining === 0)) { + remaining = undefined; + } let cost = undefined; let lastTradeTimestamp = undefined; if (filled !== undefined) { @@ -1741,7 +1770,7 @@ module.exports = class aax extends Exchange { } } let fee = undefined; - const feeCost = this.safeFloat (order, 'commission'); + const feeCost = this.safeNumber (order, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -1970,496 +1999,7 @@ module.exports = class aax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],4:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { InsufficientFunds, OrderNotFound } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class acx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'acx', - 'name': 'ACX', - 'countries': [ 'AU' ], - 'rateLimit': 1000, - 'version': 'v2', - 'has': { - 'cancelOrder': true, - 'CORS': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchMarkets': true, - 'fetchOHLCV': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTime': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '12h': '720', - '1d': '1440', - '3d': '4320', - '1w': '10080', - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg', - 'extension': '.json', - 'api': 'https://acx.io/api', - 'www': 'https://acx.io', - 'doc': 'https://acx.io/documents/api_v2', - }, - 'api': { - 'public': { - 'get': [ - 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. - 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator - 'k', // Get OHLC(k line) of specific market - 'markets', // Get all available markets - 'order_book', // Get the order book of specified market - 'order_book/{market}', - 'tickers', // Get ticker of all markets - 'tickers/{market}', // Get ticker of specific market - 'timestamp', // Get server current time, in seconds since Unix epoch - 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. - 'trades/{market}', - ], - }, - 'private': { - 'get': [ - 'members/me', // Get your profile and accounts info - 'deposits', // Get your deposits history - 'deposit', // Get details of specific deposit - 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. - 'orders', // Get your orders, results is paginated - 'order', // Get information of specified order - 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. - 'withdraws', // Get your cryptocurrency withdraws - 'withdraw', // Get your cryptocurrency withdraw - ], - 'post': [ - 'orders', // Create a Sell/Buy order - 'orders/multi', // Create multiple sell/buy orders - 'orders/clear', // Cancel all my orders - 'order/delete', // Cancel an order - 'withdraw', // Create a withdraw - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': false, - 'percentage': true, - 'maker': 0.2 / 100, - 'taker': 0.2 / 100, - }, - 'funding': { - 'tierBased': false, - 'percentage': true, - 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account. - }, - }, - 'commonCurrencies': { - 'PLA': 'Plair', - }, - 'exceptions': { - '2002': InsufficientFunds, - '2003': OrderNotFound, - }, - }); - } - - async fetchMarkets (params = {}) { - const markets = await this.publicGetMarkets (params); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = market['id']; - const symbol = market['name']; - let baseId = this.safeString (market, 'base_unit'); - let quoteId = this.safeString (market, 'quote_unit'); - if ((baseId === undefined) || (quoteId === undefined)) { - const ids = symbol.split ('/'); - baseId = ids[0].toLowerCase (); - quoteId = ids[1].toLowerCase (); - } - let base = baseId.toUpperCase (); - let quote = quoteId.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - // todo: find out their undocumented precision and limits - const precision = { - 'amount': 8, - 'price': 8, - }; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'precision': precision, - 'info': market, - 'active': undefined, - 'limits': this.limits, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetMembersMe (params); - const balances = this.safeValue (response, 'accounts'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 300 - } - const orderbook = await this.publicGetDepth (this.extend (request, params)); - const timestamp = this.safeTimestamp (orderbook, 'timestamp'); - return this.parseOrderBook (orderbook, timestamp); - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.safeTimestamp (ticker, 'at'); - ticker = ticker['ticker']; - let symbol = undefined; - if (market) { - symbol = market['symbol']; - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetTickers (params); - const ids = Object.keys (response); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let market = undefined; - let symbol = id; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } else { - let base = id.slice (0, 3); - let quote = id.slice (3, 6); - base = base.toUpperCase (); - quote = quote.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - symbol = base + '/' + quote; - } - result[symbol] = this.parseTicker (response[id], market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTickersMarket (this.extend (request, params)); - return this.parseTicker (response, market); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const id = this.safeString (trade, 'tid'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': undefined, - 'side': undefined, - 'order': undefined, - 'takerOrMaker': undefined, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), - 'cost': this.safeFloat (trade, 'funds'), - 'fee': undefined, - }; - } - - async fetchTime (params = {}) { - const response = await this.publicGetTimestamp (params); - // - // 1594911427 - // - return response * 1000; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - return [ - this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (limit === undefined) { - limit = 500; // default is 30 - } - const request = { - 'market': market['id'], - 'period': this.timeframes[timeframe], - 'limit': limit, - }; - if (since !== undefined) { - request['timestamp'] = parseInt (since / 1000); - } - const response = await this.publicGetK (this.extend (request, params)); - return this.parseOHLCVs (response, market, timeframe, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'done': 'closed', - 'wait': 'open', - 'cancel': 'canceled', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - const marketId = this.safeString (order, 'market'); - const symbol = this.safeSymbol (marketId, market); - const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const status = this.parseOrderStatus (this.safeString (order, 'state')); - const type = this.safeString (order, 'type'); - const side = this.safeString (order, 'side'); - const id = this.safeString (order, 'id'); - return { - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': this.safeFloat (order, 'price'), - 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'volume'), - 'filled': this.safeFloat (order, 'executed_volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'trades': undefined, - 'fee': undefined, - 'info': order, - 'cost': undefined, - 'average': undefined, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': parseInt (id), - }; - const response = await this.privateGetOrder (this.extend (request, params)); - return this.parseOrder (response); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'market': this.marketId (symbol), - 'side': side, - 'volume': amount.toString (), - 'ord_type': type, - }; - if (type === 'limit') { - request['price'] = price.toString (); - } - const response = await this.privatePostOrders (this.extend (request, params)); - const marketId = this.safeValue (response, 'market'); - const market = this.safeValue (this.markets_by_id, marketId); - return this.parseOrder (response, market); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - const response = await this.privatePostOrderDelete (this.extend (request, params)); - const order = this.parseOrder (response); - const status = order['status']; - if (status === 'closed' || status === 'canceled') { - throw new OrderNotFound (this.id + ' ' + this.json (order)); - } - return order; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - // they have XRP but no docs on memo/tag - const request = { - 'currency': currency['id'], - 'sum': amount, - 'address': address, - }; - const response = await this.privatePostWithdraw (this.extend (request, params)); - // withdrawal response is undocumented - return { - 'info': response, - 'id': undefined, - }; - } - - nonce () { - return this.milliseconds (); - } - - encodeParams (params) { - if ('orders' in params) { - const orders = params['orders']; - let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); - for (let i = 0; i < orders.length; i++) { - const order = orders[i]; - const keys = Object.keys (order); - for (let k = 0; k < keys.length; k++) { - const key = keys[k]; - const value = order[key]; - query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); - } - } - return query; - } - return this.urlencode (this.keysort (params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let request = '/api/' + this.version + '/' + this.implodeParams (path, params); - if ('extension' in this.urls) { - request += this.urls['extension']; - } - const query = this.omit (params, this.extractParams (path)); - let url = this.urls['api'] + request; - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce ().toString (); - const query = this.encodeParams (this.extend ({ - 'access_key': this.apiKey, - 'tonce': nonce, - }, params)); - const auth = method + '|' + request + '|' + query; - const signed = this.hmac (this.encode (auth), this.encode (this.secret)); - const suffix = query + '&signature=' + signed; - if (method === 'GET') { - url += '?' + suffix; - } else { - body = suffix; - headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; - } - if (code === 400) { - const error = this.safeValue (response, 'error'); - const errorCode = this.safeString (error, 'code'); - const feedback = this.id + ' ' + this.json (response); - this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); - // fallback to default error handler - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],5:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],4:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -2467,6 +2007,7 @@ module.exports = class acx extends Exchange { const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, BadSymbol, InvalidOrder, PermissionDenied, InvalidAddress, AuthenticationError, InvalidNonce, BadRequest, InsufficientFunds, OrderNotFound } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -2655,8 +2196,8 @@ module.exports = class aofex extends Exchange { const symbol = base + '/' + quote; const numericId = this.safeInteger (market, 'id'); const precision = this.safeValue (precisions, id, {}); - const makerFee = this.safeFloat (market, 'maker_fee'); - const takerFee = this.safeFloat (market, 'taker_fee'); + const makerFee = this.safeNumber (market, 'maker_fee'); + const takerFee = this.safeNumber (market, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -2674,12 +2215,12 @@ module.exports = class aofex extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -2707,11 +2248,11 @@ module.exports = class aofex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -2790,11 +2331,11 @@ module.exports = class aofex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -2817,8 +2358,8 @@ module.exports = class aofex extends Exchange { return { 'info': response, 'symbol': symbol, - 'maker': this.safeFloat (result, 'fromFee'), - 'taker': this.safeFloat (result, 'toFee'), + 'maker': this.safeNumber (result, 'fromFee'), + 'taker': this.safeNumber (result, 'toFee'), }; } @@ -2875,8 +2416,8 @@ module.exports = class aofex extends Exchange { if (market) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); let change = undefined; if (symbol !== undefined) { change = parseFloat (this.priceToPrecision (symbol, last - open)); @@ -2885,8 +2426,8 @@ module.exports = class aofex extends Exchange { } const average = this.sum (last, open) / 2; const percentage = change / open * 100; - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); let vwap = this.vwap (baseVolume, quoteVolume); if (vwap !== undefined) { vwap = parseFloat (this.priceToPrecision (symbol, vwap)); @@ -2895,8 +2436,8 @@ module.exports = class aofex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -3014,13 +2555,15 @@ module.exports = class aofex extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'number'); - let cost = this.safeFloat (trade, 'total_price'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'number'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total_price'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -3164,21 +2707,21 @@ module.exports = class aofex extends Exchange { const orderType = this.safeString (order, 'type'); const type = (orderType === '2') ? 'limit' : 'market'; const side = this.safeString (order, 'side'); - // const amount = this.safeFloat (order, 'number'); - // const price = this.safeFloat (order, 'price'); + // const amount = this.safeNumber (order, 'number'); + // const price = this.safeNumber (order, 'price'); let cost = undefined; let price = undefined; let amount = undefined; let average = undefined; - const number = this.safeFloat (order, 'number'); - const totalPrice = this.safeFloat (order, 'total_price'); + const number = this.safeNumber (order, 'number'); + const totalPrice = this.safeNumber (order, 'total_price'); if (type === 'limit') { amount = number; - price = this.safeFloat (order, 'price'); + price = this.safeNumber (order, 'price'); } else { - average = this.safeFloat (order, 'deal_price'); + average = this.safeNumber (order, 'deal_price'); if (side === 'buy') { - amount = this.safeFloat (order, 'deal_number'); + amount = this.safeNumber (order, 'deal_number'); } else { amount = number; } @@ -3561,7 +3104,1693 @@ module.exports = class aofex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],6:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],5:[function(require,module,exports){ +'use strict'; + +// --------------------------------------------------------------------------- + +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); + +// --------------------------------------------------------------------------- + +module.exports = class ascendex extends Exchange { + describe () { + return this.deepExtend (super.describe (), { + 'id': 'ascendex', + 'name': 'AscendEX', + 'countries': [ 'SG', 'CN' ], // Singapore, China + 'rateLimit': 500, + // new metainfo interface + 'has': { + 'CORS': false, + 'fetchMarkets': true, + 'fetchCurrencies': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchOHLCV': true, + 'fetchTrades': true, + 'fetchAccounts': true, + 'fetchBalance': true, + 'createOrder': true, + 'cancelOrder': true, + 'cancelAllOrders': true, + 'fetchDepositAddress': true, + 'fetchTransactions': true, + 'fetchDeposits': true, + 'fetchWithdrawals': true, + 'fetchOrder': true, + 'fetchOrders': true, + 'fetchOpenOrders': true, + 'fetchClosedOrders': true, + }, + 'timeframes': { + '1m': '1', + '5m': '5', + '15m': '15', + '30m': '30', + '1h': '60', + '2h': '120', + '4h': '240', + '6h': '360', + '12h': '720', + '1d': '1d', + '1w': '1w', + '1M': '1m', + }, + 'version': 'v1', + 'urls': { + 'logo': 'https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg', + 'api': 'https://ascendex.com', + 'test': 'https://bitmax-test.io', + 'www': 'https://ascendex.com', + 'doc': [ + 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', + ], + 'fees': 'https://ascendex.com/en/feerate/transactionfee-traderate', + 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', + }, + 'api': { + 'public': { + 'get': [ + 'assets', + 'products', + 'ticker', + 'barhist/info', + 'barhist', + 'depth', + 'trades', + 'cash/assets', // not documented + 'cash/products', // not documented + 'margin/assets', // not documented + 'margin/products', // not documented + 'futures/collateral', + 'futures/contracts', + 'futures/ref-px', + 'futures/market-data', + 'futures/funding-rates', + ], + }, + 'accountCategory': { + 'get': [ + 'balance', + 'order/open', + 'order/status', + 'order/hist/current', + 'risk', + ], + 'post': [ + 'order', + 'order/batch', + ], + 'delete': [ + 'order', + 'order/all', + 'order/batch', + ], + }, + 'accountGroup': { + 'get': [ + 'cash/balance', + 'margin/balance', + 'margin/risk', + 'transfer', + 'futures/collateral-balance', + 'futures/position', + 'futures/risk', + 'futures/funding-payments', + 'order/hist', + ], + 'post': [ + 'futures/transfer/deposit', + 'futures/transfer/withdraw', + ], + }, + 'private': { + 'get': [ + 'info', + 'wallet/transactions', + 'wallet/deposit/address', // not documented + ], + }, + }, + 'fees': { + 'trading': { + 'feeSide': 'get', + 'tierBased': true, + 'percentage': true, + 'taker': 0.002, + 'maker': 0.002, + }, + }, + 'precisionMode': TICK_SIZE, + 'options': { + 'account-category': 'cash', // 'cash'/'margin'/'futures' + 'account-group': undefined, + 'fetchClosedOrders': { + 'method': 'accountGroupGetOrderHist', // 'accountGroupGetAccountCategoryOrderHistCurrent' + }, + }, + 'exceptions': { + 'exact': { + // not documented + '1900': BadRequest, // {"code":1900,"message":"Invalid Http Request Input"} + '2100': AuthenticationError, // {"code":2100,"message":"ApiKeyFailure"} + '5002': BadSymbol, // {"code":5002,"message":"Invalid Symbol"} + '6001': BadSymbol, // {"code":6001,"message":"Trading is disabled on symbol."} + '6010': InsufficientFunds, // {'code': 6010, 'message': 'Not enough balance.'} + '60060': InvalidOrder, // { 'code': 60060, 'message': 'The order is already filled or canceled.' } + '600503': InvalidOrder, // {"code":600503,"message":"Notional is too small."} + // documented + '100001': BadRequest, // INVALID_HTTP_INPUT Http request is invalid + '100002': BadRequest, // DATA_NOT_AVAILABLE Some required data is missing + '100003': BadRequest, // KEY_CONFLICT The same key exists already + '100004': BadRequest, // INVALID_REQUEST_DATA The HTTP request contains invalid field or argument + '100005': BadRequest, // INVALID_WS_REQUEST_DATA Websocket request contains invalid field or argument + '100006': BadRequest, // INVALID_ARGUMENT The arugment is invalid + '100007': BadRequest, // ENCRYPTION_ERROR Something wrong with data encryption + '100008': BadSymbol, // SYMBOL_ERROR Symbol does not exist or not valid for the request + '100009': AuthenticationError, // AUTHORIZATION_NEEDED Authorization is require for the API access or request + '100010': BadRequest, // INVALID_OPERATION The action is invalid or not allowed for the account + '100011': BadRequest, // INVALID_TIMESTAMP Not a valid timestamp + '100012': BadRequest, // INVALID_STR_FORMAT String format does not + '100013': BadRequest, // INVALID_NUM_FORMAT Invalid number input + '100101': ExchangeError, // UNKNOWN_ERROR Some unknown error + '150001': BadRequest, // INVALID_JSON_FORMAT Require a valid json object + '200001': AuthenticationError, // AUTHENTICATION_FAILED Authorization failed + '200002': ExchangeError, // TOO_MANY_ATTEMPTS Tried and failed too many times + '200003': ExchangeError, // ACCOUNT_NOT_FOUND Account not exist + '200004': ExchangeError, // ACCOUNT_NOT_SETUP Account not setup properly + '200005': ExchangeError, // ACCOUNT_ALREADY_EXIST Account already exist + '200006': ExchangeError, // ACCOUNT_ERROR Some error related with error + '200007': ExchangeError, // CODE_NOT_FOUND + '200008': ExchangeError, // CODE_EXPIRED Code expired + '200009': ExchangeError, // CODE_MISMATCH Code does not match + '200010': AuthenticationError, // PASSWORD_ERROR Wrong assword + '200011': ExchangeError, // CODE_GEN_FAILED Do not generate required code promptly + '200012': ExchangeError, // FAKE_COKE_VERIFY + '200013': ExchangeError, // SECURITY_ALERT Provide security alert message + '200014': PermissionDenied, // RESTRICTED_ACCOUNT Account is restricted for certain activity, such as trading, or withdraw. + '200015': PermissionDenied, // PERMISSION_DENIED No enough permission for the operation + '300001': InvalidOrder, // INVALID_PRICE Order price is invalid + '300002': InvalidOrder, // INVALID_QTY Order size is invalid + '300003': InvalidOrder, // INVALID_SIDE Order side is invalid + '300004': InvalidOrder, // INVALID_NOTIONAL Notional is too small or too large + '300005': InvalidOrder, // INVALID_TYPE Order typs is invalid + '300006': InvalidOrder, // INVALID_ORDER_ID Order id is invalid + '300007': InvalidOrder, // INVALID_TIME_IN_FORCE Time In Force in order request is invalid + '300008': InvalidOrder, // INVALID_ORDER_PARAMETER Some order parameter is invalid + '300009': InvalidOrder, // TRADING_VIOLATION Trading violation on account or asset + '300011': InsufficientFunds, // INVALID_BALANCE No enough account or asset balance for the trading + '300012': BadSymbol, // INVALID_PRODUCT Not a valid product supported by exchange + '300013': InvalidOrder, // INVALID_BATCH_ORDER Some or all orders are invalid in batch order request + '300020': InvalidOrder, // TRADING_RESTRICTED There is some trading restriction on account or asset + '300021': InvalidOrder, // TRADING_DISABLED Trading is disabled on account or asset + '300031': InvalidOrder, // NO_MARKET_PRICE No market price for market type order trading + '310001': InsufficientFunds, // INVALID_MARGIN_BALANCE No enough margin balance + '310002': InvalidOrder, // INVALID_MARGIN_ACCOUNT Not a valid account for margin trading + '310003': InvalidOrder, // MARGIN_TOO_RISKY Leverage is too high + '310004': BadSymbol, // INVALID_MARGIN_ASSET This asset does not support margin trading + '310005': InvalidOrder, // INVALID_REFERENCE_PRICE There is no valid reference price + '510001': ExchangeError, // SERVER_ERROR Something wrong with server. + '900001': ExchangeError, // HUMAN_CHALLENGE Human change do not pass + }, + 'broad': {}, + }, + 'commonCurrencies': { + 'BOND': 'BONDED', + 'BTCBEAR': 'BEAR', + 'BTCBULL': 'BULL', + }, + }); + } + + getAccount (params = {}) { + // get current or provided bitmax sub-account + const account = this.safeValue (params, 'account', this.options['account']); + return account.toLowerCase ().capitalize (); + } + + async fetchCurrencies (params = {}) { + const assets = await this.publicGetAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode" : "LTCBULL", + // "assetName" : "3X Long LTC Token", + // "precisionScale" : 9, + // "nativeScale" : 4, + // "withdrawalFee" : "0.2", + // "minWithdrawalAmt" : "1.0", + // "status" : "Normal" + // }, + // ] + // } + // + const margin = await this.publicGetMarginAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode":"BTT", + // "borrowAssetCode":"BTT-B", + // "interestAssetCode":"BTT-I", + // "nativeScale":0, + // "numConfirmations":1, + // "withdrawFee":"100.0", + // "minWithdrawalAmt":"1000.0", + // "statusCode":"Normal", + // "statusMessage":"", + // "interestRate":"0.001" + // } + // ] + // } + // + const cash = await this.publicGetCashAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode":"LTCBULL", + // "nativeScale":4, + // "numConfirmations":20, + // "withdrawFee":"0.2", + // "minWithdrawalAmt":"1.0", + // "statusCode":"Normal", + // "statusMessage":"" + // } + // ] + // } + // + const assetsData = this.safeValue (assets, 'data', []); + const marginData = this.safeValue (margin, 'data', []); + const cashData = this.safeValue (cash, 'data', []); + const assetsById = this.indexBy (assetsData, 'assetCode'); + const marginById = this.indexBy (marginData, 'assetCode'); + const cashById = this.indexBy (cashData, 'assetCode'); + const dataById = this.deepExtend (assetsById, marginById, cashById); + const ids = Object.keys (dataById); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + const currency = dataById[id]; + const code = this.safeCurrencyCode (id); + const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); + // why would the exchange API have different names for the same field + const fee = this.safeNumber2 (currency, 'withdrawFee', 'withdrawalFee'); + const status = this.safeString2 (currency, 'status', 'statusCode'); + const active = (status === 'Normal'); + const margin = ('borrowAssetCode' in currency); + result[code] = { + 'id': id, + 'code': code, + 'info': currency, + 'type': undefined, + 'margin': margin, + 'name': this.safeString (currency, 'assetName'), + 'active': active, + 'fee': fee, + 'precision': precision, + 'limits': { + 'amount': { + 'min': Math.pow (10, -precision), + 'max': undefined, + }, + 'price': { + 'min': Math.pow (10, -precision), + 'max': undefined, + }, + 'cost': { + 'min': undefined, + 'max': undefined, + }, + 'withdraw': { + 'min': this.safeNumber (currency, 'minWithdrawalAmt'), + 'max': undefined, + }, + }, + }; + } + return result; + } + + async fetchMarkets (params = {}) { + const products = await this.publicGetProducts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"LBA/BTC", + // "baseAsset":"LBA", + // "quoteAsset":"BTC", + // "status":"Normal", + // "minNotional":"0.000625", + // "maxNotional":"6.25", + // "marginTradable":false, + // "commissionType":"Quote", + // "commissionReserveRate":"0.001", + // "tickSize":"0.000000001", + // "lotSize":"1" + // }, + // ] + // } + // + const cash = await this.publicGetCashProducts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"QTUM/BTC", + // "domain":"BTC", + // "tradingStartTime":1569506400000, + // "collapseDecimals":"0.0001,0.000001,0.00000001", + // "minQty":"0.000000001", + // "maxQty":"1000000000", + // "minNotional":"0.000625", + // "maxNotional":"12.5", + // "statusCode":"Normal", + // "statusMessage":"", + // "tickSize":"0.00000001", + // "useTick":false, + // "lotSize":"0.1", + // "useLot":false, + // "commissionType":"Quote", + // "commissionReserveRate":"0.001", + // "qtyScale":1, + // "priceScale":8, + // "notionalScale":4 + // } + // ] + // } + // + const futures = await this.publicGetFuturesContracts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"BTC-PERP", + // "tradingStartTime":1579701600000, + // "collapseDecimals":"1,0.1,0.01", + // "minQty":"0.000000001", + // "maxQty":"1000000000", + // "minNotional":"5", + // "maxNotional":"1000000", + // "statusCode":"Normal", + // "statusMessage":"", + // "tickSize":"0.25", + // "lotSize":"0.0001", + // "priceScale":2, + // "qtyScale":4, + // "notionalScale":2 + // } + // ] + // } + // + const productsData = this.safeValue (products, 'data', []); + const productsById = this.indexBy (productsData, 'symbol'); + const cashData = this.safeValue (cash, 'data', []); + const futuresData = this.safeValue (futures, 'data', []); + const cashAndFuturesData = this.arrayConcat (cashData, futuresData); + const cashAndFuturesById = this.indexBy (cashAndFuturesData, 'symbol'); + const dataById = this.deepExtend (productsById, cashAndFuturesById); + const ids = Object.keys (dataById); + const result = []; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + const market = dataById[id]; + const baseId = this.safeString (market, 'baseAsset'); + const quoteId = this.safeString (market, 'quoteAsset'); + const base = this.safeCurrencyCode (baseId); + const quote = this.safeCurrencyCode (quoteId); + const precision = { + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), + }; + const status = this.safeString (market, 'status'); + const active = (status === 'Normal'); + const type = ('useLot' in market) ? 'spot' : 'future'; + const spot = (type === 'spot'); + const future = (type === 'future'); + let symbol = id; + if (!future) { + symbol = base + '/' + quote; + } + result.push ({ + 'id': id, + 'symbol': symbol, + 'base': base, + 'quote': quote, + 'baseId': baseId, + 'quoteId': quoteId, + 'info': market, + 'type': type, + 'spot': spot, + 'future': future, + 'active': active, + 'precision': precision, + 'limits': { + 'amount': { + 'min': this.safeNumber (market, 'minQty'), + 'max': this.safeNumber (market, 'maxQty'), + }, + 'price': { + 'min': this.safeNumber (market, 'tickSize'), + 'max': undefined, + }, + 'cost': { + 'min': this.safeNumber (market, 'minNotional'), + 'max': this.safeNumber (market, 'maxNotional'), + }, + }, + }); + } + return result; + } + + async fetchAccounts (params = {}) { + let accountGroup = this.safeString (this.options, 'account-group'); + let response = undefined; + if (accountGroup === undefined) { + response = await this.privateGetInfo (params); + // + // { + // "code":0, + // "data":{ + // "email":"igor.kroitor@gmail.com", + // "accountGroup":8, + // "viewPermission":true, + // "tradePermission":true, + // "transferPermission":true, + // "cashAccount":["cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda"], + // "marginAccount":["martXoh1v1N3EMQC5FDtSj5VHso8aI2Z"], + // "futuresAccount":["futc9r7UmFJAyBY2rE3beA2JFxav2XFF"], + // "userUID":"U6491137460" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + accountGroup = this.safeString (data, 'accountGroup'); + this.options['account-group'] = accountGroup; + } + return [ + { + 'id': accountGroup, + 'type': undefined, + 'currency': undefined, + 'info': response, + }, + ]; + } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchBalance', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeString (account, 'id'); + const request = { + 'account-group': accountGroup, + }; + let method = 'accountCategoryGetBalance'; + if (accountCategory === 'futures') { + method = 'accountGroupGetFuturesCollateralBalance'; + } else { + request['account-category'] = accountCategory; + } + const response = await this[method] (this.extend (request, params)); + // + // cash + // + // { + // 'code': 0, + // 'data': [ + // { + // 'asset': 'BCHSV', + // 'totalBalance': '64.298000048', + // 'availableBalance': '64.298000048', + // }, + // ] + // } + // + // margin + // + // { + // 'code': 0, + // 'data': [ + // { + // 'asset': 'BCHSV', + // 'totalBalance': '64.298000048', + // 'availableBalance': '64.298000048', + // 'borrowed': '0', + // 'interest': '0', + // }, + // ] + // } + // + // futures + // + // { + // "code":0, + // "data":[ + // {"asset":"BTC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"9456.59"}, + // {"asset":"ETH","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"235.95"}, + // {"asset":"USDT","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"}, + // {"asset":"USDC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00035"}, + // {"asset":"PAX","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00045"}, + // {"asset":"USDTR","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"} + // ] + // } + // + const result = { 'info': response }; + const balances = this.safeValue (response, 'data', []); + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); + const account = this.account (); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async fetchOrderBook (symbol, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + const response = await this.publicGetDepth (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "m":"depth-snapshot", + // "symbol":"BTC-PERP", + // "data":{ + // "ts":1590223998202, + // "seqnum":115444921, + // "asks":[ + // ["9207.5","18.2383"], + // ["9207.75","18.8235"], + // ["9208","10.7873"], + // ], + // "bids":[ + // ["9207.25","0.4009"], + // ["9207","0.003"], + // ["9206.5","0.003"], + // ] + // } + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const orderbook = this.safeValue (data, 'data', {}); + const timestamp = this.safeInteger (orderbook, 'ts'); + const result = this.parseOrderBook (orderbook, timestamp); + result['nonce'] = this.safeInteger (orderbook, 'seqnum'); + return result; + } + + parseTicker (ticker, market = undefined) { + // + // { + // "symbol":"QTUM/BTC", + // "open":"0.00016537", + // "close":"0.00019077", + // "high":"0.000192", + // "low":"0.00016537", + // "volume":"846.6", + // "ask":["0.00018698","26.2"], + // "bid":["0.00018408","503.7"], + // "type":"spot" + // } + // + const timestamp = undefined; + const marketId = this.safeString (ticker, 'symbol'); + let symbol = undefined; + if (marketId in this.markets_by_id) { + market = this.markets_by_id[marketId]; + } else if (marketId !== undefined) { + const type = this.safeString (ticker, 'type'); + if (type === 'spot') { + const [ baseId, quoteId ] = marketId.split ('/'); + const base = this.safeCurrencyCode (baseId); + const quote = this.safeCurrencyCode (quoteId); + symbol = base + '/' + quote; + } + } + if ((symbol === undefined) && (market !== undefined)) { + symbol = market['symbol']; + } + const close = this.safeNumber (ticker, 'close'); + const bid = this.safeValue (ticker, 'bid', []); + const ask = this.safeValue (ticker, 'ask', []); + const open = this.safeNumber (ticker, 'open'); + let change = undefined; + let percentage = undefined; + let average = undefined; + if ((open !== undefined) && (close !== undefined)) { + change = close - open; + if (open > 0) { + percentage = change / open * 100; + } + average = this.sum (open, close) / 2; + } + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 0), + 'bidVolume': this.safeNumber (bid, 1), + 'ask': this.safeNumber (ask, 0), + 'askVolume': this.safeNumber (ask, 1), + 'vwap': undefined, + 'open': open, + 'close': close, + 'last': close, + 'previousClose': undefined, // previous day close + 'change': change, + 'percentage': percentage, + 'average': average, + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + const response = await this.publicGetTicker (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "symbol":"BTC-PERP", // or "BTC/USDT" + // "open":"9073", + // "close":"9185.75", + // "high":"9185.75", + // "low":"9185.75", + // "volume":"576.8334", + // "ask":["9185.75","15.5863"], + // "bid":["9185.5","0.003"], + // "type":"derivatives", // or "spot" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + return this.parseTicker (data, market); + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (symbols !== undefined) { + const marketIds = this.marketIds (symbols); + request['symbol'] = marketIds.join (','); + } + const response = await this.publicGetTicker (this.extend (request, params)); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"QTUM/BTC", + // "open":"0.00016537", + // "close":"0.00019077", + // "high":"0.000192", + // "low":"0.00016537", + // "volume":"846.6", + // "ask":["0.00018698","26.2"], + // "bid":["0.00018408","503.7"], + // "type":"spot" + // } + // ] + // } + // + const data = this.safeValue (response, 'data', []); + return this.parseTickers (data, symbols); + } + + parseOHLCV (ohlcv, market = undefined) { + // + // { + // "m":"bar", + // "s":"BTC/USDT", + // "data":{ + // "i":"1", + // "ts":1590228000000, + // "o":"9139.59", + // "c":"9131.94", + // "h":"9139.99", + // "l":"9121.71", + // "v":"25.20648" + // } + // } + // + const data = this.safeValue (ohlcv, 'data', {}); + return [ + this.safeInteger (data, 'ts'), + this.safeNumber (data, 'o'), + this.safeNumber (data, 'h'), + this.safeNumber (data, 'l'), + this.safeNumber (data, 'c'), + this.safeNumber (data, 'v'), + ]; + } + + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + 'interval': this.timeframes[timeframe], + }; + // if since and limit are not specified + // the exchange will return just 1 last candle by default + const duration = this.parseTimeframe (timeframe); + const options = this.safeValue (this.options, 'fetchOHLCV', {}); + const defaultLimit = this.safeInteger (options, 'limit', 500); + if (since !== undefined) { + request['from'] = since; + if (limit === undefined) { + limit = defaultLimit; + } else { + limit = Math.min (limit, defaultLimit); + } + request['to'] = this.sum (since, limit * duration * 1000, 1); + } else if (limit !== undefined) { + request['n'] = limit; // max 500 + } + const response = await this.publicGetBarhist (this.extend (request, params)); + // + // { + // "code":0, + // "data":[ + // { + // "m":"bar", + // "s":"BTC/USDT", + // "data":{ + // "i":"1", + // "ts":1590228000000, + // "o":"9139.59", + // "c":"9131.94", + // "h":"9139.99", + // "l":"9121.71", + // "v":"25.20648" + // } + // } + // ] + // } + // + const data = this.safeValue (response, 'data', []); + return this.parseOHLCVs (data, market, timeframe, since, limit); + } + + parseTrade (trade, market = undefined) { + // + // public fetchTrades + // + // { + // "p":"9128.5", // price + // "q":"0.0030", // quantity + // "ts":1590229002385, // timestamp + // "bm":false, // if true, the buyer is the market maker, we only use this field to "define the side" of a public trade + // "seqnum":180143985289898554 + // } + // + const timestamp = this.safeInteger (trade, 'ts'); + const priceString = this.safeString2 (trade, 'price', 'p'); + const amountString = this.safeString (trade, 'q'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const buyerIsMaker = this.safeValue (trade, 'bm', false); + const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; + const side = buyerIsMaker ? 'buy' : 'sell'; + let symbol = undefined; + if ((symbol === undefined) && (market !== undefined)) { + symbol = market['symbol']; + } + return { + 'info': trade, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'symbol': symbol, + 'id': undefined, + 'order': undefined, + 'type': undefined, + 'takerOrMaker': makerOrTaker, + 'side': side, + 'price': price, + 'amount': amount, + 'cost': cost, + 'fee': undefined, + }; + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + if (limit !== undefined) { + request['n'] = limit; // max 100 + } + const response = await this.publicGetTrades (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "m":"trades", + // "symbol":"BTC-PERP", + // "data":[ + // {"p":"9128.5","q":"0.0030","ts":1590229002385,"bm":false,"seqnum":180143985289898554}, + // {"p":"9129","q":"0.0030","ts":1590229002642,"bm":false,"seqnum":180143985289898587}, + // {"p":"9129.5","q":"0.0030","ts":1590229021306,"bm":false,"seqnum":180143985289899043} + // ] + // } + // } + // + const records = this.safeValue (response, 'data', []); + const trades = this.safeValue (records, 'data', []); + return this.parseTrades (trades, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'PendingNew': 'open', + 'New': 'open', + 'PartiallyFilled': 'open', + 'Filled': 'closed', + 'Canceled': 'canceled', + 'Rejected': 'rejected', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + // + // createOrder + // + // { + // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", + // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", + // "orderType": "Market", + // "symbol": "BTC/USDT", + // "timestamp": 1573576916201 + // } + // + // fetchOrder, fetchOpenOrders, fetchClosedOrders + // + // { + // "symbol": "BTC/USDT", + // "price": "8131.22", + // "orderQty": "0.00082", + // "orderType": "Market", + // "avgPx": "7392.02", + // "cumFee": "0.005152238", + // "cumFilledQty": "0.00082", + // "errorCode": "", + // "feeAsset": "USDT", + // "lastExecTime": 1575953151764, + // "orderId": "a16eee20b6750866943712zWEDdAjt3", + // "seqNum": 2623469, + // "side": "Buy", + // "status": "Filled", + // "stopPrice": "", + // "execInst": "NULL_VAL" + // } + // + // { + // "ac": "FUTURES", + // "accountId": "testabcdefg", + // "avgPx": "0", + // "cumFee": "0", + // "cumQty": "0", + // "errorCode": "NULL_VAL", + // "execInst": "NULL_VAL", + // "feeAsset": "USDT", + // "lastExecTime": 1584072844085, + // "orderId": "r170d21956dd5450276356bbtcpKa74", + // "orderQty": "1.1499", + // "orderType": "Limit", + // "price": "4000", + // "sendingTime": 1584072841033, + // "seqNum": 24105338, + // "side": "Buy", + // "status": "Canceled", + // "stopPrice": "", + // "symbol": "BTC-PERP" + // }, + // + const status = this.parseOrderStatus (this.safeString (order, 'status')); + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '/'); + const timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); + const lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const average = this.safeNumber (order, 'avgPx'); + const filled = this.safeNumber2 (order, 'cumFilledQty', 'cumQty'); + const id = this.safeString (order, 'orderId'); + let clientOrderId = this.safeString (order, 'id'); + if (clientOrderId !== undefined) { + if (clientOrderId.length < 1) { + clientOrderId = undefined; + } + } + const type = this.safeStringLower (order, 'orderType'); + const side = this.safeStringLower (order, 'side'); + const feeCost = this.safeNumber (order, 'cumFee'); + let fee = undefined; + if (feeCost !== undefined) { + const feeCurrencyId = this.safeString (order, 'feeAsset'); + const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); + fee = { + 'cost': feeCost, + 'currency': feeCurrencyCode, + }; + } + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ + 'info': order, + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': lastTradeTimestamp, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': price, + 'stopPrice': stopPrice, + 'amount': amount, + 'cost': undefined, + 'average': average, + 'filled': filled, + 'remaining': undefined, + 'status': status, + 'fee': fee, + 'trades': undefined, + }); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const market = this.market (symbol); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'createOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'symbol': market['id'], + 'time': this.milliseconds (), + 'orderQty': this.amountToPrecision (symbol, amount), + 'orderType': type, // "limit", "market", "stop_market", "stop_limit" + 'side': side, // "buy" or "sell" + // 'orderPrice': this.priceToPrecision (symbol, price), + // 'stopPrice': this.priceToPrecision (symbol, stopPrice), // required for stop orders + // 'postOnly': 'false', // 'false', 'true' + // 'timeInForce': 'GTC', // GTC, IOC, FOK + // 'respInst': 'ACK', // ACK, 'ACCEPT, DONE + }; + if (clientOrderId !== undefined) { + request['id'] = clientOrderId; + params = this.omit (params, [ 'clientOrderId', 'id' ]); + } + if ((type === 'limit') || (type === 'stop_limit')) { + request['orderPrice'] = this.priceToPrecision (symbol, price); + } + if ((type === 'stop_limit') || (type === 'stop_market')) { + const stopPrice = this.safeNumber (params, 'stopPrice'); + if (stopPrice === undefined) { + throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); + } else { + request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); + params = this.omit (params, 'stopPrice'); + } + } + const response = await this.accountCategoryPostOrder (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "ac": "MARGIN", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "action": "place-order", + // "info": { + // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", + // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", + // "orderType": "Market", + // "symbol": "BTC/USDT", + // "timestamp": 1573576916201 + // }, + // "status": "Ack" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const info = this.safeValue (data, 'info', {}); + return this.parseOrder (info, market); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'orderId': id, + }; + const response = await this.accountCategoryGetOrderStatus (this.extend (request, params)); + // + // { + // "code": 0, + // "accountCategory": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "data": [ + // { + // "symbol": "BTC/USDT", + // "price": "8131.22", + // "orderQty": "0.00082", + // "orderType": "Market", + // "avgPx": "7392.02", + // "cumFee": "0.005152238", + // "cumFilledQty": "0.00082", + // "errorCode": "", + // "feeAsset": "USDT", + // "lastExecTime": 1575953151764, + // "orderId": "a16eee20b6750866943712zWEDdAjt3", + // "seqNum": 2623469, + // "side": "Buy", + // "status": "Filled", + // "stopPrice": "", + // "execInst": "NULL_VAL" + // } + // ] + // } + // + const data = this.safeValue (response, 'data', {}); + return this.parseOrder (data); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + } + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchOpenOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + }; + const response = await this.accountCategoryGetOrderOpen (this.extend (request, params)); + // + // { + // "ac": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "code": 0, + // "data": [ + // { + // "avgPx": "0", // Average filled price of the order + // "cumFee": "0", // cumulative fee paid for this order + // "cumFilledQty": "0", // cumulative filled quantity + // "errorCode": "", // error code; could be empty + // "feeAsset": "USDT", // fee asset + // "lastExecTime": 1576019723550, // The last execution time of the order + // "orderId": "s16ef21882ea0866943712034f36d83", // server provided orderId + // "orderQty": "0.0083", // order quantity + // "orderType": "Limit", // order type + // "price": "7105", // order price + // "seqNum": 8193258, // sequence number + // "side": "Buy", // order side + // "status": "New", // order status on matching engine + // "stopPrice": "", // only available for stop market and stop limit orders; otherwise empty + // "symbol": "BTC/USDT", + // "execInst": "NULL_VAL" // execution instruction + // }, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + if (accountCategory === 'futures') { + return this.parseOrders (data, market, since, limit); + } + // a workaround for https://github.com/ccxt/ccxt/issues/7187 + const orders = []; + for (let i = 0; i < data.length; i++) { + const order = this.parseOrder (data[i], market); + orders.push (order); + } + return this.filterBySymbolSinceLimit (orders, symbol, since, limit); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + } + const defaultAccountCategory = this.safeString (this.options, 'account-category'); + const options = this.safeValue (this.options, 'fetchClosedOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + // 'category': accountCategory, + // 'symbol': market['id'], + // 'orderType': 'market', // optional, string + // 'side': 'buy', // or 'sell', optional, case insensitive. + // 'status': 'Filled', // "Filled", "Canceled", or "Rejected" + // 'startTime': exchange.milliseconds (), + // 'endTime': exchange.milliseconds (), + // 'page': 1, + // 'pageSize': 100, + }; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const method = this.safeValue (options, 'method', 'accountGroupGetOrderHist'); + if (method === 'accountGroupGetOrderHist') { + if (accountCategory !== undefined) { + request['category'] = accountCategory; + } + } else { + request['account-category'] = accountCategory; + } + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['pageSize'] = limit; + } + const response = await this[method] (this.extend (request, params)); + // + // accountCategoryGetOrderHistCurrent + // + // { + // "code":0, + // "accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda", + // "ac":"CASH", + // "data":[ + // { + // "seqNum":15561826728, + // "orderId":"a17294d305c0U6491137460bethu7kw9", + // "symbol":"ETH/USDT", + // "orderType":"Limit", + // "lastExecTime":1591635618200, + // "price":"200", + // "orderQty":"0.1", + // "side":"Buy", + // "status":"Canceled", + // "avgPx":"0", + // "cumFilledQty":"0", + // "stopPrice":"", + // "errorCode":"", + // "cumFee":"0", + // "feeAsset":"USDT", + // "execInst":"NULL_VAL" + // } + // ] + // } + // + // accountGroupGetOrderHist + // + // { + // "code": 0, + // "data": { + // "data": [ + // { + // "ac": "FUTURES", + // "accountId": "testabcdefg", + // "avgPx": "0", + // "cumFee": "0", + // "cumQty": "0", + // "errorCode": "NULL_VAL", + // "execInst": "NULL_VAL", + // "feeAsset": "USDT", + // "lastExecTime": 1584072844085, + // "orderId": "r170d21956dd5450276356bbtcpKa74", + // "orderQty": "1.1499", + // "orderType": "Limit", + // "price": "4000", + // "sendingTime": 1584072841033, + // "seqNum": 24105338, + // "side": "Buy", + // "status": "Canceled", + // "stopPrice": "", + // "symbol": "BTC-PERP" + // }, + // ], + // "hasNext": False, + // "limit": 500, + // "page": 1, + // "pageSize": 20 + // } + // } + // + let data = this.safeValue (response, 'data'); + const isArray = Array.isArray (data); + if (!isArray) { + data = this.safeValue (data, 'data', []); + } + return this.parseOrders (data, market, since, limit); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument'); + } + await this.loadMarkets (); + await this.loadAccounts (); + const market = this.market (symbol); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'cancelOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'symbol': market['id'], + 'time': this.milliseconds (), + 'id': 'foobar', + }; + if (clientOrderId === undefined) { + request['orderId'] = id; + } else { + request['id'] = clientOrderId; + params = this.omit (params, [ 'clientOrderId', 'id' ]); + } + const response = await this.accountCategoryDeleteOrder (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "ac": "CASH", + // "action": "cancel-order", + // "status": "Ack", + // "info": { + // "id": "wv8QGquoeamhssvQBeHOHGQCGlcBjj23", + // "orderId": "16e6198afb4s8bXHbAwwoqDo2ebc19dc", + // "orderType": "", // could be empty + // "symbol": "ETH/USDT", + // "timestamp": 1573594877822 + // } + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const info = this.safeValue (data, 'info', {}); + return this.parseOrder (info, market); + } + + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'cancelAllOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'time': this.milliseconds (), + }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.accountCategoryDeleteOrderAll (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "ac": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "action": "cancel-all", + // "info": { + // "id": "2bmYvi7lyTrneMzpcJcf2D7Pe9V1P9wy", + // "orderId": "", + // "orderType": "NULL_VAL", + // "symbol": "", + // "timestamp": 1574118495462 + // }, + // "status": "Ack" + // } + // } + // + return response; + } + + parseDepositAddress (depositAddress, currency = undefined) { + // + // { + // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // destTag: "", + // tagType: "", + // tagId: "", + // chainName: "ERC20", + // numConfirmations: 20, + // withdrawalFee: 1, + // nativeScale: 4, + // tips: [] + // } + // + const address = this.safeString (depositAddress, 'address'); + const tagId = this.safeString (depositAddress, 'tagId'); + const tag = this.safeString (depositAddress, tagId); + this.checkAddress (address); + const code = (currency === undefined) ? undefined : currency['code']; + return { + 'currency': code, + 'address': address, + 'tag': tag, + 'info': depositAddress, + }; + } + + async fetchDepositAddress (code, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const chainName = this.safeString (params, 'chainName'); + params = this.omit (params, 'chainName'); + const request = { + 'asset': currency['id'], + }; + const response = await this.privateGetWalletDepositAddress (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "asset":"USDT", + // "assetName":"Tether", + // "address":[ + // { + // "address":"1N22odLHXnLPCjC8kwBJPTayarr9RtPod6", + // "destTag":"", + // "tagType":"", + // "tagId":"", + // "chainName":"Omni", + // "numConfirmations":3, + // "withdrawalFee":4.7, + // "nativeScale":4, + // "tips":[] + // }, + // { + // "address":"0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // "destTag":"", + // "tagType":"", + // "tagId":"", + // "chainName":"ERC20", + // "numConfirmations":20, + // "withdrawalFee":1.0, + // "nativeScale":4, + // "tips":[] + // } + // ] + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const addresses = this.safeValue (data, 'address', []); + const numAddresses = addresses.length; + let address = undefined; + if (numAddresses > 1) { + const addressesByChainName = this.indexBy (addresses, 'chainName'); + if (chainName === undefined) { + const chainNames = Object.keys (addressesByChainName); + const chains = chainNames.join (', '); + throw new ArgumentsRequired (this.id + ' fetchDepositAddress returned more than one address, a chainName parameter is required, one of ' + chains); + } + address = this.safeValue (addressesByChainName, chainName, {}); + } else { + // first address + address = this.safeValue (addresses, 0, {}); + } + const result = this.parseDepositAddress (address, currency); + return this.extend (result, { + 'info': response, + }); + } + + async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'txType': 'deposit', + }; + return await this.fetchTransactions (code, since, limit, this.extend (request, params)); + } + + async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'txType': 'withdrawal', + }; + return await this.fetchTransactions (code, since, limit, this.extend (request, params)); + } + + async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'asset': currency['id'], + // 'page': 1, + // 'pageSize': 20, + // 'startTs': this.milliseconds (), + // 'endTs': this.milliseconds (), + // 'txType': undefned, // deposit, withdrawal + }; + let currency = undefined; + if (code !== undefined) { + currency = this.currency (code); + request['asset'] = currency['id']; + } + if (since !== undefined) { + request['startTs'] = since; + } + if (limit !== undefined) { + request['pageSize'] = limit; + } + const response = await this.privateGetWalletTransactions (this.extend (request, params)); + // + // { + // code: 0, + // data: { + // data: [ + // { + // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", + // time: 1591606166000, + // asset: "USDT", + // transactionType: "deposit", + // amount: "25", + // commission: "0", + // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", + // status: "pending", + // numConfirmed: 8, + // numConfirmations: 20, + // destAddress: { address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722" } + // } + // ], + // page: 1, + // pageSize: 20, + // hasNext: false + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const transactions = this.safeValue (data, 'data', []); + return this.parseTransactions (transactions, currency, since, limit); + } + + parseTransactionStatus (status) { + const statuses = { + 'reviewing': 'pending', + 'pending': 'pending', + 'confirmed': 'ok', + 'rejected': 'rejected', + }; + return this.safeString (statuses, status, status); + } + + parseTransaction (transaction, currency = undefined) { + // + // { + // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", + // time: 1591606166000, + // asset: "USDT", + // transactionType: "deposit", + // amount: "25", + // commission: "0", + // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", + // status: "pending", + // numConfirmed: 8, + // numConfirmations: 20, + // destAddress: { + // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // destTag: "..." // for currencies that have it + // } + // } + // + const id = this.safeString (transaction, 'requestId'); + const amount = this.safeNumber (transaction, 'amount'); + const destAddress = this.safeValue (transaction, 'destAddress', {}); + const address = this.safeString (destAddress, 'address'); + const tag = this.safeString (destAddress, 'destTag'); + const txid = this.safeString (transaction, 'networkTransactionId'); + const type = this.safeString (transaction, 'transactionType'); + const timestamp = this.safeInteger (transaction, 'time'); + const currencyId = this.safeString (transaction, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); + const feeCost = this.safeNumber (transaction, 'commission'); + return { + 'info': transaction, + 'id': id, + 'currency': code, + 'amount': amount, + 'address': address, + 'addressTo': address, + 'addressFrom': undefined, + 'tag': tag, + 'tagTo': tag, + 'tagFrom': undefined, + 'status': status, + 'type': type, + 'updated': undefined, + 'txid': txid, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'fee': { + 'currency': code, + 'cost': feeCost, + }, + }; + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let url = ''; + let query = params; + const accountCategory = (api === 'accountCategory'); + if (accountCategory || (api === 'accountGroup')) { + url += this.implodeParams ('/{account-group}', params); + query = this.omit (params, 'account-group'); + } + const request = this.implodeParams (path, query); + url += '/api/pro/' + this.version; + if (accountCategory) { + url += this.implodeParams ('/{account-category}', query); + query = this.omit (query, 'account-category'); + } + url += '/' + request; + query = this.omit (query, this.extractParams (path)); + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const timestamp = this.milliseconds ().toString (); + const payload = timestamp + '+' + request; + const hmac = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); + headers = { + 'x-auth-key': this.apiKey, + 'x-auth-timestamp': timestamp, + 'x-auth-signature': hmac, + }; + if (method === 'GET') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + headers['Content-Type'] = 'application/json'; + body = this.json (query); + } + } + url = this.urls['api'] + url; + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; // fallback to default error handler + } + // + // {'code': 6010, 'message': 'Not enough balance.'} + // {'code': 60060, 'message': 'The order is already filled or canceled.'} + // {"code":2100,"message":"ApiKeyFailure"} + // {"code":300001,"message":"Price is too low from market price.","reason":"INVALID_PRICE","accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda","ac":"CASH","action":"place-order","status":"Err","info":{"symbol":"BTC/USDT"}} + // + const code = this.safeString (response, 'code'); + const message = this.safeString (response, 'message'); + const error = (code !== undefined) && (code !== '0'); + if (error || (message !== undefined)) { + const feedback = this.id + ' ' + body; + this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); + this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); + this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); + throw new ExchangeError (feedback); // unknown message + } + } +}; + +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],6:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -3608,6 +4837,7 @@ const { // eslint-disable-line object-curly-newline const { TRUNCATE, ROUND, DECIMAL_PLACES, NO_PADDING } = functions.precisionConstants const BN = require ('../static_dependencies/BN/bn') +const Precise = require ('./Precise') // ---------------------------------------------------------------------------- @@ -3788,6 +5018,11 @@ module.exports = class Exchange { this.minFundingAddressLength = 1 // used in checkAddress this.substituteCommonCurrencyCodes = true // reserved + this.quoteJsonNumbers = true // treat numbers in json as quoted precise strings + this.number = Number // or String (a pointer to a function) + + // whether fees should be summed by currency code + this.reduceFees = true // do not delete this line, it is needed for users to be able to define their own fetchImplementation this.fetchImplementation = defaultFetch @@ -4083,7 +5318,7 @@ module.exports = class Exchange { parseJson (jsonString) { try { if (this.isJsonEncodedObject (jsonString)) { - return JSON.parse (jsonString) + return JSON.parse (this.onJsonResponse (jsonString)) } } catch (e) { // SyntaxError @@ -4162,7 +5397,11 @@ module.exports = class Exchange { } onRestResponse (statusCode, statusText, url, method, responseHeaders, responseBody, requestHeaders, requestBody) { - return responseBody.trim ().replace (/:(\d{15,}),/g, ':"$1",'); + return responseBody.trim () + } + + onJsonResponse (responseBody) { + return this.quoteJsonNumbers ? responseBody.replace (/":([+.0-9eE-]+),/g, '":"$1",') : responseBody; } setMarkets (markets, currencies = undefined) { @@ -4482,8 +5721,8 @@ module.exports = class Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = parseFloat (bidask[priceKey]) - const amount = parseFloat (bidask[amountKey]) + const price = this.safeNumber (bidask, priceKey) + const amount = this.safeNumber (bidask, amountKey) return [ price, amount ] } @@ -4509,7 +5748,7 @@ module.exports = class Exchange { } } - parseBalance (balance) { + parseBalance (balance, legacy = true) { const codes = Object.keys (this.omit (balance, [ 'info', 'free', 'used', 'total' ])); @@ -4521,20 +5760,34 @@ module.exports = class Exchange { const code = codes[i] if (balance[code].total === undefined) { if (balance[code].free !== undefined && balance[code].used !== undefined) { - balance[code].total = this.sum (balance[code].free, balance[code].used) + if (legacy) { + balance[code].total = this.sum (balance[code].free, balance[code].used) + } else { + balance[code].total = Precise.stringAdd (balance[code].free, balance[code].used) + } } } if (balance[code].free === undefined) { if (balance[code].total !== undefined && balance[code].used !== undefined) { - balance[code].free = this.sum (balance[code].total, -balance[code].used) + if (legacy) { + balance[code].free = this.sum (balance[code].total, -balance[code].used) + } else { + balance[code].free = Precise.stringSub (balance[code].total, balance[code].used) + } } } if (balance[code].used === undefined) { if (balance[code].total !== undefined && balance[code].free !== undefined) { - balance[code].used = this.sum (balance[code].total, -balance[code].free) + if (legacy) { + balance[code].used = this.sum (balance[code].total, -balance[code].free) + } else { + balance[code].used = Precise.stringSub (balance[code].total, balance[code].free) + } } } - + balance[code].free = this.parseNumber (balance[code].free) + balance[code].used = this.parseNumber (balance[code].used) + balance[code].total = this.parseNumber (balance[code].total) balance.free[code] = balance[code].free balance.used[code] = balance[code].used balance.total[code] = balance[code].total @@ -4543,6 +5796,10 @@ module.exports = class Exchange { return balance } + async fetchBalance (params = {}) { + throw new NotSupported (this.id + ' fetchBalance not supported yet') + } + async fetchPartialBalance (part, params = {}) { const balance = await this.fetchBalance (params) return balance[part] @@ -4652,11 +5909,27 @@ module.exports = class Exchange { return indexed ? indexBy (result, key) : result } + parseTickers (tickers, symbols = undefined) { + const result = []; + for (let i = 0; i < tickers.length; i++) { + result.push (this.parseTicker (tickers[i])); + } + return this.filterByArray (result, 'symbol', symbols); + } + + parseDepositAddresses (addresses, codes = undefined) { + let result = []; + for (let i = 0; i < addresses.length; i++) { + const address = this.parseDepositAddress (addresses[i]); + result.push (address); + } + if (codes) { + result = this.filterByArray (result, 'currency', codes); + } + return this.indexBy (result, 'currency'); + } + parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (trades)) { - // throw new ExchangeError (this.id + ' parseTrades expected an array in the trades argument, but got ' + typeof trades); - // } let result = Object.values (trades || []).map ((trade) => this.extend (this.parseTrade (trade, market), params)) result = sortBy (result, 'timestamp') const symbol = (market !== undefined) ? market['symbol'] : undefined @@ -4665,10 +5938,6 @@ module.exports = class Exchange { } parseTransactions (transactions, currency = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (transactions)) { - // throw new ExchangeError (this.id + ' parseTransactions expected an array in the transactions argument, but got ' + typeof transactions); - // } let result = Object.values (transactions || []).map ((transaction) => this.extend (this.parseTransaction (transaction, currency), params)) result = this.sortBy (result, 'timestamp'); const code = (currency !== undefined) ? currency['code'] : undefined; @@ -4676,6 +5945,14 @@ module.exports = class Exchange { return this.filterByCurrencySinceLimit (result, code, since, limit, tail); } + parseTransfers (transfers, currency = undefined, since = undefined, limit = undefined, params = {}) { + let result = Object.values (transfers || []).map ((transfer) => this.extend (this.parseTransfer (transfer, currency), params)) + result = this.sortBy (result, 'timestamp'); + const code = (currency !== undefined) ? currency['code'] : undefined; + const tail = since === undefined; + return this.filterByCurrencySinceLimit (result, code, since, limit, tail); + } + parseLedger (data, currency = undefined, since = undefined, limit = undefined, params = {}) { let result = []; const array = Object.values (data || []); @@ -4820,19 +6097,19 @@ module.exports = class Exchange { return this.createOrder (symbol, ...args) } - createLimitOrder (symbol, side, amount, price = undefined, params = {}) { + createLimitOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'limit', side, amount, price, params) } - createMarketOrder (symbol, side, amount, price = undefined, params = {}) { + createMarketOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'market', side, amount, price, params) } - createLimitBuyOrder (symbol, amount, price = undefined, params = {}) { + createLimitBuyOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'buy', amount, price, params) } - createLimitSellOrder (symbol, amount, price = undefined, params = {}) { + createLimitSellOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'sell', amount, price, params) } @@ -4865,15 +6142,43 @@ module.exports = class Exchange { } calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol] - const rate = market[takerOrMaker] - const cost = parseFloat (this.costToPrecision (symbol, amount * price)) + const market = this.markets[symbol]; + const feeSide = this.safeString (market, 'feeSide', 'quote'); + let key = 'quote'; + let cost = undefined; + if (feeSide === 'quote') { + // the fee is always in quote currency + cost = amount * price; + } else if (feeSide === 'base') { + // the fee is always in base currency + cost = amount; + } else if (feeSide === 'get') { + // the fee is always in the currency you get + cost = amount; + if (side === 'sell') { + cost *= price; + } else { + key = 'base'; + } + } else if (feeSide === 'give') { + // the fee is always in the currency you give + cost = amount; + if (side === 'buy') { + cost *= price; + } else { + key = 'base'; + } + } + const rate = market[takerOrMaker]; + if (cost !== undefined) { + cost *= rate; + } return { 'type': takerOrMaker, - 'currency': market['quote'], + 'currency': market[key], 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, rate * cost)), - } + 'cost': cost, + }; } checkRequiredDependencies () { @@ -4957,6 +6262,25 @@ module.exports = class Exchange { return new BN (a).pow (new BN (b)) } + reduceFeesByCurrency (fees) { + const reduced = {}; + for (let i = 0; i < fees.length; i++) { + const fee = fees[i]; + const feeCurrencyCode = this.safeValue (fee, 'currency'); + if (feeCurrencyCode !== undefined) { + if (feeCurrencyCode in reduced) { + reduced[feeCurrencyCode]['cost'] = this.sum (reduced[feeCurrencyCode]['cost'], fee['cost']); + } else { + reduced[feeCurrencyCode] = { + 'cost': fee['cost'], + 'currency': feeCurrencyCode, + }; + } + } + } + return Object.values (reduced); + } + safeOrder (order) { // Cost // Remaining @@ -4965,70 +6289,295 @@ module.exports = class Exchange { // Amount // Filled // - // First we try to calculate filled from the trades - const parseFilled = order['filled'] === undefined; - const parseCost = order['cost'] === undefined; - if (parseFilled) { - order['filled'] = 0 - } - if (parseCost) { - order['cost'] = 0 - } - if (parseFilled || parseCost) { - if (Array.isArray (order['trades'])) { - for (let i = 0; i < order['trades'].length; i++) { - const trade = order['trades'][i] - if (parseFilled) { - order['filled'] = this.sum (order['filled'], trade['amount']) + // first we try to calculate the order fields from the trades + let amount = this.safeValue (order, 'amount'); + let remaining = this.safeValue (order, 'remaining'); + let filled = this.safeValue (order, 'filled'); + let cost = this.safeValue (order, 'cost'); + let average = this.safeValue (order, 'average'); + let price = this.safeValue (order, 'price'); + let lastTradeTimeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); + const parseFilled = (filled === undefined); + const parseCost = (cost === undefined); + const parseLastTradeTimeTimestamp = (lastTradeTimeTimestamp === undefined); + const parseFee = this.safeValue (order, 'fee') === undefined; + const parseFees = this.safeValue (order, 'fees') === undefined; + const shouldParseFees = parseFee || parseFees; + const fees = shouldParseFees ? [] : undefined; + if (parseFilled || parseCost || shouldParseFees) { + const trades = this.safeValue (order, 'trades'); + if (trades !== undefined) { + if (parseFilled) { + filled = 0; + } + if (parseCost) { + cost = 0; + } + for (let i = 0; i < trades.length; i++) { + const trade = trades[i]; + const tradeAmount = this.safeValue (trade, 'amount'); + if (parseFilled && (tradeAmount !== undefined)) { + filled = this.sum (filled, tradeAmount); } - if (parseCost) { - order['cost'] = this.sum (order['cost'], trade['cost']) + const tradeCost = this.safeValue (trade, 'cost'); + if (parseCost && (tradeCost !== undefined)) { + cost = this.sum (cost, tradeCost); + } + const tradeTimestamp = this.safeValue (trade, 'timestamp'); + if (parseLastTradeTimeTimestamp && (tradeTimestamp !== undefined)) { + if (lastTradeTimeTimestamp === undefined) { + lastTradeTimeTimestamp = tradeTimestamp; + } else { + lastTradeTimeTimestamp = Math.max (lastTradeTimeTimestamp, tradeTimestamp); + } + } + if (shouldParseFees) { + const tradeFees = this.safeValue (trade, 'fees'); + if (tradeFees !== undefined) { + for (let j = 0; j < tradeFees.length; j++) { + const tradeFee = tradeFees[j]; + fees.push (this.extend ({}, tradeFee)); + } + } else { + const tradeFee = this.safeValue (trade, 'fee'); + if (tradeFee !== undefined) { + fees.push (this.extend ({}, tradeFee)); + } + } } } } } - // We ensure amount = filled + remaining - if (order['amount'] === undefined) { - if (order['filled'] !== undefined && order['remaining'] !== undefined) { - order['amount'] = this.sum (order['filled'], order['remaining']) + if (shouldParseFees) { + const reducedFees = this.reduceFees ? this.reduceFeesByCurrency (fees) : fees; + const reducedLength = reducedFees.length; + if (!parseFee && (reducedLength === 0)) { + reducedFees.push (order['fee']); + } + if (parseFees) { + order['fees'] = reducedFees; + } + if (parseFee && (reducedLength === 1)) { + order['fee'] = reducedFees[0]; } } - if (order['filled'] === undefined) { - if (order['amount'] !== undefined && order['remaining'] !== undefined) { - order['filled'] = Math.max (this.sum (order['amount'], -order['remaining']), 0) + if (amount === undefined) { + // ensure amount = filled + remaining + if (filled !== undefined && remaining !== undefined) { + amount = this.sum (filled, remaining); + } else if (this.safeString (order, 'status') === 'closed') { + amount = filled; } } - if (order['remaining'] === undefined) { - if (order['amount'] !== undefined && order['filled'] !== undefined) { - order['remaining'] = Math.max (this.sum (order['amount'], -order['filled']), 0) + if (filled === undefined) { + if (amount !== undefined && remaining !== undefined) { + filled = Math.max (this.sum (amount, -remaining), 0); } } - // We ensure that the average field is calculated correctly - if (order['average'] === undefined) { - if (order['filled'] !== undefined && order['cost'] !== undefined && order['cost'] > 0) { - order['average'] = order['filled'] / order['cost'] + if (remaining === undefined) { + if (amount !== undefined && filled !== undefined) { + remaining = Math.max (this.sum (amount, -filled), 0); } } - // We also ensure the cost field is calculated correctly - const costPriceExists = (order['average'] !== undefined) || (order['price'] !== undefined) - if ((order['filled'] !== undefined) && costPriceExists) { - let costPrice = undefined; - if (order['average'] === undefined) { - costPrice = order['price'] - } else { - costPrice = order['average'] + // ensure that the average field is calculated correctly + if (average === undefined) { + if ((filled !== undefined) && (cost !== undefined) && (cost > 0)) { + average = cost / filled; } - order['cost'] = costPrice * order['filled'] } - // We add support for market orders - if (order['price'] === undefined && order['type'] === 'market') { - order['price'] = order['average'] + // also ensure the cost field is calculated correctly + const costPriceExists = (average !== undefined) || (price !== undefined); + if (parseCost && (filled !== undefined) && costPriceExists) { + cost = (average === undefined) ? (price * filled) : (average * filled); } - return order + // support for market orders + const orderType = this.safeValue (order, 'type'); + const emptyPrice = (price === undefined) || (price === 0.0); + if (emptyPrice && (orderType === 'market')) { + price = average; + } + return this.extend (order, { + 'lastTradeTimestamp': lastTradeTimeTimestamp, + 'price': price, + 'amount': amount, + 'cost': cost, + 'average': average, + 'filled': filled, + 'remaining': remaining, + }); + } + + parseNumber (value, d = undefined) { + if (value === undefined) { + return d + } else { + try { + return this.number (value) + } catch (e) { + return d + } + } + } + + safeNumber (object, key, d = undefined) { + const value = this.safeString (object, key) + return this.parseNumber (value, d) + } + + safeNumber2 (object, key1, key2, d = undefined) { + const value = this.safeString2 (object, key1, key2) + return this.parseNumber (value, d) } } -},{"../static_dependencies/BN/bn":126,"./errors":8,"./functions":9}],7:[function(require,module,exports){ +},{"../static_dependencies/BN/bn":123,"./Precise":7,"./errors":9,"./functions":10}],7:[function(require,module,exports){ +'use strict' + +const BN = require ('../static_dependencies/BN/bn') + +class Precise { + constructor (number, decimals = 0) { + const isBN = number instanceof BN + const isString = typeof number === 'string' + if (!(isBN || isString)) { + throw new Error ('Precise initiated with something other than a string or BN') + } + if (isBN) { + this.integer = number + this.decimals = decimals + } else { + if (decimals) { + throw new Error ('Cannot set decimals when initializing with a string') + } + let modifier = 0 + number = number.toLowerCase () + if (number.indexOf ('e') > -1) { + [ number, modifier ] = number.split ('e') + modifier = parseInt (modifier) + } + const decimalIndex = number.indexOf ('.') + this.decimals = (decimalIndex > -1) ? number.length - decimalIndex - 1 : 0 + const integerString = number.replace ('.', '') + this.integer = new BN (integerString) + this.decimals = this.decimals - modifier + } + this.base = 10 + this.reduce () + } + + mul (other) { + // other must be another instance of Precise + const integerResult = this.integer.mul (other.integer) + return new Precise (integerResult, this.decimals + other.decimals) + } + + div (other, precision = 18) { + const distance = precision - this.decimals + other.decimals + let numerator + if (distance === 0) { + numerator = this.integer + } else if (distance < 0) { + const exponent = new BN (this.base).pow (new BN (-distance)) + numerator = this.integer.div (exponent) + } else { + const exponent = new BN (this.base).pow (new BN (distance)) + numerator = this.integer.mul (exponent) + } + const result = numerator.div (other.integer) + return new Precise (result, precision) + } + + add (other) { + if (this.decimals === other.decimals) { + const integerResult = this.integer.add (other.integer) + return new Precise (integerResult, this.decimals) + } else { + const [ smaller, bigger ] = + (this.decimals > other.decimals) ? [ other, this ] : [ this, other ] + const exponent = new BN (bigger.decimals - smaller.decimals) + const normalised = smaller.integer.mul (new BN (this.base).pow (exponent)) + const result = normalised.add (bigger.integer) + return new Precise (result, bigger.decimals) + } + } + + sub (other) { + const negative = new Precise (other.integer.neg (), other.decimals) + return this.add (negative) + } + + reduce () { + const zero = new BN (0) + if (this.integer.eq (zero)) { + this.decimals = 0 + return this + } + const base = new BN (this.base) + let divmod = this.integer.divmod (base) + while (divmod.mod.eq (zero)) { + this.integer = divmod.div + this.decimals-- + divmod = this.integer.divmod (base) + } + return this + } + + toString () { + const sign = this.integer.negative ? '-' : '' + const integerArray = Array.from (this.integer.abs ().toString (this.base).padStart (this.decimals, '0')) + const index = integerArray.length - this.decimals + let item + if (index === 0) { + // if we are adding to the front + item = '0.' + } else if (this.decimals < 0) { + item = '0'.repeat (-this.decimals) + } else if (this.decimals === 0) { + item = '' + } else { + item = '.' + } + integerArray.splice (index, 0, item) + return sign + integerArray.join ('') + } + + static stringMul (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).mul (new Precise (string2)).toString () + } + + static stringDiv (string1, string2, precision = 18) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).div (new Precise (string2), precision).toString () + } + + static stringAdd (string1, string2) { + if ((string1 === undefined) && (string2 === undefined)) { + return undefined + } + if (string1 === undefined) { + return string2 + } else if (string2 === undefined) { + return string1 + } + return (new Precise (string1)).add (new Precise (string2)).toString () + } + + static stringSub (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).sub (new Precise (string2)).toString () + } +} + +module.exports = Precise; + +},{"../static_dependencies/BN/bn":123}],8:[function(require,module,exports){ 'use strict'; const errorHierarchy = { @@ -5074,7 +6623,7 @@ const errorHierarchy = { module.exports = errorHierarchy; -},{}],8:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ 'use strict'; const errorHierarchy = require ('./errorHierarchy.js') @@ -5131,7 +6680,7 @@ module.exports = subclass ( errorHierarchy ) -},{"./errorHierarchy.js":7}],9:[function(require,module,exports){ +},{"./errorHierarchy.js":8}],10:[function(require,module,exports){ 'use strict'; /* ------------------------------------------------------------------------ */ @@ -5161,7 +6710,7 @@ module.exports = unCamelCasePropertyNames (Object.assign ({} /* ------------------------------------------------------------------------ */ -},{"./functions/crypto":10,"./functions/encode":11,"./functions/generic":12,"./functions/misc":13,"./functions/number":14,"./functions/platform":15,"./functions/string":16,"./functions/throttle":17,"./functions/time":18,"./functions/type":19}],10:[function(require,module,exports){ +},{"./functions/crypto":11,"./functions/encode":12,"./functions/generic":13,"./functions/misc":14,"./functions/number":15,"./functions/platform":16,"./functions/string":17,"./functions/throttle":18,"./functions/time":19,"./functions/type":20}],11:[function(require,module,exports){ 'use strict' /* ------------------------------------------------------------------------ */ @@ -5321,7 +6870,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"../../static_dependencies/BN/bn.js":126,"../../static_dependencies/crypto-js/crypto-js":127,"./../../static_dependencies/elliptic/lib/elliptic":128,"./../../static_dependencies/node-rsa/NodeRSA":146,"./../errors":8,"./encode":11,"./string":16}],11:[function(require,module,exports){ +},{"../../static_dependencies/BN/bn.js":123,"../../static_dependencies/crypto-js/crypto-js":124,"./../../static_dependencies/elliptic/lib/elliptic":125,"./../../static_dependencies/node-rsa/NodeRSA":143,"./../errors":9,"./encode":12,"./string":17}],12:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -5343,7 +6892,6 @@ let base58Encoder = null module.exports = { json: (data, params = undefined) => JSON.stringify (data) - , unjson: JSON.parse , isJsonEncodedObject: object => ( (typeof object === 'string') && @@ -5441,7 +6989,7 @@ module.exports['byteArrayToWordArray'] = byteArrayToWordArray /* ------------------------------------------------------------------------ */ -},{"../../static_dependencies/BN/bn":126,"../../static_dependencies/crypto-js/crypto-js":127,"../../static_dependencies/qs/index":162}],12:[function(require,module,exports){ +},{"../../static_dependencies/BN/bn":123,"../../static_dependencies/crypto-js/crypto-js":124,"../../static_dependencies/qs/index":159}],13:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -5679,7 +7227,7 @@ module.exports = { } -},{"./type":19}],13:[function(require,module,exports){ +},{"./type":20}],14:[function(require,module,exports){ 'use strict'; const { ROUND_UP, ROUND_DOWN } = require ('./number') @@ -5819,7 +7367,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"../errors":8,"./number":14}],14:[function(require,module,exports){ +},{"../errors":9,"./number":15}],15:[function(require,module,exports){ 'use strict' /* ------------------------------------------------------------------------ @@ -6160,7 +7708,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{}],15:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ (function (process){ "use strict"; @@ -6201,7 +7749,7 @@ module.exports = { defaultFetch, } }).call(this,require('_process')) -},{"../../static_dependencies/fetch-ponyfill/fetch-node":144,"_process":210}],16:[function(require,module,exports){ +},{"../../static_dependencies/fetch-ponyfill/fetch-node":141,"_process":206}],17:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -6221,7 +7769,7 @@ module.exports = { , strip: s => s.replace(/^\s+|\s+$/g, '') } -},{}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -6287,7 +7835,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"./time":18}],18:[function(require,module,exports){ +},{"./time":19}],19:[function(require,module,exports){ 'use strict'; /* ------------------------------------------------------------------------ */ @@ -6491,7 +8039,7 @@ module.exports = /* ------------------------------------------------------------------------ */ -},{}],19:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -6559,7 +8107,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{}],20:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -6593,13 +8141,14 @@ module.exports = class bequant extends hitbtc { } }; -},{"./hitbtc":93}],21:[function(require,module,exports){ +},{"./hitbtc":91}],22:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AccountSuspended, ArgumentsRequired, AuthenticationError, DDoSProtection, ExchangeNotAvailable, InvalidOrder, OrderNotFound, PermissionDenied, InsufficientFunds, BadSymbol, RateLimitExceeded, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -6825,9 +8374,9 @@ module.exports = class bibox extends Exchange { const quote = this.safeCurrencyCode (quoteId); symbol = base + '/' + quote; } - const last = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); - const baseVolume = this.safeFloat2 (ticker, 'vol', 'vol24H'); + const last = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); + const baseVolume = this.safeNumber2 (ticker, 'vol', 'vol24H'); let open = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; @@ -6841,11 +8390,11 @@ module.exports = class bibox extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -6856,7 +8405,7 @@ module.exports = class bibox extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': baseVolume, - 'quoteVolume': this.safeFloat (ticker, 'amount'), + 'quoteVolume': this.safeNumber (ticker, 'amount'), 'info': ticker, }; } @@ -6872,17 +8421,6 @@ module.exports = class bibox extends Exchange { return this.parseTicker (response['result'], market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - const ticker = this.parseTicker (rawTickers[i]); - if ((symbols === undefined) || (this.inArray (ticker['symbol'], symbols))) { - tickers.push (ticker); - } - } - return tickers; - } - async fetchTickers (symbols = undefined, params = {}) { const request = { 'cmd': 'marketAll', @@ -6915,7 +8453,7 @@ module.exports = class bibox extends Exchange { symbol = market['symbol']; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = this.safeString (trade, 'fee_symbol'); if (feeCurrency !== undefined) { if (feeCurrency in this.currencies_by_id) { @@ -6925,12 +8463,11 @@ module.exports = class bibox extends Exchange { } } const feeRate = undefined; // todo: deduce from market if market is defined - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if (feeCost !== undefined) { fee = { 'cost': -feeCost, @@ -6981,7 +8518,7 @@ module.exports = class bibox extends Exchange { request['size'] = limit; // default = 200 } const response = await this.publicGetMdata (this.extend (request, params)); - return this.parseOrderBook (response['result'], this.safeFloat (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); + return this.parseOrderBook (response['result'], this.safeNumber (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); } parseOHLCV (ohlcv, market = undefined) { @@ -6997,11 +8534,11 @@ module.exports = class bibox extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -7093,7 +8630,7 @@ module.exports = class bibox extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw_min'), + 'min': this.safeNumber (currency, 'withdraw_min'), 'max': undefined, }, }, @@ -7225,19 +8762,17 @@ module.exports = class bibox extends Exchange { code = this.currencies_by_id[code]['code']; } const account = this.account (); - let balance = indexed[id]; + const balance = indexed[id]; if (typeof balance === 'string') { - balance = parseFloat (balance); account['free'] = balance; - account['used'] = 0.0; account['total'] = balance; } else { - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -7328,8 +8863,8 @@ module.exports = class bibox extends Exchange { let tag = this.safeString (transaction, 'addr_remark'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'fee'); if (type === 'deposit') { feeCost = 0; tag = undefined; @@ -7437,26 +8972,19 @@ module.exports = class bibox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const type = (order['order_type'] === 1) ? 'market' : 'limit'; - const timestamp = order['createdAt']; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'deal_price'); - const filled = this.safeFloat (order, 'deal_amount'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat2 (order, 'deal_money', 'money'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - cost = price * filled; - } - } - const side = (order['order_side'] === 1) ? 'buy' : 'sell'; + const rawType = this.safeString (order, 'order_type'); + const type = (rawType === '1') ? 'market' : 'limit'; + const timestamp = this.safeInteger (order, 'createdAt'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'deal_price'); + const filled = this.safeNumber (order, 'deal_amount'); + const amount = this.safeNumber (order, 'amount'); + const cost = this.safeNumber2 (order, 'deal_money', 'money'); + const rawSide = this.safeString (order, 'order_side'); + const side = (rawSide === '1') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -7464,8 +8992,7 @@ module.exports = class bibox extends Exchange { 'currency': undefined, }; } - cost = cost ? cost : (parseFloat (price) * filled); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -7483,11 +9010,11 @@ module.exports = class bibox extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -7655,7 +9182,7 @@ module.exports = class bibox extends Exchange { }; const response = await this.privatePostTransfer (request); info[code] = response; - withdrawFees[code] = this.safeFloat (response['result'], 'withdraw_fee'); + withdrawFees[code] = this.safeNumber (response['result'], 'withdraw_fee'); } return { 'info': info, @@ -7725,13 +9252,14 @@ module.exports = class bibox extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],22:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],23:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, OrderNotFound, InsufficientFunds, PermissionDenied, BadRequest, RateLimitExceeded, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -7988,28 +9516,28 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (ticker, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = undefined; - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', {}); const ask = this.safeValue (ticker, 'ask', {}); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 'price'), - 'bidVolume': this.safeFloat (bid, 'quantity'), - 'ask': this.safeFloat (ask, 'price'), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 'price'), + 'bidVolume': this.safeNumber (bid, 'quantity'), + 'ask': this.safeNumber (ask, 'price'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'daily_change'), + 'change': this.safeNumber (ticker, 'daily_change'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -8174,16 +9702,13 @@ module.exports = class bigone extends Exchange { // } // const timestamp = this.parse8601 (this.safeString2 (trade, 'created_at', 'inserted_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } let side = this.safeString (trade, 'side'); const takerSide = this.safeString (trade, 'taker_side'); let takerOrMaker = undefined; @@ -8257,8 +9782,8 @@ module.exports = class bigone extends Exchange { takerCurrencyCode = market['quote']; } } - const makerFeeCost = this.safeFloat (trade, 'maker_fee'); - const takerFeeCost = this.safeFloat (trade, 'taker_fee'); + const makerFeeCost = this.safeNumber (trade, 'maker_fee'); + const takerFeeCost = this.safeNumber (trade, 'taker_fee'); if (makerFeeCost !== undefined) { if (takerFeeCost !== undefined) { result['fees'] = [ @@ -8321,11 +9846,11 @@ module.exports = class bigone extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -8396,11 +9921,11 @@ module.exports = class bigone extends Exchange { const symbol = this.safeString (balance, 'asset_symbol'); const code = this.safeCurrencyCode (symbol); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -8422,13 +9947,9 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (order, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (amount !== undefined && filled !== undefined) { - remaining = Math.max (0, amount - filled); - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); const status = this.parseOrderStatus (this.safeString (order, 'state')); let side = this.safeString (order, 'side'); if (side === 'BID') { @@ -8436,15 +9957,9 @@ module.exports = class bigone extends Exchange { } else { side = 'sell'; } - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'updated_at')); - const average = this.safeFloat (order, 'avg_deal_price'); - return { + const average = this.safeNumber (order, 'avg_deal_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -8459,14 +9974,14 @@ module.exports = class bigone extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -8490,7 +10005,7 @@ module.exports = class bigone extends Exchange { const isStopLimit = (uppercaseType === 'STOP_LIMIT'); const isStopMarket = (uppercaseType === 'STOP_MARKET'); if (isStopLimit || isStopMarket) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price parameter'); } @@ -8829,7 +10344,7 @@ module.exports = class bigone extends Exchange { const currencyId = this.safeString (transaction, 'asset_symbol'); const code = this.safeCurrencyCode (currencyId); const id = this.safeInteger (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const timestamp = this.parse8601 (this.safeString (transaction, 'inserted_at')); const updated = this.parse8601 (this.safeString2 (transaction, 'updated_at', 'completed_at')); @@ -9000,14 +10515,15 @@ module.exports = class bigone extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],23:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],24:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, NotSupported, BadRequest, BadSymbol, AccountSuspended, OrderImmediatelyFillable } = require ('./base/errors'); -const { ROUND, TRUNCATE } = require ('./base/functions/number'); +const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -9050,6 +10566,8 @@ module.exports = class binance extends Exchange { 'fetchTransactions': false, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, + 'fetchTransfers': true, }, 'timeframes': { '1m': '1m', @@ -9198,6 +10716,26 @@ module.exports = class binance extends Exchange { 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/recentRecord', 'apiReferral/kickback/historicalRecord', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccount', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/info', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/recentRecord', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/status', + 'broker/subAccount/depositHist', + 'broker/subAccount/spotSummary', + 'broker/subAccount/marginSummary', + 'broker/subAccount/futuresSummary', + 'broker/rebate/futures/recentRecord', + 'broker/subAccountApi/ipRestriction', + 'broker/universalTransfer', + // v2 not supported yet + // GET /sapi/v2/broker/subAccount/futuresSummary ], 'post': [ 'asset/dust', @@ -9237,11 +10775,30 @@ module.exports = class binance extends Exchange { // leveraged token endpoints 'blvt/subscribe', 'blvt/redeem', - // broker api + // brokerage API 'apiReferral/customization', 'apiReferral/userCustomization', 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/historicalRecord', + 'broker/subAccount', + 'broker/subAccount/margin', + 'broker/subAccount/futures', + 'broker/subAccountApi', + 'broker/subAccountApi/permission', + 'broker/subAccountApi/commission', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/spot', + 'broker/subAccount/bnbBurn/marginInterest', + 'broker/subAccount/blvt', + 'broker/subAccountApi/ipRestriction', + 'broker/subAccountApi/ipRestriction/ipList', + 'broker/universalTransfer', + 'broker/subAccountApi/permission/universalTransfer', + 'broker/subAccountApi/permission/vanillaOptions', ], 'put': [ 'userDataStream', @@ -9252,6 +10809,9 @@ module.exports = class binance extends Exchange { 'margin/order', 'userDataStream', 'userDataStream/isolated', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccountApi/ipRestriction/ipList', ], }, 'wapi': { @@ -9388,6 +10948,8 @@ module.exports = class binance extends Exchange { 'positionSide/dual', 'userTrades', 'income', + 'commissionRate', + 'apiTradingStatus', // broker endpoints 'apiReferral/ifNewUser', 'apiReferral/customization', @@ -9477,6 +11039,7 @@ module.exports = class binance extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.001, @@ -9501,7 +11064,7 @@ module.exports = class binance extends Exchange { 'parseOrderToPrecision': false, // force amounts and costs in parseOrder to precision 'newOrderRespType': { 'market': 'FULL', // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills - 'limit': 'RESULT', // we change it from 'ACK' by default to 'RESULT' + 'limit': 'FULL', // we change it from 'ACK' by default to 'FULL' (returns immediately if limit is not hit) }, 'quoteOrderQty': true, // whether market orders support amounts in quote currency 'broker': { @@ -9510,6 +11073,25 @@ module.exports = class binance extends Exchange { 'future': 'x-xcKtGhcu', 'delivery': 'x-xcKtGhcu', }, + 'fetchPositions': { + 'future': 'fapiPrivateV2GetAccount', // 'fapiPrivateGetPositionRisk' + 'delivery': 'dapiPrivateGetAccount', // 'dapiPrivateGetPositionRisk' + }, + 'accountsByType': { + 'main': 'MAIN', + 'spot': 'MAIN', + 'margin': 'MARGIN', + 'future': 'UMFUTURE', + 'delivery': 'CMFUTURE', + 'mining': 'MINING', + }, + 'typesByAccount': { + 'MAIN': 'spot', + 'MARGIN': 'margin', + 'UMFUTURE': 'future', + 'CMFUTURE': 'delivery', + 'MINING': 'mining', + }, }, // https://binance-docs.github.io/apidocs/spot/en/#error-codes-2 'exceptions': { @@ -9567,6 +11149,8 @@ module.exports = class binance extends Exchange { '-3010': ExchangeError, // {"code":-3010,"msg":"Repay not allowed. Repay amount exceeds borrow amount."} '-3022': AccountSuspended, // You account's trading is banned. '-4028': BadRequest, // {"code":-4028,"msg":"Leverage 100 is not valid"} + '-3020': InsufficientFunds, // {"code":-3020,"msg":"Transfer out amount exceeds max amount."} + '-3041': InsufficientFunds, // {"code":-3041,"msg":"Balance is not enough"} '-5013': InsufficientFunds, // Asset transfer failed: insufficient balance" }, }); @@ -9709,13 +11293,14 @@ module.exports = class binance extends Exchange { let fee = undefined; for (let j = 0; j < networkList.length; j++) { const networkItem = networkList[j]; - const name = this.safeString (networkItem, 'name'); - const withdrawFee = this.safeFloat (networkItem, 'withdrawFee'); + const network = this.safeString (networkItem, 'network'); + // const name = this.safeString (networkItem, 'name'); + const withdrawFee = this.safeNumber (networkItem, 'withdrawFee'); const depositEnable = this.safeValue (networkItem, 'depositEnable'); const withdrawEnable = this.safeValue (networkItem, 'withdrawEnable'); isDepositEnabled = isDepositEnabled || depositEnable; isWithdrawEnabled = isWithdrawEnabled || withdrawEnable; - fees[name] = withdrawFee; + fees[network] = withdrawFee; const isDefault = this.safeValue (networkItem, 'isDefault'); if (isDefault || fee === undefined) { fee = withdrawFee; @@ -9901,7 +11486,7 @@ module.exports = class binance extends Exchange { if (this.options['adjustForTimeDifference']) { await this.loadTimeDifference (); } - const markets = this.safeValue (response, 'symbols'); + const markets = this.safeValue (response, 'symbols', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -9966,10 +11551,10 @@ module.exports = class binance extends Exchange { // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } @@ -9980,47 +11565,26 @@ module.exports = class binance extends Exchange { const stepSize = this.safeString (filter, 'stepSize'); entry['precision']['amount'] = this.precisionFromString (stepSize); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat2 (filter, 'minNotional', 'notional'); + entry['limits']['cost']['min'] = this.safeNumber2 (filter, 'minNotional', 'notional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'spot'); @@ -10191,8 +11755,8 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -10205,13 +11769,13 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['used'] = this.safeFloat (balance, 'initialMargin'); - account['total'] = this.safeFloat2 (balance, 'marginBalance', 'balance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['used'] = this.safeString (balance, 'initialMargin'); + account['total'] = this.safeString2 (balance, 'marginBalance', 'balance'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -10264,36 +11828,36 @@ module.exports = class binance extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'openPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'openPrice'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } async fetchStatus (params = {}) { const response = await this.wapiGetSystemStatus (params); - let status = this.safeValue (response, 'status'); + let status = this.safeString (response, 'status'); if (status !== undefined) { - status = (status === 0) ? 'ok' : 'maintenance'; + status = (status === '0') ? 'ok' : 'maintenance'; this.status = this.extend (this.status, { 'status': status, 'updated': this.milliseconds (), @@ -10322,14 +11886,6 @@ module.exports = class binance extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBidsAsks', 'defaultType', 'spot'); @@ -10384,11 +11940,11 @@ module.exports = class binance extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -10519,8 +12075,11 @@ module.exports = class binance extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -10538,7 +12097,7 @@ module.exports = class binance extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -10551,10 +12110,6 @@ module.exports = class binance extends Exchange { } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } return { 'info': trade, 'timestamp': timestamp, @@ -10673,7 +12228,7 @@ module.exports = class binance extends Exchange { parseOrder (order, market = undefined) { // - // spot + // spot // // { // "symbol": "LTCBTC", @@ -10694,7 +12249,7 @@ module.exports = class binance extends Exchange { // "isWorking": true // } // - // futures + // futures // // { // "symbol": "BTCUSDT", @@ -10712,6 +12267,33 @@ module.exports = class binance extends Exchange { // "updateTime": 1499827319559 // } // + // createOrder with { "newOrderRespType": "FULL" } + // + // { + // "symbol": "BTCUSDT", + // "orderId": 5403233939, + // "orderListId": -1, + // "clientOrderId": "x-R4BD3S825e669e75b6c14f69a2c43e", + // "transactTime": 1617151923742, + // "price": "0.00000000", + // "origQty": "0.00050000", + // "executedQty": "0.00050000", + // "cummulativeQuoteQty": "29.47081500", + // "status": "FILLED", + // "timeInForce": "GTC", + // "type": "MARKET", + // "side": "BUY", + // "fills": [ + // { + // "price": "58941.63000000", + // "qty": "0.00050000", + // "commission": "0.00007050", + // "commissionAsset": "BNB", + // "tradeId": 737466631 + // } + // ] + // } + // const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -10721,80 +12303,26 @@ module.exports = class binance extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); // - Spot/Margin market: cummulativeQuoteQty // - Futures market: cumQuote. // Note this is not the actual cost, since Binance futures uses leverage to calculate margins. - let cost = this.safeFloat2 (order, 'cummulativeQuoteQty', 'cumQuote'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const cost = this.safeNumber2 (order, 'cummulativeQuoteQty', 'cumQuote'); const id = this.safeString (order, 'orderId'); let type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - if (this.options['parseOrderToPrecision']) { - price = parseFloat (this.priceToPrecision (symbol, price)); - } - } - } - } - } else if (type === 'limit_maker') { + if (type === 'limit_maker') { type = 'limit'; } const side = this.safeStringLower (order, 'side'); - let fee = undefined; - let trades = undefined; - const fills = this.safeValue (order, 'fills'); - if (fills !== undefined) { - trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - if (this.options['parseOrderToPrecision']) { - average = parseFloat (this.priceToPrecision (symbol, average)); - } - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const fills = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (fills, market); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -10810,13 +12338,13 @@ module.exports = class binance extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -10863,8 +12391,11 @@ module.exports = class binance extends Exchange { } else { request['newClientOrderId'] = clientOrderId; } - if (market['spot']) { + if ((orderType === 'spot') || (orderType === 'margin')) { request['newOrderRespType'] = this.safeValue (this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills + } else { + // delivery and future + request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK" } // additional required fields depending on the order type let timeInForceIsRequired = false; @@ -10894,7 +12425,7 @@ module.exports = class binance extends Exchange { if (uppercaseType === 'MARKET') { const quoteOrderQty = this.safeValue (this.options, 'quoteOrderQty', false); if (quoteOrderQty) { - const quoteOrderQty = this.safeFloat (params, 'quoteOrderQty'); + const quoteOrderQty = this.safeNumber (params, 'quoteOrderQty'); const precision = market['precision']['price']; if (quoteOrderQty !== undefined) { request['quoteOrderQty'] = this.decimalToPrecision (quoteOrderQty, TRUNCATE, precision, this.precisionMode); @@ -10914,7 +12445,7 @@ module.exports = class binance extends Exchange { } else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) { stopPriceIsRequired = true; quantityIsRequired = true; - if (market['future']) { + if (market['future'] || market['delivery']) { priceIsRequired = true; } } else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) { @@ -10937,7 +12468,7 @@ module.exports = class binance extends Exchange { stopPriceIsRequired = true; } else if (uppercaseType === 'TRAILING_STOP_MARKET') { quantityIsRequired = true; - const callbackRate = this.safeFloat (params, 'callbackRate'); + const callbackRate = this.safeNumber (params, 'callbackRate'); if (callbackRate === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a callbackRate extra param for a ' + type + ' order'); } @@ -10955,7 +12486,7 @@ module.exports = class binance extends Exchange { request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -11171,10 +12702,15 @@ module.exports = class binance extends Exchange { } } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.fetchBalance (params); - const info = this.safeValue (response, 'info', {}); + const defaultType = this.safeString (this.options, 'defaultType', 'future'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + const options = this.safeValue (this.options, 'fetchPositions', {}); + const defaultMethod = (type === 'delivery') ? 'dapiPrivateGetAccount' : 'fapiPrivateV2GetAccount'; + const method = this.safeString (options, type, defaultMethod); + const response = await this[method] (params); // // futures, delivery // @@ -11217,9 +12753,44 @@ module.exports = class binance extends Exchange { // ] // } // - const positions = this.safeValue2 (info, 'positions', 'userAssets', []); - // todo unify parsePosition/parsePositions - return positions; + // fapiPrivateGetPositionRisk, dapiPrivateGetPositionRisk + // + // [ + // { + // symbol: 'XRPUSD_210625', + // positionAmt: '0', + // entryPrice: '0.00000000', + // markPrice: '0.00000000', + // unRealizedProfit: '0.00000000', + // liquidationPrice: '0', + // leverage: '20', + // maxQty: '500000', + // marginType: 'cross', + // isolatedMargin: '0.00000000', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0', + // isolatedWallet: '0' + // }, + // { + // symbol: 'BTCUSD_210326', + // positionAmt: '1', + // entryPrice: '60665.79999885', + // markPrice: '60696.76856843', + // unRealizedProfit: '0.00000084', + // liquidationPrice: '58034.68208092', + // leverage: '20', + // maxQty: '50', + // marginType: 'isolated', + // isolatedMargin: '0.00008345', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0.00164753', + // isolatedWallet: '0.00008261' + // }, + // ] + // + return this.safeValue (response, 'positions', response); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -11357,7 +12928,7 @@ module.exports = class binance extends Exchange { // const fee = { 'currency': earnedCurrency, - 'cost': this.safeFloat (trade, 'serviceChargeAmount'), + 'cost': this.safeNumber (trade, 'serviceChargeAmount'), }; let symbol = undefined; let amount = undefined; @@ -11365,13 +12936,13 @@ module.exports = class binance extends Exchange { let side = undefined; if (tradedCurrencyIsQuote) { symbol = applicantSymbol; - amount = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); - cost = this.safeFloat (trade, 'amount'); + amount = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); + cost = this.safeNumber (trade, 'amount'); side = 'buy'; } else { symbol = tradedCurrency + '/' + earnedCurrency; - amount = this.safeFloat (trade, 'amount'); - cost = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); + amount = this.safeNumber (trade, 'amount'); + cost = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); side = 'sell'; } let price = undefined; @@ -11544,8 +13115,8 @@ module.exports = class binance extends Exchange { } } const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'transactionFee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'transactionFee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -11572,6 +13143,151 @@ module.exports = class binance extends Exchange { }; } + parseTransferStatus (status) { + const statuses = { + 'CONFIRMED': 'ok', + }; + return this.safeString (statuses, status, status); + } + + parseTransfer (transfer, currency = undefined) { + // + // transfer + // + // { + // "tranId":13526853623 + // } + // + // fetchTransfers + // + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // } + // + const id = this.safeString (transfer, 'tranId'); + const currencyId = this.safeString (transfer, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const amount = this.safeNumber (transfer, 'amount'); + const type = this.safeString (transfer, 'type'); + let fromAccount = undefined; + let toAccount = undefined; + const typesByAccount = this.safeValue (this.options, 'typesByAccount', {}); + if (type !== undefined) { + const parts = type.split ('_'); + fromAccount = this.safeValue (parts, 0); + toAccount = this.safeValue (parts, 1); + fromAccount = this.safeString (typesByAccount, fromAccount, fromAccount); + toAccount = this.safeString (typesByAccount, toAccount, toAccount); + } + const timestamp = this.safeInteger (transfer, 'timestamp'); + const status = this.parseTransferStatus (this.safeString (transfer, 'status')); + return { + 'info': transfer, + 'id': id, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'currency': code, + 'amount': amount, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': status, + }; + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount, fromAccount); + const toId = this.safeString (accountsByType, toAccount, toAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'asset': currency['id'], + 'amount': this.currencyToPrecision (code, amount), + 'type': type, + }; + const response = await this.sapiPostAssetTransfer (this.extend (request, params)); + // + // { + // "tranId":13526853623 + // } + // + const transfer = this.parseTransfer (response, currency); + return this.extend (transfer, { + 'amount': amount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + }); + } + + async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const defaultType = this.safeString2 (this.options, 'fetchTransfers', 'defaultType', 'spot'); + const fromAccount = this.safeString (params, 'fromAccount', defaultType); + const defaultTo = (fromAccount === 'future') ? 'spot' : 'future'; + const toAccount = this.safeString (params, 'toAccount', defaultTo); + let type = this.safeString (params, 'type'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + if (type === undefined) { + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount parameter must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount parameter must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'type': type, + }; + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['size'] = limit; + } + const response = await this.sapiGetAssetTransfer (this.extend (request, params)); + // + // { + // total: 3, + // rows: [ + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // }, + // ] + // } + // + const rows = this.safeValue (response, 'rows', []); + return this.parseTransfers (rows, currency, since, limit); + } + async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -11634,7 +13350,7 @@ module.exports = class binance extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (detail[id], 'withdrawFee'); + withdrawFees[code] = this.safeNumber (detail[id], 'withdrawFee'); } return { 'withdraw': withdrawFees, @@ -11681,8 +13397,8 @@ module.exports = class binance extends Exchange { return { 'info': fee, 'symbol': symbol, - 'maker': this.safeFloat (fee, 'maker'), - 'taker': this.safeFloat (fee, 'taker'), + 'maker': this.safeNumber (fee, 'maker'), + 'taker': this.safeNumber (fee, 'taker'), }; } @@ -11744,7 +13460,6 @@ module.exports = class binance extends Exchange { if (api === 'wapi') { url += '.html'; } - const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); if (path === 'historicalTrades') { if (this.apiKey) { headers = { @@ -11753,19 +13468,22 @@ module.exports = class binance extends Exchange { } else { throw new AuthenticationError (this.id + ' historicalTrades endpoint requires `apiKey` credential'); } - } else if (userDataStream) { + } + const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); + if (userDataStream) { if (this.apiKey) { // v1 special case for userDataStream - body = this.urlencode (params); headers = { 'X-MBX-APIKEY': this.apiKey, 'Content-Type': 'application/x-www-form-urlencoded', }; + if (method !== 'GET') { + body = this.urlencode (params); + } } else { throw new AuthenticationError (this.id + ' userDataStream endpoint requires `apiKey` credential'); } - } - if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { + } else if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { this.checkRequiredCredentials (); let query = undefined; const recvWindow = this.safeInteger (this.options, 'recvWindow', 5000); @@ -11797,13 +13515,8 @@ module.exports = class binance extends Exchange { headers['Content-Type'] = 'application/x-www-form-urlencoded'; } } else { - // userDataStream endpoints are public, but POST, PUT, DELETE - // therefore they don't accept URL query arguments - // https://github.com/ccxt/ccxt/issues/5224 - if (!userDataStream) { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } + if (Object.keys (params).length) { + url += '?' + this.urlencode (params); } } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; @@ -11885,7 +13598,7 @@ module.exports = class binance extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],24:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],25:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -11937,13 +13650,14 @@ module.exports = class binanceus extends binance { }; -},{"./binance.js":23}],25:[function(require,module,exports){ +},{"./binance.js":24}],26:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, InvalidNonce, AuthenticationError, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -12095,12 +13809,12 @@ module.exports = class bit2c extends Exchange { const currencyId = this.currencyId (code); const uppercase = currencyId.toUpperCase (); if (uppercase in balance) { - account['free'] = this.safeFloat (balance, 'AVAILABLE_' + uppercase); - account['total'] = this.safeFloat (balance, uppercase); + account['free'] = this.safeString (balance, 'AVAILABLE_' + uppercase); + account['total'] = this.safeString (balance, uppercase); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -12119,22 +13833,22 @@ module.exports = class bit2c extends Exchange { }; const ticker = await this.publicGetExchangesPairTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const averagePrice = this.safeFloat (ticker, 'av'); - const baseVolume = this.safeFloat (ticker, 'a'); + const averagePrice = this.safeNumber (ticker, 'av'); + const baseVolume = this.safeNumber (ticker, 'a'); let quoteVolume = undefined; if (baseVolume !== undefined && averagePrice !== undefined) { quoteVolume = baseVolume * averagePrice; } - const last = this.safeFloat (ticker, 'll'); + const last = this.safeNumber (ticker, 'll'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'h'), + 'bid': this.safeNumber (ticker, 'h'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'l'), + 'ask': this.safeNumber (ticker, 'l'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -12216,14 +13930,8 @@ module.exports = class bit2c extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -12236,7 +13944,7 @@ module.exports = class bit2c extends Exchange { } const id = this.safeString (order, 'id'); const status = this.safeString (order, 'status'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -12253,12 +13961,12 @@ module.exports = class bit2c extends Exchange { 'amount': amount, 'filled': undefined, 'remaining': undefined, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -12284,16 +13992,16 @@ module.exports = class bit2c extends Exchange { parseTrade (trade, market = undefined) { let timestamp = undefined; let id = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let orderId = undefined; let feeCost = undefined; let side = undefined; const reference = this.safeString (trade, 'reference'); if (reference !== undefined) { timestamp = this.safeTimestamp (trade, 'ticks'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'firstAmount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'firstAmount'); const reference_parts = reference.split ('|'); // reference contains 'pair|orderId|tradeId' if (market === undefined) { const marketId = this.safeString (trade, 'pair'); @@ -12311,12 +14019,12 @@ module.exports = class bit2c extends Exchange { } else if (side === 1) { side = 'sell'; } - feeCost = this.safeFloat (trade, 'feeAmount'); + feeCost = this.safeNumber (trade, 'feeAmount'); } else { timestamp = this.safeTimestamp (trade, 'date'); id = this.safeString (trade, 'tid'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'amount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'amount'); side = this.safeValue (trade, 'isBid'); if (side !== undefined) { if (side) { @@ -12330,6 +14038,9 @@ module.exports = class bit2c extends Exchange { if (market !== undefined) { symbol = market['symbol']; } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -12342,7 +14053,7 @@ module.exports = class bit2c extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': { 'cost': feeCost, 'currency': 'NIS', @@ -12398,13 +14109,14 @@ module.exports = class bit2c extends Exchange { }; -},{"./base/Exchange":6,"./base/errors":8}],26:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],27:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -12479,21 +14191,23 @@ module.exports = class bitbank extends Exchange { }, }, 'markets': { + 'BAT/JPY': { 'id': 'bat_jpy', 'symbol': 'BAT/JPY', 'base': 'BAT', 'quote': 'JPY', 'baseId': 'bat', 'quoteId': 'jpy' }, + 'BAT/BTC': { 'id': 'bat_btc', 'symbol': 'BAT/BTC', 'base': 'BAT', 'quote': 'BTC', 'baseId': 'bat', 'quoteId': 'btc' }, 'BCH/BTC': { 'id': 'bcc_btc', 'symbol': 'BCH/BTC', 'base': 'BCH', 'quote': 'BTC', 'baseId': 'bcc', 'quoteId': 'btc' }, 'BCH/JPY': { 'id': 'bcc_jpy', 'symbol': 'BCH/JPY', 'base': 'BCH', 'quote': 'JPY', 'baseId': 'bcc', 'quoteId': 'jpy' }, + 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, + 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, + 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, + 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, + 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, 'MONA/BTC': { 'id': 'mona_btc', 'symbol': 'MONA/BTC', 'base': 'MONA', 'quote': 'BTC', 'baseId': 'mona', 'quoteId': 'btc' }, 'MONA/JPY': { 'id': 'mona_jpy', 'symbol': 'MONA/JPY', 'base': 'MONA', 'quote': 'JPY', 'baseId': 'mona', 'quoteId': 'jpy' }, 'QTUM/BTC': { 'id': 'qtum_btc', 'symbol': 'QTUM/BTC', 'base': 'QTUM', 'quote': 'BTC', 'baseId': 'qtum', 'quoteId': 'btc' }, 'QTUM/JPY': { 'id': 'qtum_jpy', 'symbol': 'QTUM/JPY', 'base': 'QTUM', 'quote': 'JPY', 'baseId': 'qtum', 'quoteId': 'jpy' }, - 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, - 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, - 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, - 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, - 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, - 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, - 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, - 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, 'XLM/BTC': { 'id': 'xlm_btc', 'symbol': 'XLM/BTC', 'base': 'XLM', 'quote': 'BTC', 'baseId': 'xlm', 'quoteId': 'btc' }, + 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, + 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, + 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, }, 'fees': { 'trading': { @@ -12542,16 +14256,16 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -12561,7 +14275,7 @@ module.exports = class bitbank extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -12597,18 +14311,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; feeCurrency = market['quote']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'transaction_id', 'trade_id'); const takerOrMaker = this.safeString (trade, 'maker_taker'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee_amount_quote'); + const feeCost = this.safeNumber (trade, 'fee_amount_quote'); if (feeCost !== undefined) { fee = { 'currency': feeCurrency, @@ -12660,11 +14371,11 @@ module.exports = class bitbank extends Exchange { // return [ this.safeInteger (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -12715,14 +14426,13 @@ module.exports = class bitbank extends Exchange { const balance = assets[i]; const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'free_amount'), - 'used': this.safeFloat (balance, 'locked_amount'), - 'total': this.safeFloat (balance, 'onhand_amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'free_amount'); + account['used'] = this.safeString (balance, 'locked_amount'); + account['total'] = this.safeString (balance, 'onhand_amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -12747,21 +14457,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (order, 'ordered_at'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'start_amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const average = this.safeFloat (order, 'average_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'start_amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const average = this.safeNumber (order, 'average_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -12775,7 +14479,7 @@ module.exports = class bitbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, @@ -12783,7 +14487,7 @@ module.exports = class bitbank extends Exchange { 'trades': undefined, 'fee': undefined, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -13026,13 +14730,14 @@ module.exports = class bitbank extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],27:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],28:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { InvalidNonce, InsufficientFunds, AuthenticationError, InvalidOrder, ExchangeError, OrderNotFound, AccountSuspended, BadSymbol, OrderImmediatelyFillable, RateLimitExceeded, OnMaintenance, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -13307,8 +15012,8 @@ module.exports = class bitbay extends Exchange { if (this.inArray (base, fiatCurrencies) || this.inArray (quote, fiatCurrencies)) { fees = this.safeValue (this.fees, 'fiat', {}); } - const maker = this.safeFloat (fees, 'maker'); - const taker = this.safeFloat (fees, 'taker'); + const maker = this.safeNumber (fees, 'maker'); + const taker = this.safeNumber (fees, 'taker'); // todo: check that the limits have ben interpreted correctly // todo: parse the fees page result.push ({ @@ -13324,7 +15029,7 @@ module.exports = class bitbay extends Exchange { 'taker': taker, 'limits': { 'amount': { - 'min': this.safeFloat (first, 'minOffer'), + 'min': this.safeNumber (first, 'minOffer'), 'max': undefined, }, 'price': { @@ -13332,7 +15037,7 @@ module.exports = class bitbay extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (second, 'minOffer'), + 'min': this.safeNumber (second, 'minOffer'), 'max': undefined, }, }, @@ -13372,16 +15077,10 @@ module.exports = class bitbay extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (order, 'time'); - const amount = this.safeFloat (order, 'startAmount'); - const remaining = this.safeFloat (order, 'currentAmount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } + const amount = this.safeNumber (order, 'startAmount'); + const remaining = this.safeNumber (order, 'currentAmount'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'info': order, @@ -13394,16 +15093,16 @@ module.exports = class bitbay extends Exchange { 'timeInForce': undefined, 'postOnly': postOnly, 'side': this.safeStringLower (order, 'offerType'), - 'price': this.safeFloat (order, 'rate'), + 'price': this.safeNumber (order, 'rate'), 'stopPrice': undefined, 'amount': amount, 'cost': undefined, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'average': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -13456,11 +15155,11 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lockedFunds'); - account['free'] = this.safeFloat (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'lockedFunds'); + account['free'] = this.safeString (balance, 'availableFunds'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -13479,22 +15178,22 @@ module.exports = class bitbay extends Exchange { }; const ticker = await this.publicGetIdTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'volume'); - const vwap = this.safeFloat (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max'), + 'low': this.safeNumber (ticker, 'min'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -13503,7 +15202,7 @@ module.exports = class bitbay extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), + 'average': this.safeNumber (ticker, 'average'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -13804,7 +15503,7 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const change = this.safeValue (item, 'change', {}); - let amount = this.safeFloat (change, 'total'); + let amount = this.safeNumber (change, 'total'); let direction = 'in'; if (amount < 0) { direction = 'out'; @@ -13816,9 +15515,9 @@ module.exports = class bitbay extends Exchange { const referenceId = this.safeString (item, 'detailId'); const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const fundsBefore = this.safeValue (item, 'fundsBefore', {}); - const before = this.safeFloat (fundsBefore, 'total'); + const before = this.safeNumber (fundsBefore, 'total'); const fundsAfter = this.safeValue (item, 'fundsAfter', {}); - const after = this.safeFloat (fundsAfter, 'total'); + const after = this.safeNumber (fundsAfter, 'total'); return { 'info': item, 'id': id, @@ -13875,11 +15574,11 @@ module.exports = class bitbay extends Exchange { const first = this.safeValue (ohlcv, 1, {}); return [ this.safeInteger (ohlcv, 0), - this.safeFloat (first, 'o'), - this.safeFloat (first, 'h'), - this.safeFloat (first, 'l'), - this.safeFloat (first, 'c'), - this.safeFloat (first, 'v'), + this.safeNumber (first, 'o'), + this.safeNumber (first, 'h'), + this.safeNumber (first, 'l'), + this.safeNumber (first, 'c'), + this.safeNumber (first, 'v'), ]; } @@ -13962,15 +15661,12 @@ module.exports = class bitbay extends Exchange { if (wasTaker !== undefined) { takerOrMaker = wasTaker ? 'taker' : 'maker'; } - const price = this.safeFloat2 (trade, 'rate', 'r'); - const amount = this.safeFloat2 (trade, 'amount', 'a'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'commissionValue'); + const priceString = this.safeString2 (trade, 'rate', 'r'); + const amountString = this.safeString2 (trade, 'amount', 'a'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'commissionValue'); const marketId = this.safeString (trade, 'market'); market = this.safeMarket (marketId, market, '-'); const symbol = market['symbol']; @@ -14302,7 +15998,7 @@ module.exports = class bitbay extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],28:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],29:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -14338,7 +16034,7 @@ module.exports = class bitcoincom extends hitbtc { } }; -},{"./hitbtc.js":93}],29:[function(require,module,exports){ +},{"./hitbtc.js":91}],30:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -14346,6 +16042,7 @@ module.exports = class bitcoincom extends hitbtc { const Exchange = require ('./base/Exchange'); const { NotSupported, RateLimitExceeded, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, InvalidNonce, BadSymbol } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -14386,6 +16083,7 @@ module.exports = class bitfinex extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': '1m', @@ -14499,6 +16197,7 @@ module.exports = class bitfinex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'maker': 0.1 / 100, @@ -14685,6 +16384,8 @@ module.exports = class bitfinex extends Exchange { 'No summary found.': ExchangeError, // fetchTradingFees (summary) endpoint can give this vague error message 'Cannot evaluate your available balance, please try again': ExchangeNotAvailable, 'Unknown symbol': BadSymbol, + 'Cannot complete transfer. Exchange balance insufficient.': InsufficientFunds, + 'Momentary balance check. Please wait few seconds and try the transfer again.': ExchangeError, }, 'broad': { 'Invalid X-BFX-SIGNATURE': AuthenticationError, @@ -14782,6 +16483,15 @@ module.exports = class bitfinex extends Exchange { 'limit': 'exchange limit', 'market': 'exchange market', }, + 'accountsByType': { + 'spot': 'exchange', + 'margin': 'trading', + 'funding': 'deposit', + 'exchange': 'exchange', + 'trading': 'trading', + 'deposit': 'deposit', + 'derivatives': 'trading', + }, }, }); } @@ -14795,7 +16505,7 @@ module.exports = class bitfinex extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdraw[code] = this.safeFloat (fees, id); + withdraw[code] = this.safeNumber (fees, id); } return { 'info': response, @@ -14831,14 +16541,31 @@ module.exports = class bitfinex extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } async fetchMarkets (params = {}) { const ids = await this.publicGetSymbols (); + // + // [ "btcusd", "ltcusd", "ltcbtc" ] + // const details = await this.publicGetSymbolsDetails (); + // + // [ + // { + // "pair":"btcusd", + // "price_precision":5, + // "initial_margin":"10.0", + // "minimum_margin":"5.0", + // "maximum_order_size":"2000.0", + // "minimum_order_size":"0.0002", + // "expiration":"NA", + // "margin":true + // }, + // ] + // const result = []; for (let i = 0; i < details.length; i++) { const market = details[i]; @@ -14869,8 +16596,8 @@ module.exports = class bitfinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -14881,6 +16608,7 @@ module.exports = class bitfinex extends Exchange { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -14889,6 +16617,8 @@ module.exports = class bitfinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': true, + 'type': 'spot', + 'margin': margin, 'precision': precision, 'limits': limits, 'info': market, @@ -14913,40 +16643,15 @@ module.exports = class bitfinex extends Exchange { return this.decimalToPrecision (price, TRUNCATE, 8, DECIMAL_PLACES); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - const code = market[key]; - const currency = this.safeValue (this.currencies, code); - if (currency !== undefined) { - const precision = this.safeInteger (currency, 'precision'); - if (precision !== undefined) { - cost = parseFloat (this.currencyToPrecision (code, cost)); - } - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); - const types = { - 'exchange': 'exchange', - 'deposit': 'funding', - 'trading': 'margin', - }; - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } const query = this.omit (params, 'type'); const response = await this.privatePostBalances (query); // [ { type: 'deposit', @@ -14962,12 +16667,16 @@ module.exports = class bitfinex extends Exchange { // amount: '0.0005', // available: '0.0005' } ], const result = { 'info': response }; + const isDerivative = requestedType === 'derivatives'; for (let i = 0; i < response.length; i++) { const balance = response[i]; const type = this.safeString (balance, 'type'); - const parsedType = this.safeString (types, type); - if ((parsedType === balanceType) || (type === balanceType)) { - const currencyId = this.safeString (balance, 'currency'); + const currencyId = this.safeStringLower (balance, 'currency', ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { const code = this.safeCurrencyCode (currencyId); // bitfinex had BCH previously, now it's BAB, but the old // BCH symbol is kept for backward-compatibility @@ -14976,13 +16685,80 @@ module.exports = class bitfinex extends Exchange { // https://github.com/ccxt/ccxt/issues/4989 if (!(code in result)) { const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currencyId = this.currencyId (code); + const fromCurrencyId = this.convertDerivativesId (currencyId, fromAccount); + const toCurrencyId = this.convertDerivativesId (currencyId, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'walletfrom': fromId, + 'walletto': toId, + }; + const response = await this.privatePostTransfer (this.extend (request, params)); + // [ + // { + // status: 'success', + // message: '0.0001 Bitcoin transfered from Margin to Exchange' + // } + // ] + const result = this.safeValue (response, 0); + const status = this.safeString (result, 'status'); + const message = this.safeString (result, 'message'); + if (message === undefined) { + throw new ExchangeError (this.id + ' transfer failed'); + } + // [{"status":"error","message":"Momentary balance check. Please wait few seconds and try the transfer again."}] + if (status === 'error') { + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + return { + 'info': response, + 'status': status, + 'amount': requestedAmount, + 'code': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'timestamp': undefined, + 'datetime': undefined, + }; + } + + convertDerivativesId (currencyId, type) { + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if ((type !== 'derivatives' && type !== 'trading' && type !== 'margin') && isDerivativeCode) { + currencyId = currencyId.slice (0, start); + } else if (type === 'derivatives' && !isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + return currencyId; } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -15021,7 +16797,7 @@ module.exports = class bitfinex extends Exchange { } parseTicker (ticker, market = undefined) { - let timestamp = this.safeFloat (ticker, 'timestamp'); + let timestamp = this.safeNumber (ticker, 'timestamp'); if (timestamp !== undefined) { timestamp *= 1000; } @@ -15044,16 +16820,16 @@ module.exports = class bitfinex extends Exchange { } } } - const last = this.safeFloat (ticker, 'last_price'); + const last = this.safeNumber (ticker, 'last_price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -15062,8 +16838,8 @@ module.exports = class bitfinex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'mid'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'mid'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -15071,24 +16847,21 @@ module.exports = class bitfinex extends Exchange { parseTrade (trade, market) { const id = this.safeString (trade, 'tid'); - let timestamp = this.safeFloat (trade, 'timestamp'); + let timestamp = this.safeNumber (trade, 'timestamp'); if (timestamp !== undefined) { timestamp = parseInt (timestamp) * 1000; } const type = undefined; const side = this.safeStringLower (trade, 'type'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; if ('fee_amount' in trade) { - const feeCost = -this.safeFloat (trade, 'fee_amount'); + const feeCost = -this.safeNumber (trade, 'fee_amount'); const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { @@ -15203,6 +16976,30 @@ module.exports = class bitfinex extends Exchange { } parseOrder (order, market = undefined) { + // + // { + // id: 57334010955, + // cid: 1611584840966, + // cid_date: null, + // gid: null, + // symbol: 'ltcbtc', + // exchange: null, + // price: '0.0042125', + // avg_execution_price: '0.0042097', + // side: 'sell', + // type: 'exchange market', + // timestamp: '1611584841.0', + // is_live: false, + // is_cancelled: false, + // is_hidden: 0, + // oco_order: 0, + // was_forced: false, + // original_amount: '0.205176', + // remaining_amount: '0.0', + // executed_amount: '0.205176', + // src: 'web' + // } + // const side = this.safeString (order, 'side'); const open = this.safeValue (order, 'is_live'); const canceled = this.safeValue (order, 'is_cancelled'); @@ -15214,30 +17011,17 @@ module.exports = class bitfinex extends Exchange { } else { status = 'closed'; } - let symbol = undefined; - if (market === undefined) { - const marketId = this.safeStringUpper (order, 'symbol'); - if (marketId !== undefined) { - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } - } - } - if (market !== undefined) { - symbol = market['symbol']; - } - let orderType = order['type']; + const marketId = this.safeStringUpper (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market); + let orderType = this.safeString (order, 'type', ''); const exchange = orderType.indexOf ('exchange ') >= 0; if (exchange) { const parts = order['type'].split (' '); orderType = parts[1]; } - let timestamp = this.safeFloat (order, 'timestamp'); - if (timestamp !== undefined) { - timestamp = parseInt (timestamp) * 1000; - } + const timestamp = this.safeTimestamp (order, 'timestamp'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -15249,17 +17033,17 @@ module.exports = class bitfinex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': side, - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_execution_price'), - 'amount': this.safeFloat (order, 'original_amount'), - 'remaining': this.safeFloat (order, 'remaining_amount'), - 'filled': this.safeFloat (order, 'executed_amount'), + 'average': this.safeNumber (order, 'avg_execution_price'), + 'amount': this.safeNumber (order, 'original_amount'), + 'remaining': this.safeNumber (order, 'remaining_amount'), + 'filled': this.safeNumber (order, 'executed_amount'), 'status': status, 'fee': undefined, 'cost': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -15314,11 +17098,11 @@ module.exports = class bitfinex extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -15466,11 +17250,11 @@ module.exports = class bitfinex extends Exchange { // "timestamp_created": "1561716066.0" // } // - let timestamp = this.safeFloat (transaction, 'timestamp_created'); + let timestamp = this.safeNumber (transaction, 'timestamp_created'); if (timestamp !== undefined) { timestamp = parseInt (timestamp * 1000); } - let updated = this.safeFloat (transaction, 'timestamp'); + let updated = this.safeNumber (transaction, 'timestamp'); if (updated !== undefined) { updated = parseInt (updated * 1000); } @@ -15478,7 +17262,7 @@ module.exports = class bitfinex extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const type = this.safeStringLower (transaction, 'type'); // DEPOSIT or WITHDRAWAL const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -15491,7 +17275,7 @@ module.exports = class bitfinex extends Exchange { 'address': this.safeString (transaction, 'address'), // todo: this is actually the tag for XRP transfers (the address is missing) 'tag': undefined, // refix it properly for the tag from description 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -15545,7 +17329,7 @@ module.exports = class bitfinex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // @@ -15623,7 +17407,7 @@ module.exports = class bitfinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],30:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],31:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -15912,6 +17696,15 @@ module.exports = class bitfinex2 extends bitfinex { 'JPY': 'JPY', 'GBP': 'GBP', }, + // actually the correct names unlike the v1 + // we don't want to extend this with accountsByType in v1 + 'v2AccountsByType': { + 'spot': 'exchange', + 'exchange': 'exchange', + 'funding': 'funding', + 'margin': 'margin', + 'derivatives': 'margin', + }, }, 'exceptions': { 'exact': { @@ -15993,8 +17786,8 @@ module.exports = class bitfinex2 extends bitfinex { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -16005,6 +17798,7 @@ module.exports = class bitfinex2 extends bitfinex { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -16019,6 +17813,7 @@ module.exports = class bitfinex2 extends bitfinex { 'type': type, 'swap': false, 'spot': spot, + 'margin': margin, 'futures': futures, }); } @@ -16131,7 +17926,7 @@ module.exports = class bitfinex2 extends bitfinex { const ids = this.safeValue (response, 0, []); const result = {}; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; const code = this.safeCurrencyCode (id); const label = this.safeValue (indexed['label'], id, []); const name = this.safeString (label, 1); @@ -16139,13 +17934,14 @@ module.exports = class bitfinex2 extends bitfinex { const type = this.safeString (pool, 1); const feeValues = this.safeValue (indexed['fees'], id, []); const fees = this.safeValue (feeValues, 1, []); - const fee = this.safeFloat (fees, 1); + const fee = this.safeNumber (fees, 1); + const undl = this.safeValue (indexed['undl'], id, []); const precision = 8; // default precision, todo: fix "magic constants" - id = 'f' + id; + const fid = 'f' + id; result[code] = { - 'id': id, + 'id': fid, 'code': code, - 'info': [ id, label, pool, feeValues ], + 'info': [ id, label, pool, feeValues, undl ], 'type': type, 'name': name, 'active': true, @@ -16176,40 +17972,117 @@ module.exports = class bitfinex2 extends bitfinex { async fetchBalance (params = {}) { // this api call does not return the 'used' amount - use the v1 version instead (which also returns zero balances) + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 await this.loadMarkets (); - const response = await this.privatePostAuthRWallets (params); - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } + const isDerivative = requestedType === 'derivatives'; + const query = this.omit (params, 'type'); + const response = await this.privatePostAuthRWallets (query); const result = { 'info': response }; - for (let b = 0; b < response.length; b++) { - const balance = response[b]; - const accountType = balance[0]; - let currency = balance[1]; - const total = balance[2]; - const available = balance[4]; - if (accountType === balanceType) { - if (currency[0] === 't') { - currency = currency.slice (1); - } - const code = this.safeCurrencyCode (currency); + for (let i = 0; i < response.length; i++) { + const balance = response[i]; + const type = this.safeString (balance, 0); + const currencyId = this.safeStringLower (balance, 1, ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { + const code = this.safeCurrencyCode (currencyId); const account = this.account (); - // do not fill in zeroes and missing values in the parser - // rewrite and unify the following to use the unified parseBalance - account['total'] = total; - if (!available) { - if (available === 0) { - account['free'] = 0; - account['used'] = total; - } else { - account['free'] = total; - } - } else { - account['free'] = available; - account['used'] = account['total'] - account['free']; - } + account['total'] = this.safeString (balance, 2); + account['free'] = this.safeString (balance, 4); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currency = this.currency (code); + const fromCurrencyId = this.convertDerivativesId (currency, fromAccount); + const toCurrencyId = this.convertDerivativesId (currency, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + // this request is slightly different from v1 fromAccount -> from + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'from': fromId, + 'to': toId, + }; + const response = await this.privatePostAuthWTransfer (this.extend (request, params)); + // [1616451183763,"acc_tf",null,null,[1616451183763,"exchange","margin",null,"UST","UST",null,1],null,"SUCCESS","1.0 Tether USDt transfered from Exchange to Margin"] + const timestamp = this.safeInteger (response, 0); + // ["error",10001,"Momentary balance check. Please wait few seconds and try the transfer again."] + const error = this.safeString (response, 0); + if (error === 'error') { + const message = this.safeString (response, 2, ''); + // same message as in v1 + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + const info = this.safeValue (response, 4); + const fromResponse = this.safeString (info, 1); + const toResponse = this.safeString (info, 2); + const toCode = this.safeCurrencyCode (this.safeString (info, 5)); + const success = this.safeString (response, 6); + const status = (success === 'SUCCESS') ? 'ok' : undefined; + return { + 'info': response, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'status': status, + 'amount': requestedAmount, + 'code': toCode, + 'fromAccount': fromResponse, + 'toAccount': toResponse, + }; + } + + convertDerivativesId (currency, type) { + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 + // { + // id: 'fUSTF0', + // code: 'USTF0', + // info: [ 'USTF0', [], [], [], [ 'USTF0', 'UST' ] ], + const info = this.safeValue (currency, 'info'); + const transferId = this.safeString (info, 0); + const underlying = this.safeValue (info, 4, []); + let currencyId = undefined; + if (type === 'derivatives') { + currencyId = this.safeString (underlying, 0, transferId); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if (!isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + } else if (type !== 'margin') { + currencyId = this.safeString (underlying, 1, transferId); + } else { + currencyId = transferId; + } + return currencyId; } async fetchOrder (id, symbol = undefined, params = {}) { @@ -16239,9 +18112,10 @@ module.exports = class bitfinex2 extends bitfinex { const priceIndex = (fullRequest['precision'] === 'R0') ? 1 : 0; for (let i = 0; i < orderbook.length; i++) { const order = orderbook[i]; - const price = order[priceIndex]; - const amount = Math.abs (order[2]); - const side = (order[2] > 0) ? 'bids' : 'asks'; + const price = this.safeNumber (order, priceIndex); + const signedAmount = this.safeNumber (order, 2); + const amount = Math.abs (signedAmount); + const side = (signedAmount > 0) ? 'bids' : 'asks'; result[side].push ([ price, amount ]); } result['bids'] = this.sortBy (result['bids'], 0, true); @@ -16256,26 +18130,26 @@ module.exports = class bitfinex2 extends bitfinex { symbol = market['symbol']; } const length = ticker.length; - const last = ticker[length - 4]; + const last = this.safeNumber (ticker, length - 4); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': ticker[length - 2], - 'low': ticker[length - 1], - 'bid': ticker[length - 10], + 'high': this.safeNumber (ticker, length - 2), + 'low': this.safeNumber (ticker, length - 1), + 'bid': this.safeNumber (ticker, length - 10), 'bidVolume': undefined, - 'ask': ticker[length - 8], + 'ask': this.safeNumber (ticker, length - 8), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': ticker[length - 6], - 'percentage': ticker[length - 5] * 100, + 'change': this.safeNumber (ticker, length - 6), + 'percentage': this.safeNumber (ticker, length - 5) * 100, 'average': undefined, - 'baseVolume': ticker[length - 3], + 'baseVolume': this.safeNumber (ticker, length - 3), 'quoteVolume': undefined, 'info': ticker, }; @@ -16364,12 +18238,12 @@ module.exports = class bitfinex2 extends bitfinex { // const tradeLength = trade.length; const isPrivate = (tradeLength > 5); - const id = trade[0].toString (); + const id = this.safeString (trade, 0); const amountIndex = isPrivate ? 4 : 2; - let amount = trade[amountIndex]; + let amount = this.safeNumber (trade, amountIndex); let cost = undefined; const priceIndex = isPrivate ? 5 : 3; - const price = trade[priceIndex]; + const price = this.safeNumber (trade, priceIndex); let side = undefined; let orderId = undefined; let takerOrMaker = undefined; @@ -16377,7 +18251,7 @@ module.exports = class bitfinex2 extends bitfinex { let fee = undefined; let symbol = undefined; const timestampIndex = isPrivate ? 2 : 1; - const timestamp = trade[timestampIndex]; + const timestamp = this.safeInteger (trade, timestampIndex); if (isPrivate) { const marketId = trade[1]; if (marketId in this.markets_by_id) { @@ -16386,10 +18260,12 @@ module.exports = class bitfinex2 extends bitfinex { } else { symbol = this.parseSymbol (marketId); } - orderId = trade[3].toString (); - takerOrMaker = (trade[8] === 1) ? 'maker' : 'taker'; - let feeCost = trade[9]; - const feeCurrency = this.safeCurrencyCode (trade[10]); + orderId = this.safeString (trade, 3); + const maker = this.safeInteger (trade, 8); + takerOrMaker = (maker === 1) ? 'maker' : 'taker'; + let feeCost = this.safeNumber (trade, 9); + const feeCurrencyId = this.safeString (trade, 10); + const feeCurrency = this.safeCurrencyCode (feeCurrencyId); if (feeCost !== undefined) { feeCost = -feeCost; if (symbol in this.markets) { @@ -16530,10 +18406,10 @@ module.exports = class bitfinex2 extends bitfinex { // https://github.com/ccxt/ccxt/issues/6686 // const timestamp = this.safeTimestamp (order, 5); const timestamp = this.safeInteger (order, 5); - const remaining = Math.abs (this.safeFloat (order, 6)); - const amount = Math.abs (this.safeFloat (order, 7)); - const filled = amount - remaining; - const side = (order[7] < 0) ? 'sell' : 'buy'; + const remaining = Math.abs (this.safeNumber (order, 6)); + const signedAmount = this.safeNumber (order, 7); + const amount = Math.abs (signedAmount); + const side = (signedAmount < 0) ? 'sell' : 'buy'; const orderType = this.safeString (order, 8); const type = this.safeString (this.safeValue (this.options, 'exchangeTypes'), orderType); let status = undefined; @@ -16542,11 +18418,10 @@ module.exports = class bitfinex2 extends bitfinex { const parts = statusString.split (' @ '); status = this.parseOrderStatus (this.safeString (parts, 0)); } - const price = this.safeFloat (order, 16); - const average = this.safeFloat (order, 17); - const cost = price * filled; + const price = this.safeNumber (order, 16); + const average = this.safeNumber (order, 17); const clientOrderId = this.safeString (order, 2); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -16561,14 +18436,14 @@ module.exports = class bitfinex2 extends bitfinex { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -16585,11 +18460,11 @@ module.exports = class bitfinex2 extends bitfinex { if ((orderType === 'LIMIT') || (orderType === 'EXCHANGE LIMIT')) { request['price'] = this.numberToString (price); } else if ((orderType === 'STOP') || (orderType === 'EXCHANGE STOP')) { - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'STOP LIMIT') || (orderType === 'EXCHANGE STOP LIMIT')) { - const priceAuxLimit = this.safeFloat (params, 'price_aux_limit'); - let stopPrice = this.safeFloat (params, 'stopPrice'); + const priceAuxLimit = this.safeNumber (params, 'price_aux_limit'); + let stopPrice = this.safeNumber (params, 'stopPrice'); if (priceAuxLimit === undefined) { if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter or a price_aux_limit parameter for a ' + orderType + ' order'); @@ -16604,9 +18479,9 @@ module.exports = class bitfinex2 extends bitfinex { } request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'TRAILING STOP') || (orderType === 'EXCHANGE TRAILING STOP')) { - const priceTrailing = this.safeFloat (params, 'price_trailing'); + const priceTrailing = this.safeNumber (params, 'price_trailing'); request['price_trailing'] = this.numberToString (priceTrailing); - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'FOK') || (orderType === 'EXCHANGE FOK') || (orderType === 'IOC') || (orderType === 'EXCHANGE IOC')) { request['price'] = this.numberToString (price); @@ -16938,11 +18813,11 @@ module.exports = class bitfinex2 extends bitfinex { if (currency !== undefined) { code = currency['code']; } - feeCost = this.safeFloat (data, 8); + feeCost = this.safeNumber (data, 8); if (feeCost !== undefined) { feeCost = -feeCost; } - amount = this.safeFloat (data, 5); + amount = this.safeNumber (data, 5); id = this.safeValue (data, 0); status = 'ok'; if (id === 0) { @@ -16956,7 +18831,7 @@ module.exports = class bitfinex2 extends bitfinex { timestamp = this.safeInteger (transaction, 5); updated = this.safeInteger (transaction, 6); status = this.parseTransactionStatus (this.safeString (transaction, 9)); - amount = this.safeFloat (transaction, 12); + amount = this.safeNumber (transaction, 12); if (amount !== undefined) { if (amount < 0) { type = 'withdrawal'; @@ -16964,7 +18839,7 @@ module.exports = class bitfinex2 extends bitfinex { type = 'deposit'; } } - feeCost = this.safeFloat (transaction, 13); + feeCost = this.safeNumber (transaction, 13); if (feeCost !== undefined) { feeCost = -feeCost; } @@ -17092,7 +18967,7 @@ module.exports = class bitfinex2 extends bitfinex { }); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // @@ -17197,13 +19072,14 @@ module.exports = class bitfinex2 extends bitfinex { } }; -},{"./base/errors":8,"./bitfinex.js":29}],31:[function(require,module,exports){ +},{"./base/errors":9,"./bitfinex.js":30}],32:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -17385,11 +19261,11 @@ module.exports = class bitflyer extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'amount'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -17408,16 +19284,16 @@ module.exports = class bitflyer extends Exchange { }; const ticker = await this.publicGetGetticker (this.extend (request, params)); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'ltp'); + const last = this.safeNumber (ticker, 'ltp'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'best_bid'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -17427,7 +19303,7 @@ module.exports = class bitflyer extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_by_product'), + 'baseVolume': this.safeNumber (ticker, 'volume_by_product'), 'quoteVolume': undefined, 'info': ticker, }; @@ -17451,14 +19327,11 @@ module.exports = class bitflyer extends Exchange { order = this.safeString (trade, 'child_order_acceptance_id'); } const timestamp = this.parse8601 (this.safeString (trade, 'exec_date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -17534,18 +19407,17 @@ module.exports = class bitflyer extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'child_order_date')); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'outstanding_size'); - const filled = this.safeFloat (order, 'executed_size'); - const price = this.safeFloat (order, 'price'); - const cost = price * filled; + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'outstanding_size'); + const filled = this.safeNumber (order, 'executed_size'); + const price = this.safeNumber (order, 'price'); const status = this.parseOrderStatus (this.safeString (order, 'child_order_state')); const type = this.safeStringLower (order, 'child_order_type'); const side = this.safeStringLower (order, 'side'); const marketId = this.safeString (order, 'product_code'); const symbol = this.safeSymbol (marketId, market); let fee = undefined; - const feeCost = this.safeFloat (order, 'total_commission'); + const feeCost = this.safeNumber (order, 'total_commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -17554,7 +19426,7 @@ module.exports = class bitflyer extends Exchange { }; } const id = this.safeString (order, 'child_order_acceptance_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -17569,14 +19441,14 @@ module.exports = class bitflyer extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrders (symbol = undefined, since = undefined, limit = 100, params = {}) { @@ -17639,7 +19511,7 @@ module.exports = class bitflyer extends Exchange { return this.parseTrades (response, market, since, limit); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { if (symbols === undefined) { throw new ArgumentsRequired (this.id + ' fetchPositions() requires a `symbols` argument, exactly one symbol in an array'); } @@ -17723,13 +19595,14 @@ module.exports = class bitflyer extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],32:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],33:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, DDoSProtection, PermissionDenied, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -17985,7 +19858,7 @@ module.exports = class bitforex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -18021,14 +19894,11 @@ module.exports = class bitforex extends Exchange { const timestamp = this.safeInteger (trade, 'time'); const id = this.safeString (trade, 'tid'); const orderId = undefined; - const amount = this.safeFloat (trade, 'amount'); - const price = this.safeFloat (trade, 'price'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const sideId = this.safeInteger (trade, 'direction'); const side = this.parseSide (sideId); return { @@ -18071,12 +19941,12 @@ module.exports = class bitforex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'active'); - account['total'] = this.safeFloat (balance, 'fix'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'active'); + account['total'] = this.safeString (balance, 'fix'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTicker (symbol, params = {}) { @@ -18092,21 +19962,21 @@ module.exports = class bitforex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (data, 'high'), - 'low': this.safeFloat (data, 'low'), - 'bid': this.safeFloat (data, 'buy'), + 'high': this.safeNumber (data, 'high'), + 'low': this.safeNumber (data, 'low'), + 'bid': this.safeNumber (data, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (data, 'sell'), + 'ask': this.safeNumber (data, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (data, 'last'), - 'last': this.safeFloat (data, 'last'), + 'close': this.safeNumber (data, 'last'), + 'last': this.safeNumber (data, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (data, 'vol'), + 'baseVolume': this.safeNumber (data, 'vol'), 'quoteVolume': undefined, 'info': response, }; @@ -18126,11 +19996,11 @@ module.exports = class bitforex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -18198,26 +20068,24 @@ module.exports = class bitforex extends Exchange { parseOrder (order, market = undefined) { const id = this.safeString (order, 'orderId'); - const timestamp = this.safeFloat (order, 'createTime'); - const lastTradeTimestamp = this.safeFloat (order, 'lastTime'); + const timestamp = this.safeNumber (order, 'createTime'); + const lastTradeTimestamp = this.safeNumber (order, 'lastTime'); const symbol = market['symbol']; const sideId = this.safeInteger (order, 'tradeType'); const side = this.parseSide (sideId); const type = undefined; - const price = this.safeFloat (order, 'orderPrice'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderAmount'); - const filled = this.safeFloat (order, 'dealAmount'); - const remaining = amount - filled; + const price = this.safeNumber (order, 'orderPrice'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderAmount'); + const filled = this.safeNumber (order, 'dealAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderState')); - const cost = filled * price; const feeSide = (side === 'buy') ? 'base' : 'quote'; const feeCurrency = market[feeSide]; const fee = { - 'cost': this.safeFloat (order, 'tradeFee'), + 'cost': this.safeNumber (order, 'tradeFee'), 'currency': feeCurrency, }; - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -18231,16 +20099,15 @@ module.exports = class bitforex extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -18356,7 +20223,7 @@ module.exports = class bitforex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],33:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],34:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -18364,6 +20231,7 @@ module.exports = class bitforex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -19152,7 +21020,7 @@ module.exports = class bitget extends Exchange { let swap = false; const baseId = this.safeString2 (market, 'base_currency', 'coin'); const quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { marketType = 'swap'; spot = false; @@ -19170,7 +21038,7 @@ module.exports = class bitget extends Exchange { 'amount': parseFloat ('1e-' + sizeIncrement), 'price': parseFloat ('1e-' + tickSize), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const status = this.safeString (market, 'status'); let active = undefined; if (status !== undefined) { @@ -19427,26 +21295,26 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat2 (ticker, 'last', 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'last', 'close'); + const open = this.safeNumber (ticker, 'open'); let bidVolume = undefined; let askVolume = undefined; let bid = this.safeValue (ticker, 'bid'); if (bid === undefined) { - bid = this.safeFloat (ticker, 'best_bid'); + bid = this.safeNumber (ticker, 'best_bid'); } else { - bidVolume = this.safeFloat (bid, 1); - bid = this.safeFloat (bid, 0); + bidVolume = this.safeNumber (bid, 1); + bid = this.safeNumber (bid, 0); } let ask = this.safeValue (ticker, 'ask'); if (ask === undefined) { - ask = this.safeFloat (ticker, 'best_ask'); + ask = this.safeNumber (ticker, 'best_ask'); } else { - askVolume = this.safeFloat (ask, 1); - ask = this.safeFloat (ask, 0); + askVolume = this.safeNumber (ask, 1); + ask = this.safeNumber (ask, 0); } - const baseVolume = this.safeFloat2 (ticker, 'amount', 'volume_24h'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber2 (ticker, 'amount', 'volume_24h'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; @@ -19460,8 +21328,8 @@ module.exports = class bitget extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -19696,9 +21564,12 @@ module.exports = class bitget extends Exchange { } let timestamp = this.safeInteger (trade, 'created_at'); timestamp = this.safeInteger2 (trade, 'timestamp', 'ts', timestamp); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'filled_amount', 'order_qty'); - amount = this.safeFloat2 (trade, 'size', 'amount', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'filled_amount', 'order_qty'); + amountString = this.safeString2 (trade, 'size', 'amount', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -19717,18 +21588,13 @@ module.exports = class bitget extends Exchange { type = this.parseOrderType (side); side = this.parseOrderSide (side); } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - let feeCost = this.safeFloat (trade, 'fee'); - if (feeCost === undefined) { - feeCost = this.safeFloat (trade, 'filled_fees'); + let feeCostString = this.safeString (trade, 'fee'); + if (feeCostString === undefined) { + feeCostString = this.safeString (trade, 'filled_fees'); } else { - feeCost = -feeCost; + feeCostString = (feeCostString[0] === '-') ? feeCostString.slice (1) : feeCostString; } + const feeCost = this.parseNumber (feeCostString); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -19851,23 +21717,23 @@ module.exports = class bitget extends Exchange { const volumeIndex = this.safeString (volume, market['type'], 'amount'); return [ this.safeInteger (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets ]; } else { const volumeIndex = this.safeValue (volume, market['type'], 6); return [ this.safeInteger (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, volumeIndex), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, volumeIndex), // Base Volume ]; } } @@ -19969,13 +21835,13 @@ module.exports = class bitget extends Exchange { } const type = this.safeValue (balance, 'type'); if (type === 'trade') { - result[code]['free'] = this.safeFloat (balance, 'balance'); + result[code]['free'] = this.safeString (balance, 'balance'); } else if ((type === 'frozen') || (type === 'lock')) { - const used = this.safeFloat (result[code], 'used'); - result[code]['used'] = this.sum (used, this.safeFloat (balance, 'balance')); + const used = this.safeString (result[code], 'used'); + result[code]['used'] = Precise.stringAdd (used, this.safeString (balance, 'balance')); } } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseSwapBalance (response) { @@ -19999,11 +21865,11 @@ module.exports = class bitget extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeString (balance, 'equity'); + account['free'] = this.safeString (balance, 'total_avail_balance'); result[symbol] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchAccounts (params = {}) { @@ -20280,26 +22146,13 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let amount = this.safeFloat2 (order, 'amount', 'size'); - const filled = this.safeFloat2 (order, 'filled_amount', 'filled_qty'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - amount = Math.max (amount, filled); - remaining = Math.max (0, amount - filled); - } - } - if (type === 'market') { - remaining = 0; - } - const cost = this.safeFloat (order, 'filled_cash_amount'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); - if ((average === undefined) && (filled !== undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } + const amount = this.safeNumber2 (order, 'amount', 'size'); + const filled = this.safeNumber2 (order, 'filled_amount', 'filled_qty'); + const cost = this.safeNumber (order, 'filled_cash_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'price_avg'); const status = this.parseOrderStatus (this.safeString2 (order, 'state', 'status')); - const feeCost = this.safeFloat2 (order, 'filled_fees', 'fee'); + const feeCost = this.safeNumber2 (order, 'filled_fees', 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -20309,7 +22162,7 @@ module.exports = class bitget extends Exchange { }; } const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -20327,11 +22180,11 @@ module.exports = class bitget extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -20378,7 +22231,7 @@ module.exports = class bitget extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'amount'); + let cost = this.safeNumber (params, 'amount'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -20928,12 +22781,12 @@ module.exports = class bitget extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const txid = this.safeString (transaction, 'tx_hash'); const timestamp = this.safeInteger (transaction, 'created_at'); const updated = this.safeInteger (transaction, 'updated_at'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -21123,7 +22976,7 @@ module.exports = class bitget extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.swapGetPositionAllPosition (params); // @@ -21264,7 +23117,7 @@ module.exports = class bitget extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],34:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],35:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -21272,6 +23125,7 @@ module.exports = class bitget extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, AuthenticationError, BadRequest, PermissionDenied, InvalidAddress, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); const { DECIMAL_PLACES, SIGNIFICANT_DIGITS, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -21465,12 +23319,12 @@ module.exports = class bithumb extends Exchange { const account = this.account (); const currency = this.currency (code); const lowerCurrencyId = this.safeStringLower (currency, 'id'); - account['total'] = this.safeFloat (balances, 'total_' + lowerCurrencyId); - account['used'] = this.safeFloat (balances, 'in_use_' + lowerCurrencyId); - account['free'] = this.safeFloat (balances, 'available_' + lowerCurrencyId); + account['total'] = this.safeString (balances, 'total_' + lowerCurrencyId); + account['used'] = this.safeString (balances, 'in_use_' + lowerCurrencyId); + account['free'] = this.safeString (balances, 'available_' + lowerCurrencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -21532,8 +23386,8 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'opening_price'); - const close = this.safeFloat (ticker, 'closing_price'); + const open = this.safeNumber (ticker, 'opening_price'); + const close = this.safeNumber (ticker, 'closing_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -21544,18 +23398,18 @@ module.exports = class bithumb extends Exchange { } average = this.sum (open, close) / 2; } - const baseVolume = this.safeFloat (ticker, 'units_traded_24H'); - const quoteVolume = this.safeFloat (ticker, 'acc_trade_value_24H'); + const baseVolume = this.safeNumber (ticker, 'units_traded_24H'); + const quoteVolume = this.safeNumber (ticker, 'acc_trade_value_24H'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -21661,11 +23515,11 @@ module.exports = class bithumb extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -21755,18 +23609,16 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'units_traded', 'units'); - let cost = this.safeFloat (trade, 'total'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'units_traded', 'units'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.commonCurrencyCode (feeCurrencyId); @@ -21969,14 +23821,14 @@ module.exports = class bithumb extends Exchange { const sideProperty = this.safeValue2 (order, 'type', 'side'); const side = (sideProperty === 'bid') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'order_status')); - let price = this.safeFloat2 (order, 'order_price', 'price'); + let price = this.safeNumber2 (order, 'order_price', 'price'); let type = 'limit'; if (price === 0) { price = undefined; type = 'market'; } - const amount = this.safeFloat2 (order, 'order_qty', 'units'); - let remaining = this.safeFloat (order, 'units_remaining'); + const amount = this.safeNumber2 (order, 'order_qty', 'units'); + let remaining = this.safeNumber (order, 'units_remaining'); if (remaining === undefined) { if (status === 'closed') { remaining = 0; @@ -21995,65 +23847,14 @@ module.exports = class bithumb extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let filled = undefined; - let cost = undefined; - let average = undefined; const id = this.safeString (order, 'order_id'); - const rawTrades = this.safeValue (order, 'contract'); - let trades = undefined; - let fee = undefined; - let fees = undefined; - let feesByCurrency = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'side': side, - 'symbol': symbol, - 'order': id, - }); - filled = 0; - feesByCurrency = {}; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - filled = this.sum (filled, trade['amount']); - cost = this.sum (cost, trade['cost']); - const tradeFee = trade['fee']; - const feeCurrency = tradeFee['currency']; - if (feeCurrency in feesByCurrency) { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': this.sum (feesByCurrency[feeCurrency]['cost'], tradeFee['cost']), - }; - } else { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': tradeFee['cost'], - }; - } - } - const feeCurrencies = Object.keys (feesByCurrency); - const feeCurrenciesLength = feeCurrencies.length; - if (feeCurrenciesLength > 1) { - fees = []; - for (let i = 0; i < feeCurrencies.length; i++) { - const feeCurrency = feeCurrencies[i]; - fees.push (feesByCurrency[feeCurrency]); - } - } else { - fee = this.safeValue (feesByCurrency, feeCurrencies[0]); - } - if (filled !== 0) { - average = cost / filled; - } - } - if (amount !== undefined) { - if ((filled === undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if ((remaining === undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const result = { + const rawTrades = this.safeValue (order, 'contract', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'side': side, + 'symbol': symbol, + 'order': id, + }); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -22068,20 +23869,14 @@ module.exports = class bithumb extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, + 'cost': undefined, + 'average': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': trades, - }; - if (fee !== undefined) { - result['fee'] = fee; - } else if (fees !== undefined) { - result['fees'] = fees; - } - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -22241,7 +24036,7 @@ module.exports = class bithumb extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],35:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],36:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -22272,7 +24067,7 @@ module.exports = class bitkk extends zb { } }; -},{"./zb.js":182}],36:[function(require,module,exports){ +},{"./zb.js":178}],37:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -22710,16 +24505,16 @@ module.exports = class bitmart extends Exchange { // const pricePrecision = this.safeInteger (market, 'price_max_precision'); const precision = { - 'amount': this.safeFloat (market, 'base_min_size'), + 'amount': this.safeNumber (market, 'base_min_size'), 'price': parseFloat (this.decimalToPrecision (Math.pow (10, -pricePrecision), ROUND, 10)), }; - const minBuyCost = this.safeFloat (market, 'min_buy_amount'); - const minSellCost = this.safeFloat (market, 'min_sell_amount'); + const minBuyCost = this.safeNumber (market, 'min_buy_amount'); + const minSellCost = this.safeNumber (market, 'min_sell_amount'); const minCost = Math.max (minBuyCost, minSellCost); const limits = { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': { 'min': undefined, @@ -22829,16 +24624,16 @@ module.exports = class bitmart extends Exchange { // // the docs are wrong: https://github.com/ccxt/ccxt/issues/5612 // - const amountPrecision = this.safeFloat (contract, 'vol_unit'); - const pricePrecision = this.safeFloat (contract, 'price_unit'); + const amountPrecision = this.safeNumber (contract, 'vol_unit'); + const pricePrecision = this.safeNumber (contract, 'price_unit'); const precision = { 'amount': amountPrecision, 'price': pricePrecision, }; const limits = { 'amount': { - 'min': this.safeFloat (contract, 'min_vol'), - 'max': this.safeFloat (contract, 'max_vol'), + 'min': this.safeNumber (contract, 'min_vol'), + 'max': this.safeNumber (contract, 'max_vol'), }, 'price': { 'min': undefined, @@ -22861,8 +24656,8 @@ module.exports = class bitmart extends Exchange { future = true; } const feeConfig = this.safeValue (market, 'fee_config', {}); - const maker = this.safeFloat (feeConfig, 'maker_fee'); - const taker = this.safeFloat (feeConfig, 'taker_fee'); + const maker = this.safeNumber (feeConfig, 'maker_fee'); + const taker = this.safeNumber (feeConfig, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -22950,33 +24745,33 @@ module.exports = class bitmart extends Exchange { const timestamp = this.safeTimestamp (ticker, 'timestamp', this.milliseconds ()); const marketId = this.safeString2 (ticker, 'symbol', 'contract_id'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat2 (ticker, 'close_24h', 'last_price'); - let percentage = this.safeFloat (ticker, 'fluctuation', 'rise_fall_rate'); + const last = this.safeNumber2 (ticker, 'close_24h', 'last_price'); + let percentage = this.safeNumber (ticker, 'fluctuation', 'rise_fall_rate'); if (percentage !== undefined) { percentage *= 100; } - const baseVolume = this.safeFloat2 (ticker, 'base_volume_24h', 'base_coin_volume'); - const quoteVolume = this.safeFloat2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); + const baseVolume = this.safeNumber2 (ticker, 'base_volume_24h', 'base_coin_volume'); + const quoteVolume = this.safeNumber2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const open = this.safeFloat2 (ticker, 'open_24h', 'open'); + const open = this.safeNumber2 (ticker, 'open_24h', 'open'); let average = undefined; if ((last !== undefined) && (open !== undefined)) { average = this.sum (last, open) / 2; } - average = this.safeFloat (ticker, 'avg_price', average); + average = this.safeNumber (ticker, 'avg_price', average); const price = this.safeValue (ticker, 'depth_price', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), - 'bid': this.safeFloat (price, 'best_bid', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (price, 'best_ask', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), + 'bid': this.safeNumber (price, 'best_bid', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (price, 'best_ask', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open_24h'), + 'open': this.safeNumber (ticker, 'open_24h'), 'close': last, 'last': last, 'previousClose': undefined, @@ -23280,18 +25075,18 @@ module.exports = class bitmart extends Exchange { if (execType !== undefined) { takerOrMaker = (execType === 'M') ? 'maker' : 'taker'; } - let price = this.safeFloat2 (trade, 'price', 'deal_price'); - price = this.safeFloat (trade, 'price_avg', price); - let amount = this.safeFloat2 (trade, 'amount', 'deal_vol'); - amount = this.safeFloat (trade, 'size', amount); - let cost = this.safeFloat2 (trade, 'count', 'notional'); + let price = this.safeNumber2 (trade, 'price', 'deal_price'); + price = this.safeNumber (trade, 'price_avg', price); + let amount = this.safeNumber2 (trade, 'amount', 'deal_vol'); + amount = this.safeNumber (trade, 'size', amount); + let cost = this.safeNumber2 (trade, 'count', 'notional'); if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { cost = amount * price; } const orderId = this.safeInteger (trade, 'order_id'); const marketId = this.safeString2 (trade, 'contract_id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (trade, 'fees'); + const feeCost = this.safeNumber (trade, 'fees'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_coin_name'); @@ -23419,11 +25214,11 @@ module.exports = class bitmart extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -23750,11 +25545,11 @@ module.exports = class bitmart extends Exchange { currencyId = this.safeString (balance, 'coind_code', currencyId); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat2 (balance, 'available', 'available_vol'); - account['used'] = this.safeFloat2 (balance, 'frozen', 'freeze_vol'); + account['free'] = this.safeString2 (balance, 'available', 'available_vol'); + account['used'] = this.safeString2 (balance, 'frozen', 'freeze_vol'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -23823,29 +25618,10 @@ module.exports = class bitmart extends Exchange { if (market !== undefined) { status = this.parseOrderStatusByType (market['type'], this.safeString (order, 'status')); } - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat2 (order, 'price_avg', 'done_avg_price'); - const amount = this.safeFloat2 (order, 'size', 'vol'); - let cost = undefined; - let filled = this.safeFloat2 (order, 'filled_size', 'done_vol'); - let remaining = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - if (filled === undefined) { - filled = Math.max (0, amount - remaining); - } - } - if (filled !== undefined) { - if (remaining === undefined) { - remaining = Math.max (0, amount - filled); - } - if (cost === undefined) { - if (average !== undefined) { - cost = average * filled; - } - } - } - } + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber2 (order, 'price_avg', 'done_avg_price'); + const amount = this.safeNumber2 (order, 'size', 'vol'); + const filled = this.safeNumber2 (order, 'filled_size', 'done_vol'); let side = this.safeString (order, 'side'); // 1 = Open long // 2 = Close short @@ -23867,7 +25643,7 @@ module.exports = class bitmart extends Exchange { average = undefined; } } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -23882,14 +25658,14 @@ module.exports = class bitmart extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatusByType (type, status) { @@ -23930,7 +25706,7 @@ module.exports = class bitmart extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -24516,12 +26292,12 @@ module.exports = class bitmart extends Exchange { type = 'deposit'; id = depositId; } - const amount = this.safeFloat (transaction, 'arrival_amount'); + const amount = this.safeNumber (transaction, 'arrival_amount'); const timestamp = this.safeInteger (transaction, 'tapply_timeime'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -24637,1735 +26413,7 @@ module.exports = class bitmart extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],37:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); - -// --------------------------------------------------------------------------- - -module.exports = class bitmax extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'bitmax', - 'name': 'BitMax', - 'countries': [ 'CN' ], // China - 'rateLimit': 500, - // new metainfo interface - 'has': { - 'CORS': false, - 'fetchMarkets': true, - 'fetchCurrencies': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchOHLCV': true, - 'fetchTrades': true, - 'fetchAccounts': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'cancelAllOrders': true, - 'fetchDepositAddress': true, - 'fetchTransactions': true, - 'fetchDeposits': true, - 'fetchWithdrawals': true, - 'fetchOrder': true, - 'fetchOrders': true, - 'fetchOpenOrders': true, - 'fetchClosedOrders': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '6h': '360', - '12h': '720', - '1d': '1d', - '1w': '1w', - '1M': '1m', - }, - 'version': 'v1', - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg', - 'api': 'https://bitmax.io', - 'test': 'https://bitmax-test.io', - 'www': 'https://bitmax.io', - 'doc': [ - 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', - ], - 'fees': 'https://bitmax.io/#/feeRate/tradeRate', - 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', - }, - 'api': { - 'public': { - 'get': [ - 'assets', - 'products', - 'ticker', - 'barhist/info', - 'barhist', - 'depth', - 'trades', - 'cash/assets', // not documented - 'cash/products', // not documented - 'margin/assets', // not documented - 'margin/products', // not documented - 'futures/collateral', - 'futures/contracts', - 'futures/ref-px', - 'futures/market-data', - 'futures/funding-rates', - ], - }, - 'accountCategory': { - 'get': [ - 'balance', - 'order/open', - 'order/status', - 'order/hist/current', - 'risk', - ], - 'post': [ - 'order', - 'order/batch', - ], - 'delete': [ - 'order', - 'order/all', - 'order/batch', - ], - }, - 'accountGroup': { - 'get': [ - 'cash/balance', - 'margin/balance', - 'margin/risk', - 'transfer', - 'futures/collateral-balance', - 'futures/position', - 'futures/risk', - 'futures/funding-payments', - 'order/hist', - ], - 'post': [ - 'futures/transfer/deposit', - 'futures/transfer/withdraw', - ], - }, - 'private': { - 'get': [ - 'info', - 'wallet/transactions', - 'wallet/deposit/address', // not documented - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'taker': 0.002, - 'maker': 0.002, - }, - }, - 'precisionMode': TICK_SIZE, - 'options': { - 'account-category': 'cash', // 'cash'/'margin'/'futures' - 'account-group': undefined, - 'fetchClosedOrders': { - 'method': 'accountGroupGetOrderHist', // 'accountGroupGetAccountCategoryOrderHistCurrent' - }, - }, - 'exceptions': { - 'exact': { - // not documented - '1900': BadRequest, // {"code":1900,"message":"Invalid Http Request Input"} - '2100': AuthenticationError, // {"code":2100,"message":"ApiKeyFailure"} - '5002': BadSymbol, // {"code":5002,"message":"Invalid Symbol"} - '6001': BadSymbol, // {"code":6001,"message":"Trading is disabled on symbol."} - '6010': InsufficientFunds, // {'code': 6010, 'message': 'Not enough balance.'} - '60060': InvalidOrder, // { 'code': 60060, 'message': 'The order is already filled or canceled.' } - '600503': InvalidOrder, // {"code":600503,"message":"Notional is too small."} - // documented - '100001': BadRequest, // INVALID_HTTP_INPUT Http request is invalid - '100002': BadRequest, // DATA_NOT_AVAILABLE Some required data is missing - '100003': BadRequest, // KEY_CONFLICT The same key exists already - '100004': BadRequest, // INVALID_REQUEST_DATA The HTTP request contains invalid field or argument - '100005': BadRequest, // INVALID_WS_REQUEST_DATA Websocket request contains invalid field or argument - '100006': BadRequest, // INVALID_ARGUMENT The arugment is invalid - '100007': BadRequest, // ENCRYPTION_ERROR Something wrong with data encryption - '100008': BadSymbol, // SYMBOL_ERROR Symbol does not exist or not valid for the request - '100009': AuthenticationError, // AUTHORIZATION_NEEDED Authorization is require for the API access or request - '100010': BadRequest, // INVALID_OPERATION The action is invalid or not allowed for the account - '100011': BadRequest, // INVALID_TIMESTAMP Not a valid timestamp - '100012': BadRequest, // INVALID_STR_FORMAT String format does not - '100013': BadRequest, // INVALID_NUM_FORMAT Invalid number input - '100101': ExchangeError, // UNKNOWN_ERROR Some unknown error - '150001': BadRequest, // INVALID_JSON_FORMAT Require a valid json object - '200001': AuthenticationError, // AUTHENTICATION_FAILED Authorization failed - '200002': ExchangeError, // TOO_MANY_ATTEMPTS Tried and failed too many times - '200003': ExchangeError, // ACCOUNT_NOT_FOUND Account not exist - '200004': ExchangeError, // ACCOUNT_NOT_SETUP Account not setup properly - '200005': ExchangeError, // ACCOUNT_ALREADY_EXIST Account already exist - '200006': ExchangeError, // ACCOUNT_ERROR Some error related with error - '200007': ExchangeError, // CODE_NOT_FOUND - '200008': ExchangeError, // CODE_EXPIRED Code expired - '200009': ExchangeError, // CODE_MISMATCH Code does not match - '200010': AuthenticationError, // PASSWORD_ERROR Wrong assword - '200011': ExchangeError, // CODE_GEN_FAILED Do not generate required code promptly - '200012': ExchangeError, // FAKE_COKE_VERIFY - '200013': ExchangeError, // SECURITY_ALERT Provide security alert message - '200014': PermissionDenied, // RESTRICTED_ACCOUNT Account is restricted for certain activity, such as trading, or withdraw. - '200015': PermissionDenied, // PERMISSION_DENIED No enough permission for the operation - '300001': InvalidOrder, // INVALID_PRICE Order price is invalid - '300002': InvalidOrder, // INVALID_QTY Order size is invalid - '300003': InvalidOrder, // INVALID_SIDE Order side is invalid - '300004': InvalidOrder, // INVALID_NOTIONAL Notional is too small or too large - '300005': InvalidOrder, // INVALID_TYPE Order typs is invalid - '300006': InvalidOrder, // INVALID_ORDER_ID Order id is invalid - '300007': InvalidOrder, // INVALID_TIME_IN_FORCE Time In Force in order request is invalid - '300008': InvalidOrder, // INVALID_ORDER_PARAMETER Some order parameter is invalid - '300009': InvalidOrder, // TRADING_VIOLATION Trading violation on account or asset - '300011': InsufficientFunds, // INVALID_BALANCE No enough account or asset balance for the trading - '300012': BadSymbol, // INVALID_PRODUCT Not a valid product supported by exchange - '300013': InvalidOrder, // INVALID_BATCH_ORDER Some or all orders are invalid in batch order request - '300020': InvalidOrder, // TRADING_RESTRICTED There is some trading restriction on account or asset - '300021': InvalidOrder, // TRADING_DISABLED Trading is disabled on account or asset - '300031': InvalidOrder, // NO_MARKET_PRICE No market price for market type order trading - '310001': InsufficientFunds, // INVALID_MARGIN_BALANCE No enough margin balance - '310002': InvalidOrder, // INVALID_MARGIN_ACCOUNT Not a valid account for margin trading - '310003': InvalidOrder, // MARGIN_TOO_RISKY Leverage is too high - '310004': BadSymbol, // INVALID_MARGIN_ASSET This asset does not support margin trading - '310005': InvalidOrder, // INVALID_REFERENCE_PRICE There is no valid reference price - '510001': ExchangeError, // SERVER_ERROR Something wrong with server. - '900001': ExchangeError, // HUMAN_CHALLENGE Human change do not pass - }, - 'broad': {}, - }, - 'commonCurrencies': { - 'BTCBEAR': 'BEAR', - 'BTCBULL': 'BULL', - }, - }); - } - - getAccount (params = {}) { - // get current or provided bitmax sub-account - const account = this.safeValue (params, 'account', this.options['account']); - return account.toLowerCase ().capitalize (); - } - - async fetchCurrencies (params = {}) { - const assets = await this.publicGetAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode" : "LTCBULL", - // "assetName" : "3X Long LTC Token", - // "precisionScale" : 9, - // "nativeScale" : 4, - // "withdrawalFee" : "0.2", - // "minWithdrawalAmt" : "1.0", - // "status" : "Normal" - // }, - // ] - // } - // - const margin = await this.publicGetMarginAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode":"BTT", - // "borrowAssetCode":"BTT-B", - // "interestAssetCode":"BTT-I", - // "nativeScale":0, - // "numConfirmations":1, - // "withdrawFee":"100.0", - // "minWithdrawalAmt":"1000.0", - // "statusCode":"Normal", - // "statusMessage":"", - // "interestRate":"0.001" - // } - // ] - // } - // - const cash = await this.publicGetCashAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode":"LTCBULL", - // "nativeScale":4, - // "numConfirmations":20, - // "withdrawFee":"0.2", - // "minWithdrawalAmt":"1.0", - // "statusCode":"Normal", - // "statusMessage":"" - // } - // ] - // } - // - const assetsData = this.safeValue (assets, 'data', []); - const marginData = this.safeValue (margin, 'data', []); - const cashData = this.safeValue (cash, 'data', []); - const assetsById = this.indexBy (assetsData, 'assetCode'); - const marginById = this.indexBy (marginData, 'assetCode'); - const cashById = this.indexBy (cashData, 'assetCode'); - const dataById = this.deepExtend (assetsById, marginById, cashById); - const ids = Object.keys (dataById); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const currency = dataById[id]; - const code = this.safeCurrencyCode (id); - const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); - // why would the exchange API have different names for the same field - const fee = this.safeFloat2 (currency, 'withdrawFee', 'withdrawalFee'); - const status = this.safeString2 (currency, 'status', 'statusCode'); - const active = (status === 'Normal'); - const margin = ('borrowAssetCode' in currency); - result[code] = { - 'id': id, - 'code': code, - 'info': currency, - 'type': undefined, - 'margin': margin, - 'name': this.safeString (currency, 'assetName'), - 'active': active, - 'fee': fee, - 'precision': precision, - 'limits': { - 'amount': { - 'min': Math.pow (10, -precision), - 'max': undefined, - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': undefined, - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawalAmt'), - 'max': undefined, - }, - }, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - const products = await this.publicGetProducts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"LBA/BTC", - // "baseAsset":"LBA", - // "quoteAsset":"BTC", - // "status":"Normal", - // "minNotional":"0.000625", - // "maxNotional":"6.25", - // "marginTradable":false, - // "commissionType":"Quote", - // "commissionReserveRate":"0.001", - // "tickSize":"0.000000001", - // "lotSize":"1" - // }, - // ] - // } - // - const cash = await this.publicGetCashProducts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"QTUM/BTC", - // "domain":"BTC", - // "tradingStartTime":1569506400000, - // "collapseDecimals":"0.0001,0.000001,0.00000001", - // "minQty":"0.000000001", - // "maxQty":"1000000000", - // "minNotional":"0.000625", - // "maxNotional":"12.5", - // "statusCode":"Normal", - // "statusMessage":"", - // "tickSize":"0.00000001", - // "useTick":false, - // "lotSize":"0.1", - // "useLot":false, - // "commissionType":"Quote", - // "commissionReserveRate":"0.001", - // "qtyScale":1, - // "priceScale":8, - // "notionalScale":4 - // } - // ] - // } - // - const futures = await this.publicGetFuturesContracts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"BTC-PERP", - // "tradingStartTime":1579701600000, - // "collapseDecimals":"1,0.1,0.01", - // "minQty":"0.000000001", - // "maxQty":"1000000000", - // "minNotional":"5", - // "maxNotional":"1000000", - // "statusCode":"Normal", - // "statusMessage":"", - // "tickSize":"0.25", - // "lotSize":"0.0001", - // "priceScale":2, - // "qtyScale":4, - // "notionalScale":2 - // } - // ] - // } - // - const productsData = this.safeValue (products, 'data', []); - const productsById = this.indexBy (productsData, 'symbol'); - const cashData = this.safeValue (cash, 'data', []); - const futuresData = this.safeValue (futures, 'data', []); - const cashAndFuturesData = this.arrayConcat (cashData, futuresData); - const cashAndFuturesById = this.indexBy (cashAndFuturesData, 'symbol'); - const dataById = this.deepExtend (productsById, cashAndFuturesById); - const ids = Object.keys (dataById); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const market = dataById[id]; - const baseId = this.safeString (market, 'baseAsset'); - const quoteId = this.safeString (market, 'quoteAsset'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), - }; - const status = this.safeString (market, 'status'); - const active = (status === 'Normal'); - const type = ('useLot' in market) ? 'spot' : 'future'; - const spot = (type === 'spot'); - const future = (type === 'future'); - let symbol = id; - if (!future) { - symbol = base + '/' + quote; - } - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'type': type, - 'spot': spot, - 'future': future, - 'active': active, - 'precision': precision, - 'limits': { - 'amount': { - 'min': this.safeFloat (market, 'minQty'), - 'max': this.safeFloat (market, 'maxQty'), - }, - 'price': { - 'min': this.safeFloat (market, 'tickSize'), - 'max': undefined, - }, - 'cost': { - 'min': this.safeFloat (market, 'minNotional'), - 'max': this.safeFloat (market, 'maxNotional'), - }, - }, - }); - } - return result; - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - // TODO: fee calculation here is incorrect, we need to support tiered fee calculation. - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - - async fetchAccounts (params = {}) { - let accountGroup = this.safeString (this.options, 'account-group'); - let response = undefined; - if (accountGroup === undefined) { - response = await this.privateGetInfo (params); - // - // { - // "code":0, - // "data":{ - // "email":"igor.kroitor@gmail.com", - // "accountGroup":8, - // "viewPermission":true, - // "tradePermission":true, - // "transferPermission":true, - // "cashAccount":["cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda"], - // "marginAccount":["martXoh1v1N3EMQC5FDtSj5VHso8aI2Z"], - // "futuresAccount":["futc9r7UmFJAyBY2rE3beA2JFxav2XFF"], - // "userUID":"U6491137460" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - accountGroup = this.safeString (data, 'accountGroup'); - this.options['account-group'] = accountGroup; - } - return [ - { - 'id': accountGroup, - 'type': undefined, - 'currency': undefined, - 'info': response, - }, - ]; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchBalance', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeString (account, 'id'); - const request = { - 'account-group': accountGroup, - }; - let method = 'accountCategoryGetBalance'; - if (accountCategory === 'futures') { - method = 'accountGroupGetFuturesCollateralBalance'; - } else { - request['account-category'] = accountCategory; - } - const response = await this[method] (this.extend (request, params)); - // - // cash - // - // { - // 'code': 0, - // 'data': [ - // { - // 'asset': 'BCHSV', - // 'totalBalance': '64.298000048', - // 'availableBalance': '64.298000048', - // }, - // ] - // } - // - // margin - // - // { - // 'code': 0, - // 'data': [ - // { - // 'asset': 'BCHSV', - // 'totalBalance': '64.298000048', - // 'availableBalance': '64.298000048', - // 'borrowed': '0', - // 'interest': '0', - // }, - // ] - // } - // - // futures - // - // { - // "code":0, - // "data":[ - // {"asset":"BTC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"9456.59"}, - // {"asset":"ETH","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"235.95"}, - // {"asset":"USDT","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"}, - // {"asset":"USDC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00035"}, - // {"asset":"PAX","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00045"}, - // {"asset":"USDTR","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"} - // ] - // } - // - const result = { 'info': response }; - const balances = this.safeValue (response, 'data', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - const response = await this.publicGetDepth (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "m":"depth-snapshot", - // "symbol":"BTC-PERP", - // "data":{ - // "ts":1590223998202, - // "seqnum":115444921, - // "asks":[ - // ["9207.5","18.2383"], - // ["9207.75","18.8235"], - // ["9208","10.7873"], - // ], - // "bids":[ - // ["9207.25","0.4009"], - // ["9207","0.003"], - // ["9206.5","0.003"], - // ] - // } - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const orderbook = this.safeValue (data, 'data', {}); - const timestamp = this.safeInteger (orderbook, 'ts'); - const result = this.parseOrderBook (orderbook, timestamp); - result['nonce'] = this.safeInteger (orderbook, 'seqnum'); - return result; - } - - parseTicker (ticker, market = undefined) { - // - // { - // "symbol":"QTUM/BTC", - // "open":"0.00016537", - // "close":"0.00019077", - // "high":"0.000192", - // "low":"0.00016537", - // "volume":"846.6", - // "ask":["0.00018698","26.2"], - // "bid":["0.00018408","503.7"], - // "type":"spot" - // } - // - const timestamp = undefined; - const marketId = this.safeString (ticker, 'symbol'); - let symbol = undefined; - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } else if (marketId !== undefined) { - const type = this.safeString (ticker, 'type'); - if (type === 'spot') { - const [ baseId, quoteId ] = marketId.split ('/'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - } - } - if ((symbol === undefined) && (market !== undefined)) { - symbol = market['symbol']; - } - const close = this.safeFloat (ticker, 'close'); - const bid = this.safeValue (ticker, 'bid', []); - const ask = this.safeValue (ticker, 'ask', []); - const open = this.safeFloat (ticker, 'open'); - let change = undefined; - let percentage = undefined; - let average = undefined; - if ((open !== undefined) && (close !== undefined)) { - change = close - open; - if (open > 0) { - percentage = change / open * 100; - } - average = this.sum (open, close) / 2; - } - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 0), - 'bidVolume': this.safeFloat (bid, 1), - 'ask': this.safeFloat (ask, 0), - 'askVolume': this.safeFloat (ask, 1), - 'vwap': undefined, - 'open': open, - 'close': close, - 'last': close, - 'previousClose': undefined, // previous day close - 'change': change, - 'percentage': percentage, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - const response = await this.publicGetTicker (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "symbol":"BTC-PERP", // or "BTC/USDT" - // "open":"9073", - // "close":"9185.75", - // "high":"9185.75", - // "low":"9185.75", - // "volume":"576.8334", - // "ask":["9185.75","15.5863"], - // "bid":["9185.5","0.003"], - // "type":"derivatives", // or "spot" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - return this.parseTicker (data, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const request = {}; - if (symbols !== undefined) { - const marketIds = this.marketIds (symbols); - request['symbol'] = marketIds.join (','); - } - const response = await this.publicGetTicker (this.extend (request, params)); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"QTUM/BTC", - // "open":"0.00016537", - // "close":"0.00019077", - // "high":"0.000192", - // "low":"0.00016537", - // "volume":"846.6", - // "ask":["0.00018698","26.2"], - // "bid":["0.00018408","503.7"], - // "type":"spot" - // } - // ] - // } - // - const data = this.safeValue (response, 'data', []); - return this.parseTickers (data, symbols); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "m":"bar", - // "s":"BTC/USDT", - // "data":{ - // "i":"1", - // "ts":1590228000000, - // "o":"9139.59", - // "c":"9131.94", - // "h":"9139.99", - // "l":"9121.71", - // "v":"25.20648" - // } - // } - // - const data = this.safeValue (ohlcv, 'data', {}); - return [ - this.safeInteger (data, 'ts'), - this.safeFloat (data, 'o'), - this.safeFloat (data, 'h'), - this.safeFloat (data, 'l'), - this.safeFloat (data, 'c'), - this.safeFloat (data, 'v'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - 'interval': this.timeframes[timeframe], - }; - // if since and limit are not specified - // the exchange will return just 1 last candle by default - const duration = this.parseTimeframe (timeframe); - const options = this.safeValue (this.options, 'fetchOHLCV', {}); - const defaultLimit = this.safeInteger (options, 'limit', 500); - if (since !== undefined) { - request['from'] = since; - if (limit === undefined) { - limit = defaultLimit; - } else { - limit = Math.min (limit, defaultLimit); - } - request['to'] = this.sum (since, limit * duration * 1000, 1); - } else if (limit !== undefined) { - request['n'] = limit; // max 500 - } - const response = await this.publicGetBarhist (this.extend (request, params)); - // - // { - // "code":0, - // "data":[ - // { - // "m":"bar", - // "s":"BTC/USDT", - // "data":{ - // "i":"1", - // "ts":1590228000000, - // "o":"9139.59", - // "c":"9131.94", - // "h":"9139.99", - // "l":"9121.71", - // "v":"25.20648" - // } - // } - // ] - // } - // - const data = this.safeValue (response, 'data', []); - return this.parseOHLCVs (data, market, timeframe, since, limit); - } - - parseTrade (trade, market = undefined) { - // - // public fetchTrades - // - // { - // "p":"9128.5", // price - // "q":"0.0030", // quantity - // "ts":1590229002385, // timestamp - // "bm":false, // if true, the buyer is the market maker, we only use this field to "define the side" of a public trade - // "seqnum":180143985289898554 - // } - // - const timestamp = this.safeInteger (trade, 'ts'); - const price = this.safeFloat2 (trade, 'price', 'p'); - const amount = this.safeFloat (trade, 'q'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } - const buyerIsMaker = this.safeValue (trade, 'bm', false); - const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; - const side = buyerIsMaker ? 'buy' : 'sell'; - let symbol = undefined; - if ((symbol === undefined) && (market !== undefined)) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'id': undefined, - 'order': undefined, - 'type': undefined, - 'takerOrMaker': makerOrTaker, - 'side': side, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - if (limit !== undefined) { - request['n'] = limit; // max 100 - } - const response = await this.publicGetTrades (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "m":"trades", - // "symbol":"BTC-PERP", - // "data":[ - // {"p":"9128.5","q":"0.0030","ts":1590229002385,"bm":false,"seqnum":180143985289898554}, - // {"p":"9129","q":"0.0030","ts":1590229002642,"bm":false,"seqnum":180143985289898587}, - // {"p":"9129.5","q":"0.0030","ts":1590229021306,"bm":false,"seqnum":180143985289899043} - // ] - // } - // } - // - const records = this.safeValue (response, 'data', []); - const trades = this.safeValue (records, 'data', []); - return this.parseTrades (trades, market, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'PendingNew': 'open', - 'New': 'open', - 'PartiallyFilled': 'open', - 'Filled': 'closed', - 'Canceled': 'canceled', - 'Rejected': 'rejected', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - // - // createOrder - // - // { - // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", - // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", - // "orderType": "Market", - // "symbol": "BTC/USDT", - // "timestamp": 1573576916201 - // } - // - // fetchOrder, fetchOpenOrders, fetchClosedOrders - // - // { - // "symbol": "BTC/USDT", - // "price": "8131.22", - // "orderQty": "0.00082", - // "orderType": "Market", - // "avgPx": "7392.02", - // "cumFee": "0.005152238", - // "cumFilledQty": "0.00082", - // "errorCode": "", - // "feeAsset": "USDT", - // "lastExecTime": 1575953151764, - // "orderId": "a16eee20b6750866943712zWEDdAjt3", - // "seqNum": 2623469, - // "side": "Buy", - // "status": "Filled", - // "stopPrice": "", - // "execInst": "NULL_VAL" - // } - // - // { - // "ac": "FUTURES", - // "accountId": "testabcdefg", - // "avgPx": "0", - // "cumFee": "0", - // "cumQty": "0", - // "errorCode": "NULL_VAL", - // "execInst": "NULL_VAL", - // "feeAsset": "USDT", - // "lastExecTime": 1584072844085, - // "orderId": "r170d21956dd5450276356bbtcpKa74", - // "orderQty": "1.1499", - // "orderType": "Limit", - // "price": "4000", - // "sendingTime": 1584072841033, - // "seqNum": 24105338, - // "side": "Buy", - // "status": "Canceled", - // "stopPrice": "", - // "symbol": "BTC-PERP" - // }, - // - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'symbol'); - const symbol = this.safeSymbol (marketId, market, '/'); - let timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); - let lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const average = this.safeFloat (order, 'avgPx'); - const filled = this.safeFloat2 (order, 'cumFilledQty', 'cumQty'); - let remaining = undefined; - if (filled !== undefined) { - if (filled === 0) { - timestamp = lastTradeTimestamp; - lastTradeTimestamp = undefined; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - let cost = undefined; - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - const id = this.safeString (order, 'orderId'); - let clientOrderId = this.safeString (order, 'id'); - if (clientOrderId !== undefined) { - if (clientOrderId.length < 1) { - clientOrderId = undefined; - } - } - const type = this.safeStringLower (order, 'orderType'); - const side = this.safeStringLower (order, 'side'); - const feeCost = this.safeFloat (order, 'cumFee'); - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (order, 'feeAsset'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': stopPrice, - 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, - 'remaining': remaining, - 'status': status, - 'fee': fee, - 'trades': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const market = this.market (symbol); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'createOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'symbol': market['id'], - 'time': this.milliseconds (), - 'orderQty': this.amountToPrecision (symbol, amount), - 'orderType': type, // "limit", "market", "stop_market", "stop_limit" - 'side': side, // "buy" or "sell" - // 'orderPrice': this.priceToPrecision (symbol, price), - // 'stopPrice': this.priceToPrecision (symbol, stopPrice), // required for stop orders - // 'postOnly': 'false', // 'false', 'true' - // 'timeInForce': 'GTC', // GTC, IOC, FOK - // 'respInst': 'ACK', // ACK, 'ACCEPT, DONE - }; - if (clientOrderId !== undefined) { - request['id'] = clientOrderId; - params = this.omit (params, [ 'clientOrderId', 'id' ]); - } - if ((type === 'limit') || (type === 'stop_limit')) { - request['orderPrice'] = this.priceToPrecision (symbol, price); - } - if ((type === 'stop_limit') || (type === 'stop_market')) { - const stopPrice = this.safeFloat (params, 'stopPrice'); - if (stopPrice === undefined) { - throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); - } else { - request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); - params = this.omit (params, 'stopPrice'); - } - } - const response = await this.accountCategoryPostOrder (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "ac": "MARGIN", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "action": "place-order", - // "info": { - // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", - // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", - // "orderType": "Market", - // "symbol": "BTC/USDT", - // "timestamp": 1573576916201 - // }, - // "status": "Ack" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const info = this.safeValue (data, 'info', {}); - return this.parseOrder (info, market); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'orderId': id, - }; - const response = await this.accountCategoryGetOrderStatus (this.extend (request, params)); - // - // { - // "code": 0, - // "accountCategory": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "data": [ - // { - // "symbol": "BTC/USDT", - // "price": "8131.22", - // "orderQty": "0.00082", - // "orderType": "Market", - // "avgPx": "7392.02", - // "cumFee": "0.005152238", - // "cumFilledQty": "0.00082", - // "errorCode": "", - // "feeAsset": "USDT", - // "lastExecTime": 1575953151764, - // "orderId": "a16eee20b6750866943712zWEDdAjt3", - // "seqNum": 2623469, - // "side": "Buy", - // "status": "Filled", - // "stopPrice": "", - // "execInst": "NULL_VAL" - // } - // ] - // } - // - const data = this.safeValue (response, 'data', {}); - return this.parseOrder (data); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchOpenOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - }; - const response = await this.accountCategoryGetOrderOpen (this.extend (request, params)); - // - // { - // "ac": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "code": 0, - // "data": [ - // { - // "avgPx": "0", // Average filled price of the order - // "cumFee": "0", // cumulative fee paid for this order - // "cumFilledQty": "0", // cumulative filled quantity - // "errorCode": "", // error code; could be empty - // "feeAsset": "USDT", // fee asset - // "lastExecTime": 1576019723550, // The last execution time of the order - // "orderId": "s16ef21882ea0866943712034f36d83", // server provided orderId - // "orderQty": "0.0083", // order quantity - // "orderType": "Limit", // order type - // "price": "7105", // order price - // "seqNum": 8193258, // sequence number - // "side": "Buy", // order side - // "status": "New", // order status on matching engine - // "stopPrice": "", // only available for stop market and stop limit orders; otherwise empty - // "symbol": "BTC/USDT", - // "execInst": "NULL_VAL" // execution instruction - // }, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - if (accountCategory === 'futures') { - return this.parseOrders (data, market, since, limit); - } - // a workaround for https://github.com/ccxt/ccxt/issues/7187 - const orders = []; - for (let i = 0; i < data.length; i++) { - const order = this.parseOrder (data[i], market); - orders.push (order); - } - return this.filterBySymbolSinceLimit (orders, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - const defaultAccountCategory = this.safeString (this.options, 'account-category'); - const options = this.safeValue (this.options, 'fetchClosedOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - // 'category': accountCategory, - // 'symbol': market['id'], - // 'orderType': 'market', // optional, string - // 'side': 'buy', // or 'sell', optional, case insensitive. - // 'status': 'Filled', // "Filled", "Canceled", or "Rejected" - // 'startTime': exchange.milliseconds (), - // 'endTime': exchange.milliseconds (), - // 'page': 1, - // 'pageSize': 100, - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['symbol'] = market['id']; - } - const method = this.safeValue (options, 'method', 'accountGroupGetOrderHist'); - if (method === 'accountGroupGetOrderHist') { - if (accountCategory !== undefined) { - request['category'] = accountCategory; - } - } else { - request['account-category'] = accountCategory; - } - if (since !== undefined) { - request['startTime'] = since; - } - if (limit !== undefined) { - request['pageSize'] = limit; - } - const response = await this[method] (this.extend (request, params)); - // - // accountCategoryGetOrderHistCurrent - // - // { - // "code":0, - // "accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda", - // "ac":"CASH", - // "data":[ - // { - // "seqNum":15561826728, - // "orderId":"a17294d305c0U6491137460bethu7kw9", - // "symbol":"ETH/USDT", - // "orderType":"Limit", - // "lastExecTime":1591635618200, - // "price":"200", - // "orderQty":"0.1", - // "side":"Buy", - // "status":"Canceled", - // "avgPx":"0", - // "cumFilledQty":"0", - // "stopPrice":"", - // "errorCode":"", - // "cumFee":"0", - // "feeAsset":"USDT", - // "execInst":"NULL_VAL" - // } - // ] - // } - // - // accountGroupGetOrderHist - // - // { - // "code": 0, - // "data": { - // "data": [ - // { - // "ac": "FUTURES", - // "accountId": "testabcdefg", - // "avgPx": "0", - // "cumFee": "0", - // "cumQty": "0", - // "errorCode": "NULL_VAL", - // "execInst": "NULL_VAL", - // "feeAsset": "USDT", - // "lastExecTime": 1584072844085, - // "orderId": "r170d21956dd5450276356bbtcpKa74", - // "orderQty": "1.1499", - // "orderType": "Limit", - // "price": "4000", - // "sendingTime": 1584072841033, - // "seqNum": 24105338, - // "side": "Buy", - // "status": "Canceled", - // "stopPrice": "", - // "symbol": "BTC-PERP" - // }, - // ], - // "hasNext": False, - // "limit": 500, - // "page": 1, - // "pageSize": 20 - // } - // } - // - let data = this.safeValue (response, 'data'); - const isArray = Array.isArray (data); - if (!isArray) { - data = this.safeValue (data, 'data', []); - } - return this.parseOrders (data, market, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument'); - } - await this.loadMarkets (); - await this.loadAccounts (); - const market = this.market (symbol); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'cancelOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'symbol': market['id'], - 'time': this.milliseconds (), - 'id': 'foobar', - }; - if (clientOrderId === undefined) { - request['orderId'] = id; - } else { - request['id'] = clientOrderId; - params = this.omit (params, [ 'clientOrderId', 'id' ]); - } - const response = await this.accountCategoryDeleteOrder (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "ac": "CASH", - // "action": "cancel-order", - // "status": "Ack", - // "info": { - // "id": "wv8QGquoeamhssvQBeHOHGQCGlcBjj23", - // "orderId": "16e6198afb4s8bXHbAwwoqDo2ebc19dc", - // "orderType": "", // could be empty - // "symbol": "ETH/USDT", - // "timestamp": 1573594877822 - // } - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const info = this.safeValue (data, 'info', {}); - return this.parseOrder (info, market); - } - - async cancelAllOrders (symbol = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'cancelAllOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'time': this.milliseconds (), - }; - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - request['symbol'] = market['id']; - } - const response = await this.accountCategoryDeleteOrderAll (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "ac": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "action": "cancel-all", - // "info": { - // "id": "2bmYvi7lyTrneMzpcJcf2D7Pe9V1P9wy", - // "orderId": "", - // "orderType": "NULL_VAL", - // "symbol": "", - // "timestamp": 1574118495462 - // }, - // "status": "Ack" - // } - // } - // - return response; - } - - parseDepositAddress (depositAddress, currency = undefined) { - // - // { - // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // destTag: "", - // tagType: "", - // tagId: "", - // chainName: "ERC20", - // numConfirmations: 20, - // withdrawalFee: 1, - // nativeScale: 4, - // tips: [] - // } - // - const address = this.safeString (depositAddress, 'address'); - const tagId = this.safeString (depositAddress, 'tagId'); - const tag = this.safeString (depositAddress, tagId); - this.checkAddress (address); - const code = (currency === undefined) ? undefined : currency['code']; - return { - 'currency': code, - 'address': address, - 'tag': tag, - 'info': depositAddress, - }; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const chainName = this.safeString (params, 'chainName'); - params = this.omit (params, 'chainName'); - const request = { - 'asset': currency['id'], - }; - const response = await this.privateGetWalletDepositAddress (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "asset":"USDT", - // "assetName":"Tether", - // "address":[ - // { - // "address":"1N22odLHXnLPCjC8kwBJPTayarr9RtPod6", - // "destTag":"", - // "tagType":"", - // "tagId":"", - // "chainName":"Omni", - // "numConfirmations":3, - // "withdrawalFee":4.7, - // "nativeScale":4, - // "tips":[] - // }, - // { - // "address":"0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // "destTag":"", - // "tagType":"", - // "tagId":"", - // "chainName":"ERC20", - // "numConfirmations":20, - // "withdrawalFee":1.0, - // "nativeScale":4, - // "tips":[] - // } - // ] - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const addresses = this.safeValue (data, 'address', []); - const numAddresses = addresses.length; - let address = undefined; - if (numAddresses > 1) { - const addressesByChainName = this.indexBy (addresses, 'chainName'); - if (chainName === undefined) { - const chainNames = Object.keys (addressesByChainName); - const chains = chainNames.join (', '); - throw new ArgumentsRequired (this.id + ' fetchDepositAddress returned more than one address, a chainName parameter is required, one of ' + chains); - } - address = this.safeValue (addressesByChainName, chainName, {}); - } else { - // first address - address = this.safeValue (addresses, 0, {}); - } - const result = this.parseDepositAddress (address, currency); - return this.extend (result, { - 'info': response, - }); - } - - async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { - const request = { - 'txType': 'deposit', - }; - return await this.fetchTransactions (code, since, limit, this.extend (request, params)); - } - - async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) { - const request = { - 'txType': 'withdrawal', - }; - return await this.fetchTransactions (code, since, limit, this.extend (request, params)); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'asset': currency['id'], - // 'page': 1, - // 'pageSize': 20, - // 'startTs': this.milliseconds (), - // 'endTs': this.milliseconds (), - // 'txType': undefned, // deposit, withdrawal - }; - let currency = undefined; - if (code !== undefined) { - currency = this.currency (code); - request['asset'] = currency['id']; - } - if (since !== undefined) { - request['startTs'] = since; - } - if (limit !== undefined) { - request['pageSize'] = limit; - } - const response = await this.privateGetWalletTransactions (this.extend (request, params)); - // - // { - // code: 0, - // data: { - // data: [ - // { - // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", - // time: 1591606166000, - // asset: "USDT", - // transactionType: "deposit", - // amount: "25", - // commission: "0", - // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", - // status: "pending", - // numConfirmed: 8, - // numConfirmations: 20, - // destAddress: { address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722" } - // } - // ], - // page: 1, - // pageSize: 20, - // hasNext: false - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const transactions = this.safeValue (data, 'data', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - 'reviewing': 'pending', - 'pending': 'pending', - 'confirmed': 'ok', - 'rejected': 'rejected', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", - // time: 1591606166000, - // asset: "USDT", - // transactionType: "deposit", - // amount: "25", - // commission: "0", - // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", - // status: "pending", - // numConfirmed: 8, - // numConfirmations: 20, - // destAddress: { - // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // destTag: "..." // for currencies that have it - // } - // } - // - const id = this.safeString (transaction, 'requestId'); - const amount = this.safeFloat (transaction, 'amount'); - const destAddress = this.safeValue (transaction, 'destAddress', {}); - const address = this.safeString (destAddress, 'address'); - const tag = this.safeString (destAddress, 'destTag'); - const txid = this.safeString (transaction, 'networkTransactionId'); - const type = this.safeString (transaction, 'transactionType'); - const timestamp = this.safeInteger (transaction, 'time'); - const currencyId = this.safeString (transaction, 'asset'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'commission'); - return { - 'info': transaction, - 'id': id, - 'currency': code, - 'amount': amount, - 'address': address, - 'addressTo': address, - 'addressFrom': undefined, - 'tag': tag, - 'tagTo': tag, - 'tagFrom': undefined, - 'status': status, - 'type': type, - 'updated': undefined, - 'txid': txid, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'fee': { - 'currency': code, - 'cost': feeCost, - }, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = ''; - let query = params; - const accountCategory = (api === 'accountCategory'); - if (accountCategory || (api === 'accountGroup')) { - url += this.implodeParams ('/{account-group}', params); - query = this.omit (params, 'account-group'); - } - const request = this.implodeParams (path, query); - url += '/api/pro/' + this.version; - if (accountCategory) { - url += this.implodeParams ('/{account-category}', query); - query = this.omit (query, 'account-category'); - } - url += '/' + request; - query = this.omit (query, this.extractParams (path)); - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const timestamp = this.milliseconds ().toString (); - const payload = timestamp + '+' + request; - const hmac = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); - headers = { - 'x-auth-key': this.apiKey, - 'x-auth-timestamp': timestamp, - 'x-auth-signature': hmac, - }; - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - headers['Content-Type'] = 'application/json'; - body = this.json (query); - } - } - url = this.urls['api'] + url; - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - // - // {'code': 6010, 'message': 'Not enough balance.'} - // {'code': 60060, 'message': 'The order is already filled or canceled.'} - // {"code":2100,"message":"ApiKeyFailure"} - // {"code":300001,"message":"Price is too low from market price.","reason":"INVALID_PRICE","accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda","ac":"CASH","action":"place-order","status":"Err","info":{"symbol":"BTC/USDT"}} - // - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'message'); - const error = (code !== undefined) && (code !== '0'); - if (error || (message !== undefined)) { - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],38:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],38:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -26373,6 +26421,7 @@ module.exports = class bitmax extends Exchange { const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, BadRequest, DDoSProtection, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -26583,8 +26632,8 @@ module.exports = class bitmex extends Exchange { 'amount': undefined, 'price': undefined, }; - const lotSize = this.safeFloat (market, 'lotSize'); - const tickSize = this.safeFloat (market, 'tickSize'); + const lotSize = this.safeNumber (market, 'lotSize'); + const tickSize = this.safeNumber (market, 'tickSize'); if (lotSize !== undefined) { precision['amount'] = lotSize; } @@ -26598,7 +26647,7 @@ module.exports = class bitmex extends Exchange { }, 'price': { 'min': tickSize, - 'max': this.safeFloat (market, 'maxPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { 'min': undefined, @@ -26608,7 +26657,7 @@ module.exports = class bitmex extends Exchange { const limitField = (position === quote) ? 'cost' : 'amount'; limits[limitField] = { 'min': lotSize, - 'max': this.safeFloat (market, 'maxOrderQty'), + 'max': this.safeNumber (market, 'maxOrderQty'), }; result.push ({ 'id': id, @@ -26620,8 +26669,8 @@ module.exports = class bitmex extends Exchange { 'active': active, 'precision': precision, 'limits': limits, - 'taker': this.safeFloat (market, 'takerFee'), - 'maker': this.safeFloat (market, 'makerFee'), + 'taker': this.safeNumber (market, 'takerFee'), + 'maker': this.safeNumber (market, 'makerFee'), 'type': type, 'spot': false, 'swap': swap, @@ -26687,21 +26736,17 @@ module.exports = class bitmex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - let free = this.safeFloat (balance, 'availableMargin'); - let total = this.safeFloat (balance, 'marginBalance'); + let free = this.safeString (balance, 'availableMargin'); + let total = this.safeString (balance, 'marginBalance'); if (code === 'BTC') { - if (free !== undefined) { - free /= 100000000; - } - if (total !== undefined) { - total /= 100000000; - } + free = Precise.stringDiv (free, '1e8'); + total = Precise.stringDiv (total, '1e8'); } account['free'] = free; account['total'] = total; result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -26780,8 +26825,8 @@ module.exports = class bitmex extends Exchange { for (let i = 0; i < response.length; i++) { const order = response[i]; const side = (order['side'] === 'Sell') ? 'asks' : 'bids'; - const amount = this.safeFloat (order, 'size'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const price = this.safeNumber (order, 'price'); // https://github.com/ccxt/ccxt/issues/4926 // https://github.com/ccxt/ccxt/issues/4927 // the exchange sometimes returns null price in the orderbook @@ -26987,7 +27032,7 @@ module.exports = class bitmex extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'transactType')); const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount !== undefined) { amount = amount / 100000000; } @@ -26998,7 +27043,7 @@ module.exports = class bitmex extends Exchange { // for unrealized pnl and other transactions without a timestamp timestamp = 0; // see comments above } - let feeCost = this.safeFloat (item, 'fee', 0); + let feeCost = this.safeNumber (item, 'fee', 0); if (feeCost !== undefined) { feeCost = feeCost / 100000000; } @@ -27006,7 +27051,7 @@ module.exports = class bitmex extends Exchange { 'cost': feeCost, 'currency': code, }; - let after = this.safeFloat (item, 'walletBalance'); + let after = this.safeNumber (item, 'walletBalance'); if (after !== undefined) { after = after / 100000000; } @@ -27325,8 +27370,8 @@ module.exports = class bitmex extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const open = this.safeFloat (ticker, 'prevPrice24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'prevPrice24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; if (last !== undefined && open !== undefined) { @@ -27339,13 +27384,13 @@ module.exports = class bitmex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askPrice'), + 'ask': this.safeNumber (ticker, 'askPrice'), 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'vwap'), + 'vwap': this.safeNumber (ticker, 'vwap'), 'open': open, 'close': last, 'last': last, @@ -27353,8 +27398,8 @@ module.exports = class bitmex extends Exchange { 'change': change, 'percentage': percentage, 'average': this.sum (open, last) / 2, - 'baseVolume': this.safeFloat (ticker, 'homeNotional24h'), - 'quoteVolume': this.safeFloat (ticker, 'foreignNotional24h'), + 'baseVolume': this.safeNumber (ticker, 'homeNotional24h'), + 'quoteVolume': this.safeNumber (ticker, 'foreignNotional24h'), 'info': ticker, }; } @@ -27379,11 +27424,11 @@ module.exports = class bitmex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -27512,23 +27557,23 @@ module.exports = class bitmex extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat2 (trade, 'avgPx', 'price'); - const amount = this.safeFloat2 (trade, 'size', 'lastQty'); + const price = this.safeNumber2 (trade, 'avgPx', 'price'); + const amount = this.safeNumber2 (trade, 'size', 'lastQty'); const id = this.safeString (trade, 'trdMatchID'); const order = this.safeString (trade, 'orderID'); const side = this.safeStringLower (trade, 'side'); // price * amount doesn't work for all symbols (e.g. XBT, ETH) - let cost = this.safeFloat (trade, 'execCost'); + let cost = this.safeNumber (trade, 'execCost'); if (cost !== undefined) { cost = Math.abs (cost) / 100000000; } let fee = undefined; if ('execComm' in trade) { - let feeCost = this.safeFloat (trade, 'execComm'); + let feeCost = this.safeNumber (trade, 'execComm'); feeCost = feeCost / 100000000; const currencyId = this.safeString (trade, 'settlCurrency'); const feeCurrency = this.safeCurrencyCode (currencyId); - const feeRate = this.safeFloat (trade, 'commission'); + const feeRate = this.safeNumber (trade, 'commission'); fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -27630,33 +27675,19 @@ module.exports = class bitmex extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'transactTime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty', 0.0); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (amount - filled, 0.0); - } - } - const average = this.safeFloat (order, 'avgPx'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = average * filled; - } else if (price !== undefined) { - cost = price * filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty', 0.0); + const average = this.safeNumber (order, 'avgPx'); const id = this.safeString (order, 'orderID'); const type = this.safeStringLower (order, 'ordType'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'clOrdID'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'ParticipateDoNotInitiate'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -27671,14 +27702,14 @@ module.exports = class bitmex extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { @@ -27739,7 +27770,7 @@ module.exports = class bitmex extends Exchange { 'ordType': orderType, }; if ((orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched')) { - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPx or stopPrice parameter for the ' + orderType + ' order type'); } else { @@ -27856,7 +27887,7 @@ module.exports = class bitmex extends Exchange { return this.parseOrders (response, market); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPosition (params); // [ @@ -28051,7 +28082,7 @@ module.exports = class bitmex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],39:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],39:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -28382,7 +28413,7 @@ module.exports = class bitpanda extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; @@ -28455,9 +28486,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -28504,8 +28535,8 @@ module.exports = class bitpanda extends Exchange { const activeFeeTier = this.safeValue (response, 'active_fee_tier', {}); const result = { 'info': response, - 'maker': this.safeFloat (activeFeeTier, 'maker_fee'), - 'taker': this.safeFloat (activeFeeTier, 'taker_fee'), + 'maker': this.safeNumber (activeFeeTier, 'maker_fee'), + 'taker': this.safeNumber (activeFeeTier, 'taker_fee'), 'percentage': true, 'tierBased': true, }; @@ -28514,9 +28545,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -28554,27 +28585,27 @@ module.exports = class bitpanda extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last_price'); - const percentage = this.safeFloat (ticker, 'price_change_percentage'); - const change = this.safeFloat (ticker, 'price_change'); + const last = this.safeNumber (ticker, 'last_price'); + const percentage = this.safeNumber (ticker, 'price_change_percentage'); + const change = this.safeNumber (ticker, 'price_change'); let open = undefined; let average = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'best_bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -28759,11 +28790,11 @@ module.exports = class bitpanda extends Exchange { const volumeField = this.safeString (options, 'volume', 'total_amount'); return [ alignedTimestamp, - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -28849,21 +28880,21 @@ module.exports = class bitpanda extends Exchange { timestamp = this.parse8601 (this.safeString (trade, 'time')); } const side = this.safeStringLower2 (trade, 'side', 'taker_side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + let cost = this.safeNumber (trade, 'volume'); if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { cost = amount * price; } const marketId = this.safeString (trade, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (feeInfo, 'fee_amount'); + const feeCost = this.safeNumber (feeInfo, 'fee_amount'); let takerOrMaker = undefined; let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (feeInfo, 'fee_percentage'); + const feeRate = this.safeNumber (feeInfo, 'fee_percentage'); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, @@ -28946,11 +28977,11 @@ module.exports = class bitpanda extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -29204,12 +29235,12 @@ module.exports = class bitpanda extends Exchange { // } // const id = this.safeString (transaction, 'transaction_id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const currencyId = this.safeString (transaction, 'currency'); currency = this.safeCurrency (currencyId, currency); const status = 'ok'; // the exchange returns cleared transactions only - const feeCost = this.safeFloat2 (transaction, 'fee_amount', 'fee'); + const feeCost = this.safeNumber2 (transaction, 'fee_amount', 'fee'); let fee = undefined; const addressTo = this.safeString (transaction, 'recipient'); const tagTo = this.safeString (transaction, 'destination_tag'); @@ -29324,72 +29355,34 @@ module.exports = class bitpanda extends Exchange { // ] // } // - const rawTrades = this.safeValue (order, 'trades', []); - order = this.safeValue (order, 'order', order); - const id = this.safeString (order, 'order_id'); - const clientOrderId = this.safeString (order, 'client_id'); - const timestamp = this.parse8601 (this.safeString (order, 'time')); - let status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'instrument_code'); + const rawOrder = this.safeValue (order, 'order', order); + const id = this.safeString (rawOrder, 'order_id'); + const clientOrderId = this.safeString (rawOrder, 'client_id'); + const timestamp = this.parse8601 (this.safeString (rawOrder, 'time')); + const rawStatus = this.parseOrderStatus (this.safeString (rawOrder, 'status')); + const status = this.parseOrderStatus (rawStatus); + const marketId = this.safeString (rawOrder, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - if (status === undefined) { - if (remaining > 0) { - status = 'open'; - } else { - status = 'closed'; - } - } - } - } - const side = this.safeStringLower (order, 'side'); - const type = this.safeStringLower (order, 'type'); - const trades = this.parseTrades (rawTrades, market, undefined, undefined); - const fees = []; - const numTrades = trades.length; - let lastTradeTimestamp = undefined; - let tradeCost = undefined; - let tradeAmount = undefined; - if (numTrades > 0) { - lastTradeTimestamp = trades[0]['timestamp']; - tradeCost = 0; - tradeAmount = 0; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - fees.push (trade['fee']); - lastTradeTimestamp = Math.max (lastTradeTimestamp, trade['timestamp']); - tradeCost = this.sum (tradeCost, trade['cost']); - tradeAmount = this.sum (tradeAmount, trade['amount']); - } - } - let average = this.safeFloat (order, 'average_price'); - if (average === undefined) { - if ((tradeCost !== undefined) && (tradeAmount !== undefined) && (tradeAmount !== 0)) { - average = tradeCost / tradeAmount; - } - } - if (cost === undefined) { - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - } - const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'trigger_price'); - const postOnly = this.safeValue (order, 'is_post_only'); - const result = { + const price = this.safeNumber (rawOrder, 'price'); + const amount = this.safeNumber (rawOrder, 'amount'); + const filledString = this.safeString (rawOrder, 'filled_amount'); + const filled = this.parseNumber (filledString); + const side = this.safeStringLower (rawOrder, 'side'); + const type = this.safeStringLower (rawOrder, 'type'); + const timeInForce = this.parseTimeInForce (this.safeString (rawOrder, 'time_in_force')); + const stopPrice = this.safeNumber (rawOrder, 'trigger_price'); + const postOnly = this.safeValue (rawOrder, 'is_post_only'); + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'type': type, + }); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -29398,41 +29391,14 @@ module.exports = class bitpanda extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, // 'fee': undefined, 'trades': trades, - }; - const numFees = fees.length; - if (numFees > 0) { - if (numFees === 1) { - result['fee'] = fees[0]; - } else { - const feesByCurrency = this.groupBy (fees, 'currency'); - const feeCurrencies = Object.keys (feesByCurrency); - const numFeesByCurrency = feeCurrencies.length; - if (numFeesByCurrency === 1) { - const feeCurrency = feeCurrencies[0]; - const feeArray = this.safeValue (feesByCurrency, feeCurrency); - let feeCost = 0; - for (let i = 0; i < feeArray.length; i++) { - feeCost = this.sum (feeCost, feeArray[i]['cost']); - } - result['fee'] = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } else { - result['fees'] = fees; - } - } - } else { - result['fee'] = undefined; - } - return result; + }); } parseTimeInForce (timeInForce) { @@ -29466,7 +29432,7 @@ module.exports = class bitpanda extends Exchange { priceIsRequired = true; } if (uppercaseType === 'STOP') { - const triggerPrice = this.safeFloat (params, 'trigger_price'); + const triggerPrice = this.safeNumber (params, 'trigger_price'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a trigger_price param for ' + type + ' orders'); } @@ -29869,7 +29835,7 @@ module.exports = class bitpanda extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],40:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],40:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -30029,28 +29995,28 @@ module.exports = class bitso extends Exchange { const symbol = base + '/' + quote; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), - 'max': this.safeFloat (market, 'maximum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), + 'max': this.safeNumber (market, 'maximum_amount'), }, 'price': { - 'min': this.safeFloat (market, 'minimum_price'), - 'max': this.safeFloat (market, 'maximum_price'), + 'min': this.safeNumber (market, 'minimum_price'), + 'max': this.safeNumber (market, 'maximum_price'), }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), - 'max': this.safeFloat (market, 'maximum_value'), + 'min': this.safeNumber (market, 'minimum_value'), + 'max': this.safeNumber (market, 'maximum_value'), }, }; - const defaultPricePrecision = this.safeFloat (this.options['precision'], quote, this.options['defaultPrecision']); - const pricePrecision = this.safeFloat (market, 'tick_size', defaultPricePrecision); + const defaultPricePrecision = this.safeNumber (this.options['precision'], quote, this.options['defaultPrecision']); + const pricePrecision = this.safeNumber (market, 'tick_size', defaultPricePrecision); const precision = { - 'amount': this.safeFloat (this.options['precision'], base, this.options['defaultPrecision']), + 'amount': this.safeNumber (this.options['precision'], base, this.options['defaultPrecision']), 'price': pricePrecision, }; const fees = this.safeValue (market, 'fees', {}); const flatRate = this.safeValue (fees, 'flat_rate', {}); - const maker = this.safeFloat (flatRate, 'maker'); - const taker = this.safeFloat (flatRate, 'taker'); + const maker = this.safeNumber (flatRate, 'maker'); + const taker = this.safeNumber (flatRate, 'taker'); const feeTiers = this.safeValue (fees, 'structure', []); const fee = { 'taker': parseFloat (this.decimalToPrecision (taker / 100, ROUND, 0.00000001, TICK_SIZE)), @@ -30062,9 +30028,9 @@ module.exports = class bitso extends Exchange { const makerFees = []; for (let j = 0; j < feeTiers.length; j++) { const tier = feeTiers[j]; - const volume = this.safeFloat (tier, 'volume'); - const takerFee = this.safeFloat (tier, 'taker'); - const makerFee = this.safeFloat (tier, 'maker'); + const volume = this.safeNumber (tier, 'volume'); + const takerFee = this.safeNumber (tier, 'taker'); + const makerFee = this.safeNumber (tier, 'maker'); const takerFeeToPrecision = parseFloat (this.decimalToPrecision (takerFee / 100, ROUND, 0.00000001, TICK_SIZE)); const makerFeeToPrecision = parseFloat (this.decimalToPrecision (makerFee / 100, ROUND, 0.00000001, TICK_SIZE)); takerFees.push ([ volume, takerFeeToPrecision ]); @@ -30104,14 +30070,13 @@ module.exports = class bitso extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'locked'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -30133,22 +30098,22 @@ module.exports = class bitso extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'payload'); const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -30169,12 +30134,12 @@ module.exports = class bitso extends Exchange { const marketId = this.safeString (trade, 'book'); const symbol = this.safeSymbol (marketId, market, '_'); const side = this.safeString2 (trade, 'side', 'maker_side'); - let amount = this.safeFloat2 (trade, 'amount', 'major'); + let amount = this.safeNumber2 (trade, 'amount', 'major'); if (amount !== undefined) { amount = Math.abs (amount); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fees_amount'); + const feeCost = this.safeNumber (trade, 'fees_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fees_currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -30183,11 +30148,11 @@ module.exports = class bitso extends Exchange { 'currency': feeCurrency, }; } - let cost = this.safeFloat (trade, 'minor'); + let cost = this.safeNumber (trade, 'minor'); if (cost !== undefined) { cost = Math.abs (cost); } - const price = this.safeFloat (trade, 'price'); + const price = this.safeNumber (trade, 'price'); const orderId = this.safeString (trade, 'oid'); const id = this.safeString (trade, 'tid'); return { @@ -30288,17 +30253,11 @@ module.exports = class bitso extends Exchange { const symbol = this.safeSymbol (marketId, market, '_'); const orderType = this.safeString (order, 'type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'unfilled_amount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'unfilled_amount'); const clientOrderId = this.safeString (order, 'client_id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -30315,12 +30274,12 @@ module.exports = class bitso extends Exchange { 'amount': amount, 'cost': undefined, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = 25, params = {}) { @@ -30496,7 +30455,7 @@ module.exports = class bitso extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],41:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],41:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -30614,6 +30573,16 @@ module.exports = class bitstamp extends Exchange { 'usdc_address/', 'omg_withdrawal/', 'omg_address/', + 'dai_withdrawal/', + 'dai_address/', + 'knc_withdrawal/', + 'knc_address/', + 'mkr_withdrawal/', + 'mkr_address/', + 'zrx_withdrawal/', + 'zrx_address/', + 'gusd_withdrawal/', + 'gusd_address/', 'transfer-to-main/', 'transfer-from-main/', 'withdrawal-requests/', @@ -30748,13 +30717,15 @@ module.exports = class bitstamp extends Exchange { const symbolId = baseId + '_' + quoteId; const id = this.safeString (market, 'url_symbol'); const precision = { - 'amount': market['base_decimals'], - 'price': market['counter_decimals'], + 'amount': this.safeInteger (market, 'base_decimals'), + 'price': this.safeInteger (market, 'counter_decimals'), }; - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; // let [ cost, currency ] = market['minimum_order'].split (' '); - const active = (market['trading'] === 'Enabled'); + const trading = this.safeString (market, 'trading'); + const active = (trading === 'Enabled'); result.push ({ 'id': id, 'symbol': symbol, @@ -30798,7 +30769,7 @@ module.exports = class bitstamp extends Exchange { 'type': currencyType, 'name': name, 'active': true, - 'fee': this.safeFloat (description['fees']['funding']['withdraw'], code), + 'fee': this.safeNumber (description['fees']['funding']['withdraw'], code), 'precision': precision, 'limits': { 'amount': { @@ -30851,13 +30822,16 @@ module.exports = class bitstamp extends Exchange { quote = this.safeCurrencyCode (quote); const description = this.safeString (market, 'description'); const [ baseDescription, quoteDescription ] = description.split (' / '); - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; if (!(base in result)) { - result[base] = this.constructCurrencyObject (baseId, base, baseDescription, market['base_decimals'], undefined, market); + const baseDecimals = this.safeInteger (market, 'base_decimals'); + result[base] = this.constructCurrencyObject (baseId, base, baseDescription, baseDecimals, undefined, market); } if (!(quote in result)) { - result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, market['counter_decimals'], parseFloat (cost), market); + const counterDecimals = this.safeInteger (market, 'counter_decimals'); + result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, counterDecimals, parseFloat (cost), market); } } return result; @@ -30899,25 +30873,25 @@ module.exports = class bitstamp extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -30960,7 +30934,7 @@ module.exports = class bitstamp extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; if (id.indexOf ('_') < 0) { - const value = this.safeFloat (transaction, id); + const value = this.safeNumber (transaction, id); if ((value !== undefined) && (value !== 0)) { return id; } @@ -31042,11 +31016,11 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString2 (trade, 'id', 'tid'); let symbol = undefined; let side = undefined; - let price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat (trade, 'amount'); + let price = this.safeNumber (trade, 'price'); + let amount = this.safeNumber (trade, 'amount'); const orderId = this.safeString (trade, 'order_id'); const type = undefined; - let cost = this.safeFloat (trade, 'cost'); + let cost = this.safeNumber (trade, 'cost'); if (market === undefined) { const keys = Object.keys (trade); for (let i = 0; i < keys.length; i++) { @@ -31063,12 +31037,12 @@ module.exports = class bitstamp extends Exchange { market = this.getMarketFromTrade (trade); } } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = undefined; if (market !== undefined) { - price = this.safeFloat (trade, market['symbolId'], price); - amount = this.safeFloat (trade, market['baseId'], amount); - cost = this.safeFloat (trade, market['quoteId'], cost); + price = this.safeNumber (trade, market['symbolId'], price); + amount = this.safeNumber (trade, market['baseId'], amount); + cost = this.safeNumber (trade, market['quoteId'], cost); feeCurrency = market['quote']; symbol = market['symbol']; } @@ -31137,7 +31111,7 @@ module.exports = class bitstamp extends Exchange { parseTradingFee (balances, symbol) { const market = this.market (symbol); - const tradeFee = this.safeFloat (balances, market['id'] + '_fee'); + const tradeFee = this.safeNumber (balances, market['id'] + '_fee'); return { 'symbol': symbol, 'maker': tradeFee, @@ -31187,11 +31161,11 @@ module.exports = class bitstamp extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -31249,12 +31223,12 @@ module.exports = class bitstamp extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -31301,7 +31275,7 @@ module.exports = class bitstamp extends Exchange { if (id.indexOf ('_withdrawal_fee') >= 0) { const currencyId = id.split ('_')[0]; const code = this.safeCurrencyCode (currencyId); - withdraw[code] = this.safeFloat (balance, id); + withdraw[code] = this.safeNumber (balance, id); } } return { @@ -31547,16 +31521,16 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString (transaction, 'id'); const currencyId = this.getCurrencyIdFromTransaction (transaction); const code = this.safeCurrencyCode (currencyId, currency); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let feeCurrency = undefined; let amount = undefined; if ('amount' in transaction) { - amount = this.safeFloat (transaction, 'amount'); + amount = this.safeNumber (transaction, 'amount'); } else if (currency !== undefined) { - amount = this.safeFloat (transaction, currency['id'], amount); + amount = this.safeNumber (transaction, currency['id'], amount); feeCurrency = currency['code']; } else if ((code !== undefined) && (currencyId !== undefined)) { - amount = this.safeFloat (transaction, currencyId, amount); + amount = this.safeNumber (transaction, currencyId, amount); feeCurrency = code; } if (amount !== undefined) { @@ -31681,83 +31655,23 @@ module.exports = class bitstamp extends Exchange { } // there is no timestamp from fetchOrder const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - let lastTradeTimestamp = undefined; - let symbol = undefined; - let marketId = this.safeStringLower (order, 'currency_pair'); - if (marketId !== undefined) { - marketId = marketId.replace ('/', ''); - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - symbol = market['symbol']; - } - } - let amount = this.safeFloat (order, 'amount'); - let filled = 0.0; - const trades = []; - const transactions = this.safeValue (order, 'transactions', []); - let feeCost = undefined; - let cost = undefined; - const numTransactions = transactions.length; - if (numTransactions > 0) { - feeCost = 0.0; - for (let i = 0; i < numTransactions; i++) { - const trade = this.parseTrade (this.extend ({ - 'order_id': id, - 'side': side, - }, transactions[i]), market); - filled = this.sum (filled, trade['amount']); - feeCost = this.sum (feeCost, trade['fee']['cost']); - if (cost === undefined) { - cost = 0.0; - } - cost = this.sum (cost, trade['cost']); - trades.push (trade); - } - lastTradeTimestamp = trades[numTransactions - 1]['timestamp']; - } + const marketId = this.safeStringLower (order, 'currency_pair'); + let symbol = this.safeSymbol (marketId, market, '/'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((status === 'closed') && (amount === undefined)) { - amount = filled; + const amount = this.safeNumber (order, 'amount'); + const transactions = this.safeValue (order, 'transactions', []); + const trades = this.parseTrades (transactions, market); + const length = trades.length; + if (length) { + symbol = trades[0]['symbol']; } - let remaining = undefined; - if (amount !== undefined) { - remaining = amount - filled; - } - let price = this.safeFloat (order, 'price'); - if (market === undefined) { - market = this.getMarketFromTrades (trades); - } - let feeCurrency = undefined; - if (market !== undefined) { - if (symbol === undefined) { - symbol = market['symbol']; - } - feeCurrency = market['quote']; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if (price === undefined) { - if (filled > 0) { - price = cost / filled; - } - } - let fee = undefined; - if (feeCost !== undefined) { - if (feeCurrency !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { + const price = this.safeNumber (order, 'price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': undefined, @@ -31766,15 +31680,15 @@ module.exports = class bitstamp extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, - 'filled': filled, - 'remaining': remaining, + 'filled': undefined, + 'remaining': undefined, 'trades': trades, - 'fee': fee, + 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } parseLedgerEntryType (type) { @@ -31854,11 +31768,11 @@ module.exports = class bitstamp extends Exchange { const parsedTransaction = this.parseTransaction (item); let direction = undefined; if ('amount' in item) { - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); direction = amount > 0 ? 'in' : 'out'; } else if (('currency' in parsedTransaction) && parsedTransaction['currency'] !== undefined) { const currencyId = this.currencyId (parsedTransaction['currency']); - const amount = this.safeFloat (item, currencyId); + const amount = this.safeNumber (item, currencyId); direction = amount > 0 ? 'in' : 'out'; } return { @@ -32105,13 +32019,14 @@ module.exports = class bitstamp extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],42:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],42:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -32208,25 +32123,25 @@ module.exports = class bitstamp1 extends Exchange { await this.loadMarkets (); const ticker = await this.publicGetTicker (params); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -32249,14 +32164,11 @@ module.exports = class bitstamp1 extends Exchange { } } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -32300,12 +32212,12 @@ module.exports = class bitstamp1 extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -32406,7 +32318,7 @@ module.exports = class bitstamp1 extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],43:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],43:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -32414,6 +32326,7 @@ module.exports = class bitstamp1 extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, DDoSProtection, PermissionDenied, AddressPending, OnMaintenance, BadRequest, InvalidAddress } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -32689,7 +32602,7 @@ module.exports = class bittrex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeSize'), + 'min': this.safeNumber (market, 'minTradeSize'), 'max': undefined, }, 'price': { @@ -32717,11 +32630,11 @@ module.exports = class bittrex extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); const balance = indexed[currencyId]; - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -32781,7 +32694,7 @@ module.exports = class bittrex extends Exchange { const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); const precision = 8; // default precision, todo: fix "magic constants" - const fee = this.safeFloat (currency, 'txFee'); // todo: redesign + const fee = this.safeNumber (currency, 'txFee'); // todo: redesign const isActive = this.safeString (currency, 'status'); result[code] = { 'id': id, @@ -32842,17 +32755,17 @@ module.exports = class bittrex extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'updatedAt')); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const percentage = this.safeFloat (ticker, 'percentChange'); - const last = this.safeFloat (ticker, 'lastTradeRate'); + const percentage = this.safeNumber (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'lastTradeRate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidRate'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidRate'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askRate'), + 'ask': this.safeNumber (ticker, 'askRate'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -32862,8 +32775,8 @@ module.exports = class bittrex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -32976,21 +32889,18 @@ module.exports = class bittrex extends Exchange { const order = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'marketSymbol'); market = this.safeMarket (marketId, market, '-'); - let cost = undefined; - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'quantity'); - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = undefined; const isTaker = this.safeValue (trade, 'isTaker'); if (isTaker !== undefined) { takerOrMaker = isTaker ? 'taker' : 'maker'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -33060,11 +32970,11 @@ module.exports = class bittrex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'startsAt')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -33171,9 +33081,9 @@ module.exports = class bittrex extends Exchange { let cost = undefined; if (isCeilingLimit) { request['limit'] = this.priceToPrecision (symbol, price); - cost = this.safeFloat2 (params, 'ceiling', 'cost', amount); + cost = this.safeNumber2 (params, 'ceiling', 'cost', amount); } else if (isCeilingMarket) { - cost = this.safeFloat2 (params, 'ceiling', 'cost'); + cost = this.safeNumber2 (params, 'ceiling', 'cost'); if (cost === undefined) { if (price === undefined) { cost = amount; @@ -33332,7 +33242,7 @@ module.exports = class bittrex extends Exchange { // } // const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const address = this.safeString (transaction, 'cryptoAddress'); const txid = this.safeString (transaction, 'txId'); const updated = this.parse8601 (this.safeString (transaction, 'updatedAt')); @@ -33368,7 +33278,7 @@ module.exports = class bittrex extends Exchange { status = 'ok'; } } - let feeCost = this.safeFloat (transaction, 'txCost'); + let feeCost = this.safeNumber (transaction, 'txCost'); if (feeCost === undefined) { if (type === 'deposit') { // according to https://support.bittrex.com/hc/en-us/articles/115000199651-What-fees-does-Bittrex-charge- @@ -33425,15 +33335,9 @@ module.exports = class bittrex extends Exchange { // } // const marketSymbol = this.safeString (order, 'marketSymbol'); - let symbol = undefined; - let feeCurrency = undefined; - if (marketSymbol !== undefined) { - const [ baseId, quoteId ] = marketSymbol.split ('-'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - feeCurrency = quote; - } + market = this.safeMarket (marketSymbol, market, '-'); + const symbol = market['symbol']; + const feeCurrency = market['quote']; const direction = this.safeStringLower (order, 'direction'); const createdAt = this.safeString (order, 'createdAt'); const updatedAt = this.safeString (order, 'updatedAt'); @@ -33446,32 +33350,15 @@ module.exports = class bittrex extends Exchange { } const timestamp = this.parse8601 (createdAt); const type = this.safeStringLower (order, 'type'); - const quantity = this.safeFloat (order, 'quantity'); - const limit = this.safeFloat (order, 'limit'); - const fillQuantity = this.safeFloat (order, 'fillQuantity'); - const commission = this.safeFloat (order, 'commission'); - const proceeds = this.safeFloat (order, 'proceeds'); - let average = undefined; - let remaining = undefined; - if (fillQuantity !== undefined) { - if (proceeds !== undefined) { - if (fillQuantity > 0) { - average = proceeds / fillQuantity; - } else if (proceeds === 0) { - average = 0; - } - } - if (quantity !== undefined) { - remaining = quantity - fillQuantity; - } - } - let status = this.safeStringLower (order, 'status'); - if ((status === 'closed') && (remaining !== undefined) && (remaining > 0)) { - status = 'canceled'; - } + const quantity = this.safeNumber (order, 'quantity'); + const limit = this.safeNumber (order, 'limit'); + const fillQuantity = this.safeNumber (order, 'fillQuantity'); + const commission = this.safeNumber (order, 'commission'); + const proceeds = this.safeNumber (order, 'proceeds'); + const status = this.safeStringLower (order, 'status'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'timestamp': timestamp, @@ -33485,10 +33372,10 @@ module.exports = class bittrex extends Exchange { 'price': limit, 'stopPrice': undefined, 'cost': proceeds, - 'average': average, + 'average': undefined, 'amount': quantity, 'filled': fillQuantity, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': { 'cost': commission, @@ -33496,7 +33383,7 @@ module.exports = class bittrex extends Exchange { }, 'info': order, 'trades': undefined, - }; + }); } parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { @@ -33545,9 +33432,9 @@ module.exports = class bittrex extends Exchange { 'side': this.safeString (order, 'side'), 'order': this.safeString (order, 'id'), 'type': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'average'), - 'amount': this.safeFloat (order, 'filled'), - 'cost': this.safeFloat (order, 'cost'), + 'price': this.safeNumber (order, 'average'), + 'amount': this.safeNumber (order, 'filled'), + 'cost': this.safeNumber (order, 'cost'), 'symbol': this.safeString (order, 'symbol'), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -33839,7 +33726,7 @@ module.exports = class bittrex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],44:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],44:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -33847,6 +33734,7 @@ module.exports = class bittrex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, BadSymbol, AuthenticationError, InsufficientFunds, InvalidOrder, ArgumentsRequired, OrderNotFound, InvalidAddress, BadRequest, RateLimitExceeded, PermissionDenied, ExchangeNotAvailable, AccountSuspended, OnMaintenance } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -34148,7 +34036,7 @@ module.exports = class bitvavo extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minOrderInBaseAsset'), + 'min': this.safeNumber (market, 'minOrderInBaseAsset'), 'max': undefined, }, 'price': { @@ -34156,7 +34044,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderInQuoteAsset'), + 'min': this.safeNumber (market, 'minOrderInQuoteAsset'), 'max': undefined, }, }, @@ -34219,7 +34107,7 @@ module.exports = class bitvavo extends Exchange { 'code': code, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -34235,7 +34123,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMinAmount'), + 'min': this.safeNumber (currency, 'withdrawalMinAmount'), 'max': undefined, }, }, @@ -34292,14 +34180,14 @@ module.exports = class bitvavo extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); + const last = this.safeNumber (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -34311,12 +34199,12 @@ module.exports = class bitvavo extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': vwap, 'open': open, 'close': last, @@ -34332,14 +34220,6 @@ module.exports = class bitvavo extends Exchange { return result; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24h (params); @@ -34453,12 +34333,11 @@ module.exports = class bitvavo extends Exchange { // feeCurrency: 'EUR' // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'side'); const id = this.safeString2 (trade, 'id', 'fillId'); @@ -34469,7 +34348,7 @@ module.exports = class bitvavo extends Exchange { if (taker !== undefined) { takerOrMaker = taker ? 'taker' : 'maker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); @@ -34540,11 +34419,11 @@ module.exports = class bitvavo extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -34592,13 +34471,12 @@ module.exports = class bitvavo extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'inOrder'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'inOrder'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDepositAddress (code, params = {}) { @@ -34648,7 +34526,7 @@ module.exports = class bitvavo extends Exchange { if (price !== undefined) { cost = amount * price; } else { - cost = this.safeFloat2 (params, 'cost', 'amountQuote'); + cost = this.safeNumber2 (params, 'cost', 'amountQuote'); } if (cost !== undefined) { const precision = market['precision']['price']; @@ -34661,7 +34539,7 @@ module.exports = class bitvavo extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['amount'] = this.amountToPrecision (symbol, amount); } else if (isStopMarket || isStopLimit) { - let stopPrice = this.safeFloat2 (params, 'stopPrice', 'triggerAmount'); + let stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerAmount'); if (stopPrice === undefined) { if (isStopLimit) { throw new ArgumentsRequired (this.id + ' createOrder requires a stopPrice parameter for a ' + type + ' order'); @@ -34723,7 +34601,7 @@ module.exports = class bitvavo extends Exchange { await this.loadMarkets (); const market = this.market (symbol); let request = {}; - const amountRemaining = this.safeFloat (params, 'amountRemaining'); + const amountRemaining = this.safeNumber (params, 'amountRemaining'); params = this.omit (params, 'amountRemaining'); if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); @@ -34788,7 +34666,6 @@ module.exports = class bitvavo extends Exchange { throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument'); } await this.loadMarkets (); - await this.loadMarkets (); const market = this.market (symbol); const request = { 'orderId': id, @@ -35014,26 +34891,13 @@ module.exports = class bitvavo extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let remaining = this.safeFloat (order, 'amountRemaining'); - let filled = this.safeFloat (order, 'filledAmount'); - const remainingCost = this.safeFloat (order, 'remainingCost'); - if ((remainingCost !== undefined) && (remainingCost === 0.0)) { - remaining = 0; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - const cost = this.safeFloat (order, 'filledAmountQuote'); - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amountRemaining'); + const filled = this.safeNumber (order, 'filledAmount'); + const cost = this.safeNumber (order, 'filledAmountQuote'); let fee = undefined; - const feeCost = this.safeFloat (order, 'feePaid'); + const feeCost = this.safeNumber (order, 'feePaid'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -35042,32 +34906,24 @@ module.exports = class bitvavo extends Exchange { 'currency': feeCurrencyCode, }; } - let lastTradeTimestamp = undefined; - const rawTrades = this.safeValue (order, 'fills'); - let trades = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'symbol': symbol, - 'order': id, - 'side': side, - }); - const numTrades = trades.length; - if (numTrades > 0) { - const lastTrade = this.safeValue (trades, numTrades - 1); - lastTradeTimestamp = lastTrade['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'symbol': symbol, + 'order': id, + 'side': side, + 'type': type, + }); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = this.safeValue (order, 'postOnly'); // https://github.com/ccxt/ccxt/issues/8489 - const stopPrice = this.safeFloat (order, 'triggerPrice'); - return { + const stopPrice = this.safeNumber (order, 'triggerPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -35077,13 +34933,13 @@ module.exports = class bitvavo extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -35278,11 +35134,11 @@ module.exports = class bitvavo extends Exchange { const currencyId = this.safeString (transaction, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -35373,7 +35229,7 @@ module.exports = class bitvavo extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],45:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],45:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -35435,7 +35291,7 @@ module.exports = class bitz extends Exchange { 'assets': 'https://{hostname}', }, 'www': 'https://www.bitz.com', - 'doc': 'https://apidoc.bitz.com/en/', + 'doc': 'https://apidocv2.bitz.plus/en/', 'fees': 'https://www.bitz.com/fee?type=1', 'referral': 'https://u.bitz.com/register?invite_code=1429193', }, @@ -35452,6 +35308,11 @@ module.exports = class bitz extends Exchange { 'currencyRate', 'currencyCoinRate', 'coinRate', + 'getContractCoin', + 'getContractKline', + 'getContractOrderBook', + 'getContractTradesHistory', + 'getContractTickers', ], }, 'trade': { @@ -35464,6 +35325,10 @@ module.exports = class bitz extends Exchange { 'getUserNowEntrustSheet', // open orders 'getEntrustSheetInfo', // order 'depositOrWithdraw', // transactions + 'getCoinAddress', + 'getCoinAddressList', + 'marketTrade', + 'addEntrustSheetBatch', ], }, 'assets': { @@ -35471,6 +35336,20 @@ module.exports = class bitz extends Exchange { 'getUserAssets', ], }, + 'contract': { + 'post': [ + 'addContractTrade', + 'cancelContractTrade', + 'getContractActivePositions', + 'getContractAccountInfo', + 'getContractMyPositions', + 'getContractOrderResult', + 'getContractTradeResult', + 'getContractOrder', + 'getContractMyHistoryTrade', + 'getContractMyTrades', + ], + }, }, 'fees': { 'trading': { @@ -35657,8 +35536,8 @@ module.exports = class bitz extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTrade'), - 'max': this.safeFloat (market, 'maxTrade'), + 'min': this.safeNumber (market, 'minTrade'), + 'max': this.safeNumber (market, 'maxTrade'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -35707,12 +35586,12 @@ module.exports = class bitz extends Exchange { const currencyId = this.safeString (balance, 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lock'); - account['total'] = this.safeFloat (balance, 'num'); - account['free'] = this.safeFloat (balance, 'over'); + account['used'] = this.safeString (balance, 'lock'); + account['total'] = this.safeString (balance, 'num'); + account['free'] = this.safeString (balance, 'over'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTicker (ticker, market = undefined) { @@ -35742,8 +35621,8 @@ module.exports = class bitz extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'now'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'now'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -35754,22 +35633,22 @@ module.exports = class bitz extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': undefined, 'open': open, 'close': last, 'last': last, 'previousClose': undefined, 'change': change, - 'percentage': this.safeFloat (ticker, 'priceChange24h'), + 'percentage': this.safeNumber (ticker, 'priceChange24h'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -35959,8 +35838,8 @@ module.exports = class bitz extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'p'); - const amount = this.safeFloat (trade, 'n'); + const price = this.safeNumber (trade, 'p'); + const amount = this.safeNumber (trade, 'n'); let cost = undefined; if (price !== undefined) { if (amount !== undefined) { @@ -36028,11 +35907,11 @@ module.exports = class bitz extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -36130,22 +36009,17 @@ module.exports = class bitz extends Exchange { if (side !== undefined) { side = (side === 'sale') ? 'sell' : 'buy'; } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'number'); - const remaining = this.safeFloat (order, 'numberOver'); - const filled = this.safeFloat (order, 'numberDeal'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'number'); + const remaining = this.safeNumber (order, 'numberOver'); + const filled = this.safeNumber (order, 'numberDeal'); let timestamp = this.safeInteger (order, 'timestamp'); if (timestamp === undefined) { timestamp = this.safeTimestamp (order, 'created'); } - let cost = this.safeFloat (order, 'orderTotalPrice'); - if (price !== undefined) { - if (filled !== undefined) { - cost = filled * price; - } - } + const cost = this.safeNumber (order, 'orderTotalPrice'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -36167,7 +36041,7 @@ module.exports = class bitz extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -36494,7 +36368,7 @@ module.exports = class bitz extends Exchange { const type = this.safeStringLower (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'network_fee'); + const feeCost = this.safeNumber (transaction, 'network_fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -36509,7 +36383,7 @@ module.exports = class bitz extends Exchange { 'address': this.safeString (transaction, 'wallet'), 'tag': this.safeString (transaction, 'memo'), 'type': type, - 'amount': this.safeFloat (transaction, 'number'), + 'amount': this.safeNumber (transaction, 'number'), 'currency': code, 'status': status, 'updated': timestamp, @@ -36661,12 +36535,13 @@ module.exports = class bitz extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],46:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],46:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -36745,17 +36620,19 @@ module.exports = class bl3p extends Exchange { const available = this.safeValue (wallet, 'available', {}); const balance = this.safeValue (wallet, 'balance', {}); const account = this.account (); - account['free'] = this.safeFloat (available, 'value'); - account['total'] = this.safeFloat (balance, 'value'); + account['free'] = this.safeString (available, 'value'); + account['total'] = this.safeString (balance, 'value'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { + const price = this.safeNumber (bidask, priceKey); + const size = this.safeNumber (bidask, amountKey); return [ - bidask[priceKey] / 100000.0, - bidask[amountKey] / 100000000.0, + price / 100000.0, + size / 100000000.0, ]; } @@ -36775,16 +36652,16 @@ module.exports = class bl3p extends Exchange { }; const ticker = await this.publicGetMarketTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -36794,7 +36671,7 @@ module.exports = class bl3p extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker['volume'], '24h'), + 'baseVolume': this.safeNumber (ticker['volume'], '24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -36803,20 +36680,13 @@ module.exports = class bl3p extends Exchange { parseTrade (trade, market = undefined) { const id = this.safeString (trade, 'trade_id'); const timestamp = this.safeInteger (trade, 'date'); - let price = this.safeFloat (trade, 'price_int'); - if (price !== undefined) { - price /= 100000.0; - } - let amount = this.safeFloat (trade, 'amount_int'); - if (amount !== undefined) { - amount /= 100000000.0; - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + let priceString = this.safeString (trade, 'price_int'); + priceString = Precise.stringDiv (priceString, '100000'); + let amountString = this.safeString (trade, 'amount_int'); + amountString = Precise.stringDiv (amountString, '100000000'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -36899,7 +36769,7 @@ module.exports = class bl3p extends Exchange { } }; -},{"./base/Exchange":6}],47:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],47:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -37065,8 +36935,8 @@ module.exports = class bleutrade extends Exchange { 'code': code, 'name': this.safeString (item, 'AssetLong'), 'active': this.safeValue (item, 'IsActive') && !this.safeValue (item, 'MaintenanceMode'), - 'fee': this.safeFloat (item, 'WithdrawTxFee'), - 'precision': this.safeFloat (item, 'DecimalPlaces'), + 'fee': this.safeNumber (item, 'WithdrawTxFee'), + 'precision': this.safeNumber (item, 'DecimalPlaces'), 'info': item, 'limits': this.limits, }; @@ -37118,7 +36988,7 @@ module.exports = class bleutrade extends Exchange { 'taker': this.fees['trading']['taker'], 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinTradeSize'), + 'min': this.safeNumber (market, 'MinTradeSize'), 'max': undefined, }, 'price': { @@ -37194,8 +37064,8 @@ module.exports = class bleutrade extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'TimeStamp')); const marketId = this.safeString (ticker, 'MarketName'); const symbol = this.safeSymbol (marketId, market, '_'); - const previous = this.safeFloat (ticker, 'PrevDay'); - const last = this.safeFloat (ticker, 'Last'); + const previous = this.safeNumber (ticker, 'PrevDay'); + const last = this.safeNumber (ticker, 'Last'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -37210,11 +37080,11 @@ module.exports = class bleutrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'High'), - 'low': this.safeFloat (ticker, 'Low'), - 'bid': this.safeFloat (ticker, 'Bid'), + 'high': this.safeNumber (ticker, 'High'), + 'low': this.safeNumber (ticker, 'Low'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': previous, @@ -37224,8 +37094,8 @@ module.exports = class bleutrade extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume'), - 'quoteVolume': this.safeFloat (ticker, 'BaseVolume'), + 'baseVolume': this.safeNumber (ticker, 'Volume'), + 'quoteVolume': this.safeNumber (ticker, 'BaseVolume'), 'info': ticker, }; } @@ -37233,11 +37103,11 @@ module.exports = class bleutrade extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (ohlcv['TimeStamp'] + '+00:00'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -37313,11 +37183,11 @@ module.exports = class bleutrade extends Exchange { const currencyId = this.safeString (item, 'Asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (item, 'Available'); - account['total'] = this.safeFloat (item, 'Balance'); + account['free'] = this.safeString (item, 'Available'); + account['total'] = this.safeString (item, 'Balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -37460,7 +37330,7 @@ module.exports = class bleutrade extends Exchange { // } const timestamp = this.parse8601 (this.safeString (item, 'TimeStamp')); - let amount = this.safeFloat (item, 'Amount'); + let amount = this.safeNumber (item, 'Amount'); let direction = undefined; if (amount !== undefined) { direction = 'in'; @@ -37534,27 +37404,12 @@ module.exports = class bleutrade extends Exchange { if ('Created' in order) { timestamp = this.parse8601 (order['Created'] + '+00:00'); } - let price = this.safeFloat (order, 'Price'); - let cost = undefined; - const amount = this.safeFloat (order, 'Quantity'); - const remaining = this.safeFloat (order, 'QuantityRemaining'); - let filled = undefined; - if (amount !== undefined && remaining !== undefined) { - filled = amount - remaining; - } - if (!cost) { - if (price && filled) { - cost = price * filled; - } - } - if (!price) { - if (cost && filled) { - price = cost / filled; - } - } - const average = this.safeFloat (order, 'PricePerUnit'); + const price = this.safeNumber (order, 'Price'); + const amount = this.safeNumber (order, 'Quantity'); + const remaining = this.safeNumber (order, 'QuantityRemaining'); + const average = this.safeNumber (order, 'PricePerUnit'); const id = this.safeString (order, 'OrderID'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -37568,15 +37423,15 @@ module.exports = class bleutrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -37613,7 +37468,7 @@ module.exports = class bleutrade extends Exchange { // Symbol: 'BTC' } // const id = this.safeString (transaction, 'ID'); - let amount = this.safeFloat (transaction, 'Amount'); + let amount = this.safeNumber (transaction, 'Amount'); let type = 'deposit'; if (amount < 0) { amount = Math.abs (amount); @@ -37715,13 +37570,14 @@ module.exports = class bleutrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],48:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],48:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -37902,11 +37758,11 @@ module.exports = class braziliex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': this.safeFloat (currency, 'txWithdrawalFee'), + 'fee': this.safeNumber (currency, 'txWithdrawalFee'), }, 'deposit': { 'active': canDeposit, - 'fee': this.safeFloat (currency, 'txDepositFee'), + 'fee': this.safeNumber (currency, 'txDepositFee'), }, }, 'limits': { @@ -37923,11 +37779,11 @@ module.exports = class braziliex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'MinWithdrawal'), + 'min': this.safeNumber (currency, 'MinWithdrawal'), 'max': Math.pow (10, precision), }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, }, @@ -37975,9 +37831,9 @@ module.exports = class braziliex extends Exchange { const quoteIsFiat = this.safeInteger (quoteCurrency, 'is_fiat', 0); let minCost = undefined; if (quoteIsFiat) { - minCost = this.safeFloat (baseCurrency, 'minAmountTradeFIAT'); + minCost = this.safeNumber (baseCurrency, 'minAmountTradeFIAT'); } else { - minCost = this.safeFloat (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); + minCost = this.safeNumber (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); } const isActive = this.safeInteger (market, 'active'); const active = (isActive === 1); @@ -38020,27 +37876,27 @@ module.exports = class braziliex extends Exchange { symbol = market['symbol']; } const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highestBid24'), - 'low': this.safeFloat (ticker, 'lowestAsk24'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'highestBid24'), + 'low': this.safeNumber (ticker, 'lowestAsk24'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'percentChange'), + 'change': this.safeNumber (ticker, 'percentChange'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume24'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume24'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24'), 'info': ticker, }; } @@ -38080,13 +37936,18 @@ module.exports = class braziliex extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString2 (trade, 'date_exec', 'date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } - const cost = this.safeFloat (trade, 'total'); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_number'); const type = 'limit'; const side = this.safeString (trade, 'type'); @@ -38128,11 +37989,11 @@ module.exports = class braziliex extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -38154,21 +38015,16 @@ module.exports = class braziliex extends Exchange { if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'date')); } - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'total', 0.0); - const amount = this.safeFloat (order, 'amount'); - const filledPercentage = this.safeFloat (order, 'progress'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'total'); + const amount = this.safeNumber (order, 'amount'); + const filledPercentage = this.safeNumber (order, 'progress'); const filled = amount * filledPercentage; - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); - let info = order; - if ('info' in info) { - info = order['info']; - } const id = this.safeString (order, 'order_number'); const fee = this.safeValue (order, 'fee'); // propagated from createOrder const status = (filledPercentage === 1.0) ? 'closed' : 'open'; const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -38185,12 +38041,12 @@ module.exports = class braziliex extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, - 'info': info, + 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -38242,7 +38098,7 @@ module.exports = class braziliex extends Exchange { 'price': this.safeString (priceParts, 1), 'total': this.safeString (totalParts, 1), 'fee': { - 'cost': this.safeFloat (feeParts, 1), + 'cost': this.safeNumber (feeParts, 1), 'currency': this.safeString (feeParts, 2), }, 'progress': '0.0', @@ -38359,13 +38215,14 @@ module.exports = class braziliex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],49:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],49:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -38507,8 +38364,8 @@ module.exports = class btcalpha extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -38560,14 +38417,11 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'id', 'tid'); const side = this.safeString2 (trade, 'my_side', 'side'); const orderId = this.safeString (trade, 'o_id'); @@ -38616,11 +38470,11 @@ module.exports = class btcalpha extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -38657,11 +38511,11 @@ module.exports = class btcalpha extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'reserve'); - account['total'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserve'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -38682,8 +38536,8 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (order, 'date'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString2 (order, 'oid', 'id'); let trades = this.safeValue (order, 'trades', []); @@ -38864,13 +38718,14 @@ module.exports = class btcalpha extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],50:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],50:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, InvalidOrder, AuthenticationError, PermissionDenied, InvalidNonce, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -38955,12 +38810,12 @@ module.exports = class btcbox extends Exchange { if (free in response) { const account = this.account (); const used = currencyId + '_lock'; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -38981,16 +38836,16 @@ module.exports = class btcbox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -39000,8 +38855,8 @@ module.exports = class btcbox extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -39025,14 +38880,11 @@ module.exports = class btcbox extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeString (trade, 'type'); return { @@ -39132,15 +38984,15 @@ module.exports = class btcbox extends Exchange { if (datetimeString !== undefined) { timestamp = this.parse8601 (order['datetime'] + '+09:00'); // Tokyo time } - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let cost = undefined; if (price !== undefined) { if (filled !== undefined) { @@ -39292,7 +39144,7 @@ module.exports = class btcbox extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],51:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],51:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -39541,11 +39393,11 @@ module.exports = class btcmarkets extends Exchange { const tagTo = tag; const addressFrom = undefined; const tagFrom = undefined; - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const currencyId = this.safeString (transaction, 'assetName'); const code = this.safeCurrencyCode (currencyId); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (fee) { amount -= fee; } @@ -39598,10 +39450,10 @@ module.exports = class btcmarkets extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const fees = this.safeValue (this.safeValue (this.options, 'fees', {}), quote, this.fees); - const pricePrecision = this.safeFloat (market, 'priceDecimals'); - const amountPrecision = this.safeFloat (market, 'amountDecimals'); - const minAmount = this.safeFloat (market, 'minOrderAmount'); - const maxAmount = this.safeFloat (market, 'maxOrderAmount'); + const pricePrecision = this.safeNumber (market, 'priceDecimals'); + const amountPrecision = this.safeNumber (market, 'amountDecimals'); + const minAmount = this.safeNumber (market, 'minOrderAmount'); + const maxAmount = this.safeNumber (market, 'maxOrderAmount'); let minPrice = undefined; if (quote === 'AUD') { minPrice = Math.pow (10, -pricePrecision); @@ -39660,14 +39512,12 @@ module.exports = class btcmarkets extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetName'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance, 'balance'); - const used = this.safeFloat (balance, 'locked'); const account = this.account (); - account['used'] = used; - account['total'] = total; + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -39683,11 +39533,11 @@ module.exports = class btcmarkets extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 0)), - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 2), // high - this.safeFloat (ohlcv, 3), // low - this.safeFloat (ohlcv, 4), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 2), // high + this.safeNumber (ohlcv, 3), // low + this.safeNumber (ohlcv, 4), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -39783,21 +39633,21 @@ module.exports = class btcmarkets extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'lastPrice'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); - const quoteVolume = this.safeFloat (ticker, 'volumeQte24h'); + const last = this.safeNumber (ticker, 'lastPrice'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); + const quoteVolume = this.safeNumber (ticker, 'volumeQte24h'); const vwap = this.vwap (baseVolume, quoteVolume); - const change = this.safeFloat (ticker, 'price24h'); - const percentage = this.safeFloat (ticker, 'pricePct24h'); + const change = this.safeNumber (ticker, 'price24h'); + const percentage = this.safeNumber (ticker, 'pricePct24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bestBid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'bestAsk'), + 'ask': this.safeNumber (ticker, 'bestAsk'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -39908,8 +39758,8 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -39918,7 +39768,7 @@ module.exports = class btcmarkets extends Exchange { } const orderId = this.safeString (trade, 'orderId'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -40009,7 +39859,7 @@ module.exports = class btcmarkets extends Exchange { } } if (triggerPriceIsRequired) { - const triggerPrice = this.safeFloat (params, 'triggerPrice'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); params = this.omit (params, 'triggerPrice'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a triggerPrice parameter for a ' + type + 'order'); @@ -40142,9 +39992,9 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const type = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'openAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'openAmount'); let filled = undefined; if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); @@ -40159,7 +40009,7 @@ module.exports = class btcmarkets extends Exchange { const id = this.safeString (order, 'orderId'); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -40351,13 +40201,14 @@ module.exports = class btcmarkets extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],52:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],52:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -40460,10 +40311,10 @@ module.exports = class btctradeua extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -40603,14 +40454,11 @@ module.exports = class btctradeua extends Exchange { const id = this.safeString (trade, 'id'); const type = 'limit'; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amnt_trade'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amnt_trade'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -40691,11 +40539,11 @@ module.exports = class btctradeua extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'amnt_trade'), + 'amount': this.safeNumber (order, 'amnt_trade'), 'filled': 0, - 'remaining': this.safeFloat (order, 'amnt_trade'), + 'remaining': this.safeNumber (order, 'amnt_trade'), 'trades': undefined, 'info': order, 'cost': undefined, @@ -40747,7 +40595,7 @@ module.exports = class btctradeua extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],53:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],53:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -40875,13 +40723,13 @@ module.exports = class btcturk extends Exchange { const used = currency['id'] + '_reserved'; if (free in response) { const account = this.account (); - account['free'] = this.safeFloat (response, free); - account['total'] = this.safeFloat (response, total); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['total'] = this.safeString (response, total); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -40901,26 +40749,26 @@ module.exports = class btcturk extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'average'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -40954,8 +40802,8 @@ module.exports = class btcturk extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -40997,11 +40845,11 @@ module.exports = class btcturk extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (this.safeString (ohlcv, 'Time')), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -41076,13 +40924,14 @@ module.exports = class btcturk extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],54:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],54:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { AddressPending, AuthenticationError, ExchangeError, NotSupported, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -41299,7 +41148,7 @@ module.exports = class buda extends Exchange { } const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); - const precision = this.safeFloat (currency, 'input_decimals'); + const precision = this.safeNumber (currency, 'input_decimals'); const minimum = Math.pow (10, -precision); result[code] = { 'id': id, @@ -41460,24 +41309,25 @@ module.exports = class buda extends Exchange { let timestamp = undefined; let side = undefined; const type = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; const order = undefined; const fee = undefined; let symbol = undefined; - let cost = undefined; if (market) { symbol = market['symbol']; } if (Array.isArray (trade)) { - timestamp = parseInt (trade[0]); - price = parseFloat (trade[1]); - amount = parseFloat (trade[2]); - cost = price * amount; - side = trade[3]; - id = trade[4].toString (); + timestamp = this.safeInteger (trade, 0); + priceString = this.safeString (trade, 1); + amountString = this.safeString (trade, 2); + side = this.safeString (trade, 3); + id = this.safeString (trade, 4); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': order, @@ -41532,11 +41382,11 @@ module.exports = class buda extends Exchange { const currencyId = this.safeString (balance, 'id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = parseFloat (balance['available_amount'][0]); - account['total'] = parseFloat (balance['amount'][0]); + account['free'] = this.safeString (balance['available_amount'], 0); + account['total'] = this.safeString (balance['amount'], 0); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -41644,15 +41494,15 @@ module.exports = class buda extends Exchange { const side = this.safeStringLower (order, 'type'); const status = this.parseOrderStatus (this.safeString (order, 'state')); const originalAmount = this.safeValue (order, 'original_amount', []); - const amount = this.safeFloat (originalAmount, 0); + const amount = this.safeNumber (originalAmount, 0); const remainingAmount = this.safeValue (order, 'amount', []); - const remaining = this.safeFloat (remainingAmount, 0); + const remaining = this.safeNumber (remainingAmount, 0); const tradedAmount = this.safeValue (order, 'traded_amount', []); - const filled = this.safeFloat (tradedAmount, 0); + const filled = this.safeNumber (tradedAmount, 0); const totalExchanged = this.safeValue (order, 'totalExchanged', []); - const cost = this.safeFloat (totalExchanged, 0); + const cost = this.safeNumber (totalExchanged, 0); const limitPrice = this.safeValue (order, 'limit', []); - let price = this.safeFloat (limitPrice, 0); + let price = this.safeNumber (limitPrice, 0); if (price === undefined) { if (limitPrice !== undefined) { price = limitPrice; @@ -41663,7 +41513,7 @@ module.exports = class buda extends Exchange { average = this.priceToPrecision (symbol, cost / filled); } const paidFee = this.safeValue (order, 'paid_fee', []); - const feeCost = this.safeFloat (paidFee, 0); + const feeCost = this.safeNumber (paidFee, 0); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (paidFee, 1); @@ -41902,13 +41752,14 @@ module.exports = class buda extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],55:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],55:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { RateLimitExceeded, BadSymbol, OrderNotFound, ExchangeError, AuthenticationError, ArgumentsRequired, ExchangeNotAvailable } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -42090,7 +41941,7 @@ module.exports = class bw extends Exchange { const symbol = base + '/' + quote; const state = this.safeInteger (market, 'state'); const active = (state === 1); - const fee = this.safeFloat (market, 'defaultFee'); + const fee = this.safeNumber (market, 'defaultFee'); result.push ({ 'id': id, 'active': active, @@ -42111,7 +41962,7 @@ module.exports = class bw extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -42197,11 +42048,11 @@ module.exports = class bw extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'drawFee'), + 'fee': this.safeNumber (currency, 'drawFee'), 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'limitAmount', 0), + 'min': this.safeNumber (currency, 'limitAmount', 0), 'max': undefined, }, 'price': { @@ -42214,7 +42065,7 @@ module.exports = class bw extends Exchange { }, 'withdraw': { 'min': undefined, - 'max': this.safeFloat (currency, 'onceDrawLimit'), + 'max': this.safeNumber (currency, 'onceDrawLimit'), }, }, }; @@ -42251,9 +42102,9 @@ module.exports = class bw extends Exchange { 'high': parseFloat (this.safeValue (ticker, 2)), 'low': parseFloat (this.safeValue (ticker, 3)), 'bid': parseFloat (this.safeValue (ticker, 7)), - 'bidVolume': this.safeFloat (bid, 'quantity'), + 'bidVolume': this.safeNumber (bid, 'quantity'), 'ask': parseFloat (this.safeValue (ticker, 8)), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, 'open': undefined, 'close': close, @@ -42382,8 +42233,11 @@ module.exports = class bw extends Exchange { // ... // const timestamp = this.safeTimestamp (trade, 2); - const price = this.safeFloat (trade, 5); - const amount = this.safeFloat (trade, 6); + const priceString = this.safeString (trade, 5); + const amountString = this.safeString (trade, 6); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 1); let symbol = undefined; if (marketId !== undefined) { @@ -42400,12 +42254,6 @@ module.exports = class bw extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const sideString = this.safeString (trade, 4); const side = (sideString === 'ask') ? 'sell' : 'buy'; return { @@ -42419,7 +42267,7 @@ module.exports = class bw extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': parseFloat (cost), + 'cost': cost, 'fee': undefined, 'info': trade, }; @@ -42476,11 +42324,11 @@ module.exports = class bw extends Exchange { // return [ this.safeTimestamp (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - this.safeFloat (ohlcv, 6), - this.safeFloat (ohlcv, 7), - this.safeFloat (ohlcv, 8), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + this.safeNumber (ohlcv, 6), + this.safeNumber (ohlcv, 7), + this.safeNumber (ohlcv, 8), ]; } @@ -42538,11 +42386,11 @@ module.exports = class bw extends Exchange { const currencyId = this.safeString (balance, 'currencyTypeId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'amount'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'amount'); + account['used'] = this.safeString (balance, 'freeze'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -42638,25 +42486,13 @@ module.exports = class bw extends Exchange { } else if (side === '1') { side = 'buy'; } - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'completeAmount'); - let remaining = this.safeFloat2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available - let cost = this.safeFloat (order, 'totalMoney'); - if (filled !== undefined) { - if (amount !== undefined) { - if (remaining === undefined) { - remaining = amount - filled; - } - } - if (cost === undefined) { - if (price !== undefined) { - cost = filled * cost; - } - } - } + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'completeAmount'); + const remaining = this.safeNumber2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available + const cost = this.safeNumber (order, 'totalMoney'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'entrustId'), 'clientOrderId': undefined, @@ -42678,7 +42514,7 @@ module.exports = class bw extends Exchange { 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -42974,12 +42810,12 @@ module.exports = class bw extends Exchange { code = currency['code']; } const type = ('depositId' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat2 (transaction, 'actuallyAmount', 'amount'); + const amount = this.safeNumber2 (transaction, 'actuallyAmount', 'amount'); const status = this.parseTransactionStatus (this.safeString2 (transaction, 'verifyStatus', 'state')); const timestamp = this.safeInteger (transaction, 'createTime'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -43110,7 +42946,7 @@ module.exports = class bw extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],56:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],56:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -43155,6 +42991,7 @@ module.exports = class bybit extends Exchange { 'fetchTrades': true, 'fetchTransactions': false, 'fetchWithdrawals': true, + 'fetchPositions': true, }, 'timeframes': { '1m': '1', @@ -43186,6 +43023,34 @@ module.exports = class bybit extends Exchange { 'referral': 'https://www.bybit.com/app/register?ref=X7Prm', }, 'api': { + 'futures': { + 'private': { + 'get': [ + 'position/list', + 'order/list', + 'order', + 'stop-order/list', + 'stop-order', + 'execution/list', + 'trade/closed-pnl/list', + ], + 'post': [ + 'order/create', + 'order/cancel', + 'order/cancelAll', + 'order/replace', + 'stop-order/create', + 'stop-order/cancel', + 'stop-order/cancelAll', + 'stop-order/replace', + 'position/change-position-margin', + 'position/trading-stop', + 'position/leverage/save', + 'position/switch-mode', + 'position/switch-isolated', + ], + }, + }, 'v2': { 'public': { 'get': [ @@ -43399,7 +43264,11 @@ module.exports = class bybit extends Exchange { 'LTC/USDT': 'linear', 'XTZ/USDT': 'linear', 'LINK/USDT': 'linear', + 'ADA/USDT': 'linear', + 'DOT/USDT': 'linear', + 'UNI/USDT': 'linear', }, + 'defaultType': 'linear', // may also be inverse or inverseFuture 'code': 'BTC', 'cancelAllOrders': { // 'method': 'v2PrivatePostOrderCancelAll', // v2PrivatePostStopOrderCancelAll @@ -43514,8 +43383,8 @@ module.exports = class bybit extends Exchange { const lotSizeFilter = this.safeValue (market, 'lot_size_filter', {}); const priceFilter = this.safeValue (market, 'price_filter', {}); const precision = { - 'amount': this.safeFloat (lotSizeFilter, 'qty_step'), - 'price': this.safeFloat (priceFilter, 'tick_size'), + 'amount': this.safeNumber (lotSizeFilter, 'qty_step'), + 'price': this.safeNumber (priceFilter, 'tick_size'), }; const status = this.safeString (market, 'status'); let active = undefined; @@ -43529,8 +43398,8 @@ module.exports = class bybit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'type': 'future', 'spot': false, 'future': true, @@ -43539,12 +43408,12 @@ module.exports = class bybit extends Exchange { 'inverse': inverse, 'limits': { 'amount': { - 'min': this.safeFloat (lotSizeFilter, 'min_trading_qty'), - 'max': this.safeFloat (lotSizeFilter, 'max_trading_qty'), + 'min': this.safeNumber (lotSizeFilter, 'min_trading_qty'), + 'max': this.safeNumber (lotSizeFilter, 'max_trading_qty'), }, 'price': { - 'min': this.safeFloat (priceFilter, 'min_price'), - 'max': this.safeFloat (priceFilter, 'max_price'), + 'min': this.safeNumber (priceFilter, 'min_price'), + 'max': this.safeNumber (priceFilter, 'max_price'), }, 'cost': { 'min': undefined, @@ -43590,9 +43459,9 @@ module.exports = class bybit extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const open = this.safeFloat (ticker, 'prev_price_24h'); - let percentage = this.safeFloat (ticker, 'price_24h_pcnt'); + const last = this.safeNumber (ticker, 'last_price'); + const open = this.safeNumber (ticker, 'prev_price_24h'); + let percentage = this.safeNumber (ticker, 'price_24h_pcnt'); if (percentage !== undefined) { percentage *= 100; } @@ -43602,18 +43471,18 @@ module.exports = class bybit extends Exchange { change = last - open; average = this.sum (open, last) / 2; } - const baseVolume = this.safeFloat (ticker, 'turnover_24h'); - const quoteVolume = this.safeFloat (ticker, 'volume_24h'); + const baseVolume = this.safeNumber (ticker, 'turnover_24h'); + const quoteVolume = this.safeNumber (ticker, 'volume_24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price_24h'), - 'low': this.safeFloat (ticker, 'low_price_24h'), - 'bid': this.safeFloat (ticker, 'bid_price'), + 'high': this.safeNumber (ticker, 'high_price_24h'), + 'low': this.safeNumber (ticker, 'low_price_24h'), + 'bid': this.safeNumber (ticker, 'bid_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask_price'), + 'ask': this.safeNumber (ticker, 'ask_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -43762,11 +43631,11 @@ module.exports = class bybit extends Exchange { // return [ this.safeTimestamp2 (ohlcv, 'open_time', 'start_at'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat2 (ohlcv, 'turnover', 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber2 (ohlcv, 'turnover', 'volume'), ]; } @@ -43892,9 +43761,9 @@ module.exports = class bybit extends Exchange { const marketId = this.safeString (trade, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat2 (trade, 'qty', 'exec_qty'); - let cost = this.safeFloat (trade, 'exec_value'); - const price = this.safeFloat2 (trade, 'exec_price', 'price'); + const amount = this.safeNumber2 (trade, 'qty', 'exec_qty'); + let cost = this.safeNumber (trade, 'exec_value'); + const price = this.safeNumber2 (trade, 'exec_price', 'price'); if (cost === undefined) { if (amount !== undefined) { if (price !== undefined) { @@ -43909,14 +43778,14 @@ module.exports = class bybit extends Exchange { const side = this.safeStringLower (trade, 'side'); const lastLiquidityInd = this.safeString (trade, 'last_liquidity_ind'); const takerOrMaker = (lastLiquidityInd === 'AddedLiquidity') ? 'maker' : 'taker'; - const feeCost = this.safeFloat (trade, 'exec_fee'); + const feeCost = this.safeNumber (trade, 'exec_fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyCode = market['inverse'] ? market['base'] : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'fee_rate'), + 'rate': this.safeNumber (trade, 'fee_rate'), }; } return { @@ -44076,12 +43945,12 @@ module.exports = class bybit extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['used'] = this.safeFloat (balance, 'used_margin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'used_margin'); + account['total'] = this.safeString (balance, 'equity'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -44208,56 +44077,42 @@ module.exports = class bybit extends Exchange { // const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); - let symbol = undefined; - let base = undefined; + const symbol = market['symbol']; + let feeCurrency = undefined; const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const id = this.safeString2 (order, 'order_id', 'stop_order_id'); const type = this.safeStringLower (order, 'order_type'); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - let average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'qty'); - let cost = this.safeFloat (order, 'cum_exec_value'); - let filled = this.safeFloat (order, 'cum_exec_qty'); - let remaining = this.safeFloat (order, 'leaves_qty'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'qty'); + const cost = this.safeNumber (order, 'cum_exec_value'); + const filled = this.safeNumber (order, 'cum_exec_qty'); + const remaining = this.safeNumber (order, 'leaves_qty'); + const marketTypes = this.safeValue (this.options, 'marketTypes', {}); + const marketType = this.safeString (marketTypes, symbol); if (market !== undefined) { - symbol = market['symbol']; - base = market['base']; + if (marketType === 'linear') { + feeCurrency = market['quote']; + } else { + feeCurrency = market['base']; + } } let lastTradeTimestamp = this.safeTimestamp (order, 'last_exec_time'); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = amount - remaining; - } - if (filled !== undefined) { - if ((remaining === undefined) && (amount !== undefined)) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if ((type === 'market') && (cost !== undefined) && (cost > 0)) { - price = undefined; - if (average === undefined) { - average = filled / cost; - } - } - } const status = this.parseOrderStatus (this.safeString2 (order, 'order_status', 'stop_order_status')); const side = this.safeStringLower (order, 'side'); - let feeCost = this.safeFloat (order, 'cum_exec_fee'); + let feeCost = this.safeNumber (order, 'cum_exec_fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); fee = { 'cost': feeCost, - 'currency': base, + 'currency': feeCurrency, }; } let clientOrderId = this.safeString (order, 'order_link_id'); @@ -44265,9 +44120,9 @@ module.exports = class bybit extends Exchange { clientOrderId = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'stop_px'); + const stopPrice = this.safeNumber (order, 'stop_px'); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -44289,7 +44144,7 @@ module.exports = class bybit extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -45140,7 +44995,8 @@ module.exports = class bybit extends Exchange { const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); + const type = this.safeStringLower (transaction, 'type'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -45160,8 +45016,8 @@ module.exports = class bybit extends Exchange { 'tag': undefined, 'tagTo': undefined, 'tagFrom': undefined, - 'type': 'withdrawal', - 'amount': this.safeFloat (transaction, 'amount'), + 'type': type, + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -45244,8 +45100,8 @@ module.exports = class bybit extends Exchange { // const currencyId = this.safeString (item, 'coin'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'wallet_balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'wallet_balance'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -45311,7 +45167,8 @@ module.exports = class bybit extends Exchange { 'recv_window': this.options['recvWindow'], 'timestamp': timestamp, }); - const auth = this.rawencode (this.keysort (query)); + const sortedQuery = this.keysort (query); + const auth = this.rawencode (sortedQuery); const signature = this.hmac (this.encode (auth), this.encode (this.secret)); if (method === 'POST') { body = this.json (this.extend (query, { @@ -45321,7 +45178,7 @@ module.exports = class bybit extends Exchange { 'Content-Type': 'application/json', }; } else { - request += '?' + auth + '&sign=' + signature; + request += '?' + this.urlencode (sortedQuery) + '&sign=' + signature; } } url += request; @@ -45344,17 +45201,48 @@ module.exports = class bybit extends Exchange { // time_now: '1583934106.590436' // } // - const errorCode = this.safeValue (response, 'ret_code'); - if (errorCode !== 0) { + const errorCode = this.safeString (response, 'ret_code'); + if (errorCode !== '0') { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback); this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback); throw new ExchangeError (feedback); // unknown message } } + + async fetchPositions (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (Array.isArray (symbols)) { + const length = symbols.length; + if (length !== 1) { + throw new ArgumentsRequired (this.id + ' fetchPositions takes exactly one symbol'); + } + request['symbol'] = this.marketId (symbols[0]); + } + const defaultType = this.safeString (this.options, 'defaultType', 'linear'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + let response = undefined; + if (type === 'linear') { + response = await this.privateLinearGetPositionList (this.extend (request, params)); + } else if (type === 'inverse') { + response = await this.v2PrivateGetPositionList (this.extend (request, params)); + } else if (type === 'inverseFuture') { + response = await this.futuresPrivateGetPositionList (this.extend (request, params)); + } + // { + // ret_code: 0, + // ret_msg: 'OK', + // ext_code: '', + // ext_info: '', + // result: [] or {} depending on the request + // } + return this.safeValue (response, 'result'); + } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],57:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],57:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -45543,12 +45431,12 @@ module.exports = class bytetrade extends Exchange { const limits = this.safeValue (currency, 'limits'); const deposit = this.safeValue (limits, 'deposit'); const amountPrecision = this.safeInteger (currency, 'basePrecision'); - let maxDeposit = this.safeFloat (deposit, 'max'); + let maxDeposit = this.safeNumber (deposit, 'max'); if (maxDeposit === -1.0) { maxDeposit = undefined; } const withdraw = this.safeValue (limits, 'withdraw'); - let maxWithdraw = this.safeFloat (withdraw, 'max'); + let maxWithdraw = this.safeNumber (withdraw, 'max'); if (maxWithdraw === -1.0) { maxWithdraw = undefined; } @@ -45564,11 +45452,11 @@ module.exports = class bytetrade extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (deposit, 'min'), + 'min': this.safeNumber (deposit, 'min'), 'max': maxDeposit, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'min'), + 'min': this.safeNumber (withdraw, 'min'), 'max': maxWithdraw, }, }, @@ -45622,12 +45510,12 @@ module.exports = class bytetrade extends Exchange { 'normalSymbol': normalSymbol, 'limits': { 'amount': { - 'min': this.safeFloat (amount, 'min'), - 'max': this.safeFloat (amount, 'max'), + 'min': this.safeNumber (amount, 'min'), + 'max': this.safeNumber (amount, 'max'), }, 'price': { - 'min': this.safeFloat (price, 'min'), - 'max': this.safeFloat (price, 'max'), + 'min': this.safeNumber (price, 'min'), + 'max': this.safeNumber (price, 'max'), }, 'cost': { 'min': undefined, @@ -45655,11 +45543,11 @@ module.exports = class bytetrade extends Exchange { const currencyId = this.safeString (balance, 'code'); const code = this.safeCurrencyCode (currencyId, undefined); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'used'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'used'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -45720,22 +45608,22 @@ module.exports = class bytetrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'open'), - 'close': this.safeFloat (ticker, 'close'), - 'last': this.safeFloat (ticker, 'last'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'open'), + 'close': this.safeNumber (ticker, 'close'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, // previous day close - 'change': this.safeFloat (ticker, 'change'), - 'percentage': this.safeFloat (ticker, 'percentage'), + 'change': this.safeNumber (ticker, 'change'), + 'percentage': this.safeNumber (ticker, 'percentage'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -45778,24 +45666,16 @@ module.exports = class bytetrade extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetDepth (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetDepth (params); + return this.parseTickers (response, symbols); } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetTickers (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetTickers (params); + return this.parseTickers (response, symbols); } parseOHLCV (ohlcv, market = undefined) { @@ -45811,11 +45691,11 @@ module.exports = class bytetrade extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -45845,9 +45725,9 @@ module.exports = class bytetrade extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeInteger (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - const cost = this.safeFloat (trade, 'cost'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + const cost = this.safeNumber (trade, 'cost'); const id = this.safeString (trade, 'id'); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'takerOrMaker'); @@ -45917,12 +45797,12 @@ module.exports = class bytetrade extends Exchange { const timestamp = this.safeInteger (order, 'timestamp'); const datetime = this.safeString (order, 'datetime'); const lastTradeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled'); - const remaining = this.safeFloat (order, 'remaining'); - const cost = this.safeFloat (order, 'cost'); - const average = this.safeFloat (order, 'average'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled'); + const remaining = this.safeNumber (order, 'remaining'); + const cost = this.safeNumber (order, 'cost'); + const average = this.safeNumber (order, 'average'); const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); @@ -46315,7 +46195,7 @@ module.exports = class bytetrade extends Exchange { }; } - async transfer (code, amount, address, message = '', params = {}) { + async transfer (code, amount, fromAccount, toAccount, params = {}) { this.checkRequiredDependencies (); if (this.apiKey === undefined) { throw new ArgumentsRequired ('transfer() requires this.apiKey'); @@ -46333,6 +46213,7 @@ module.exports = class bytetrade extends Exchange { expirationDatetime = expirationDatetime.split ('.')[0]; const feeAmount = '300000000000000'; const defaultDappId = 'Sagittarius'; + const message = this.safeString (params, 'message', ''); const dappId = this.safeString (params, 'dappId', defaultDappId); const eightBytes = this.integerPow ('2', '64'); const byteStringArray = [ @@ -46346,8 +46227,8 @@ module.exports = class bytetrade extends Exchange { this.numberToLE (feeAmount, 8), // string for 32 bit php this.numberToLE (this.apiKey.length, 1), this.stringToBinary (this.encode (this.apiKey)), - this.numberToLE (address.length, 1), - this.stringToBinary (this.encode (address)), + this.numberToLE (toAccount.length, 1), + this.stringToBinary (this.encode (toAccount)), this.numberToLE (assetType, 4), this.numberToLE (this.integerDivide (amountChain, eightBytes), 8), this.numberToLE (this.integerModulo (amountChain, eightBytes), 8), @@ -46368,7 +46249,7 @@ module.exports = class bytetrade extends Exchange { const operation = { 'fee': '300000000000000', 'from': this.apiKey, - 'to': address, + 'to': toAccount, 'asset_type': parseInt (currency['id']), 'amount': amountChain.toString (), 'message': message, @@ -46522,9 +46403,9 @@ module.exports = class bytetrade extends Exchange { const datetime = this.safeString (transaction, 'datetime'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const feeInfo = this.safeValue (transaction, 'fee'); - const feeCost = this.safeFloat (feeInfo, 'cost'); + const feeCost = this.safeNumber (feeInfo, 'cost'); const feeCurrencyId = this.safeString (feeInfo, 'code'); const feeCode = this.safeCurrencyCode (feeCurrencyId, currency); const fee = { @@ -46787,7 +46668,7 @@ module.exports = class bytetrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],58:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],58:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -46822,7 +46703,7 @@ module.exports = class cdax extends huobipro { } }; -},{"./huobipro.js":96}],59:[function(require,module,exports){ +},{"./huobipro.js":94}],59:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -47081,7 +46962,7 @@ module.exports = class cex extends Exchange { 'fee': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimumCurrencyAmount'), + 'min': this.safeNumber (currency, 'minimumCurrencyAmount'), 'max': undefined, }, 'price': { @@ -47093,7 +46974,7 @@ module.exports = class cex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimalWithdrawalAmount'), + 'min': this.safeNumber (currency, 'minimalWithdrawalAmount'), 'max': undefined, }, }, @@ -47176,15 +47057,15 @@ module.exports = class cex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minLotSize'), - 'max': this.safeFloat (market, 'maxLotSize'), + 'min': this.safeNumber (market, 'minLotSize'), + 'max': this.safeNumber (market, 'maxLotSize'), }, 'price': { - 'min': this.safeFloat (market, 'minPrice'), - 'max': this.safeFloat (market, 'maxPrice'), + 'min': this.safeNumber (market, 'minPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { - 'min': this.safeFloat (market, 'minLotSizeS2'), + 'min': this.safeNumber (market, 'minLotSizeS2'), 'max': undefined, }, }, @@ -47205,13 +47086,13 @@ module.exports = class cex extends Exchange { const currencyId = currencyIds[i]; const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); + account['free'] = this.safeString (balance, 'available'); // https://github.com/ccxt/ccxt/issues/5484 - account['used'] = this.safeFloat (balance, 'orders', 0.0); + account['used'] = this.safeString (balance, 'orders', '0'); const code = this.safeCurrencyCode (currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -47240,11 +47121,11 @@ module.exports = class cex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -47286,12 +47167,12 @@ module.exports = class cex extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const volume = this.safeFloat (ticker, 'volume'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'last'); + const volume = this.safeNumber (ticker, 'volume'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'last'); let symbol = undefined; if (market) { symbol = market['symbol']; @@ -47353,8 +47234,8 @@ module.exports = class cex extends Exchange { const id = this.safeString (trade, 'tid'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -47426,8 +47307,8 @@ module.exports = class cex extends Exchange { // "complete": false // } // - const placedAmount = this.safeFloat (response, 'amount'); - const remaining = this.safeFloat (response, 'pending'); + const placedAmount = this.safeNumber (response, 'amount'); + const remaining = this.safeNumber (response, 'pending'); const timestamp = this.safeValue (response, 'time'); const complete = this.safeValue (response, 'complete'); const status = complete ? 'closed' : 'open'; @@ -47446,7 +47327,7 @@ module.exports = class cex extends Exchange { 'side': this.safeString (response, 'type'), 'symbol': symbol, 'status': status, - 'price': this.safeFloat (response, 'price'), + 'price': this.safeNumber (response, 'price'), 'amount': placedAmount, 'cost': undefined, 'average': undefined, @@ -47488,42 +47369,42 @@ module.exports = class cex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - let amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + let amount = this.safeNumber (order, 'amount'); // sell orders can have a negative amount // https://github.com/ccxt/ccxt/issues/5338 if (amount !== undefined) { amount = Math.abs (amount); } - const remaining = this.safeFloat2 (order, 'pending', 'remains'); + const remaining = this.safeNumber2 (order, 'pending', 'remains'); const filled = amount - remaining; let fee = undefined; let cost = undefined; if (market !== undefined) { symbol = market['symbol']; - const taCost = this.safeFloat (order, 'ta:' + market['quote']); - const ttaCost = this.safeFloat (order, 'tta:' + market['quote']); + const taCost = this.safeNumber (order, 'ta:' + market['quote']); + const ttaCost = this.safeNumber (order, 'tta:' + market['quote']); cost = this.sum (taCost, ttaCost); const baseFee = 'fa:' + market['base']; const baseTakerFee = 'tfa:' + market['base']; const quoteFee = 'fa:' + market['quote']; const quoteTakerFee = 'tfa:' + market['quote']; - let feeRate = this.safeFloat (order, 'tradingFeeMaker'); + let feeRate = this.safeNumber (order, 'tradingFeeMaker'); if (!feeRate) { - feeRate = this.safeFloat (order, 'tradingFeeTaker', feeRate); + feeRate = this.safeNumber (order, 'tradingFeeTaker', feeRate); } if (feeRate) { feeRate /= 100.0; // convert to mathematically-correct percentage coefficients: 1.0 = 100% } if ((baseFee in order) || (baseTakerFee in order)) { - const baseFeeCost = this.safeFloat2 (order, baseFee, baseTakerFee); + const baseFeeCost = this.safeNumber2 (order, baseFee, baseTakerFee); fee = { 'currency': market['base'], 'rate': feeRate, 'cost': baseFeeCost, }; } else if ((quoteFee in order) || (quoteTakerFee in order)) { - const quoteFeeCost = this.safeFloat2 (order, quoteFee, quoteTakerFee); + const quoteFeeCost = this.safeNumber2 (order, quoteFee, quoteTakerFee); fee = { 'currency': market['quote'], 'rate': feeRate, @@ -47563,7 +47444,7 @@ module.exports = class cex extends Exchange { // ds: 0 } continue; } - const tradePrice = this.safeFloat (item, 'price'); + const tradePrice = this.safeNumber (item, 'price'); if (tradePrice === undefined) { // this represents the order // { @@ -47667,8 +47548,8 @@ module.exports = class cex extends Exchange { // "fee_amount": "0.03" // } const tradeTimestamp = this.parse8601 (this.safeString (item, 'time')); - const tradeAmount = this.safeFloat (item, 'amount'); - const feeCost = this.safeFloat (item, 'fee_amount'); + const tradeAmount = this.safeNumber (item, 'amount'); + const feeCost = this.safeNumber (item, 'fee_amount'); let absTradeAmount = (tradeAmount < 0) ? -tradeAmount : tradeAmount; let tradeCost = undefined; if (tradeSide === 'sell') { @@ -48013,12 +47894,12 @@ module.exports = class cex extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const side = this.safeString (order, 'type'); - const baseAmount = this.safeFloat (order, 'a:' + baseId + ':cds'); - const quoteAmount = this.safeFloat (order, 'a:' + quoteId + ':cds'); - const fee = this.safeFloat (order, 'f:' + quoteId + ':cds'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const remaining = this.safeFloat (order, 'remains'); + const baseAmount = this.safeNumber (order, 'a:' + baseId + ':cds'); + const quoteAmount = this.safeNumber (order, 'a:' + quoteId + ':cds'); + const fee = this.safeNumber (order, 'f:' + quoteId + ':cds'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const remaining = this.safeNumber (order, 'remains'); const filled = amount - remaining; let orderAmount = undefined; let cost = undefined; @@ -48030,10 +47911,10 @@ module.exports = class cex extends Exchange { cost = quoteAmount; average = orderAmount / cost; } else { - const ta = this.safeFloat (order, 'ta:' + quoteId, 0); - const tta = this.safeFloat (order, 'tta:' + quoteId, 0); - const fa = this.safeFloat (order, 'fa:' + quoteId, 0); - const tfa = this.safeFloat (order, 'tfa:' + quoteId, 0); + const ta = this.safeNumber (order, 'ta:' + quoteId, 0); + const tta = this.safeNumber (order, 'tta:' + quoteId, 0); + const fa = this.safeNumber (order, 'fa:' + quoteId, 0); + const tfa = this.safeNumber (order, 'tfa:' + quoteId, 0); if (side === 'sell') { cost = this.sum (this.sum (ta, tta), this.sum (fa, tfa)); } else { @@ -48172,47 +48053,14 @@ module.exports = class cex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],60:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const foxbit = require ('./foxbit.js'); - -// --------------------------------------------------------------------------- - -module.exports = class chilebit extends foxbit { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'chilebit', - 'name': 'ChileBit', - 'countries': [ 'CL' ], - 'has': { - 'CORS': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg', - 'api': { - 'public': 'https://api.blinktrade.com/api', - 'private': 'https://api.blinktrade.com/tapi', - }, - 'www': 'https://chilebit.net', - 'doc': 'https://blinktrade.com/docs', - }, - 'options': { - 'brokerId': '9', // https://blinktrade.com/docs/#brokers - }, - }); - } -}; - -},{"./foxbit.js":87}],61:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],60:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, RateLimitExceeded, InvalidNonce } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -48620,10 +48468,10 @@ module.exports = class coinbase extends Exchange { const timestamp = this.parse8601 (this.safeValue (transaction, 'created_at')); const updated = this.parse8601 (this.safeValue (transaction, 'updated_at')); const type = this.safeString (transaction, 'resource'); - const amount = this.safeFloat (subtotalObject, 'amount'); + const amount = this.safeNumber (subtotalObject, 'amount'); const currencyId = this.safeString (subtotalObject, 'currency'); const currency = this.safeCurrencyCode (currencyId); - const feeCost = this.safeFloat (feeObject, 'amount'); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -48699,15 +48547,12 @@ module.exports = class coinbase extends Exchange { const orderId = undefined; const side = this.safeString (trade, 'resource'); const type = undefined; - const cost = this.safeFloat (subtotalObject, 'amount'); - const amount = this.safeFloat (amountObject, 'amount'); - let price = undefined; - if (cost !== undefined) { - if ((amount !== undefined) && (amount > 0)) { - price = cost / amount; - } - } - const feeCost = this.safeFloat (feeObject, 'amount'); + const costString = this.safeString (subtotalObject, 'amount'); + const amountString = this.safeString (amountObject, 'amount'); + const cost = this.parseNumber (costString); + const amount = this.parseNumber (amountString); + const price = this.parseNumber (Precise.stringDiv (costString, amountString)); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -48775,7 +48620,7 @@ module.exports = class coinbase extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (quoteCurrency, 'min_size'), + 'min': this.safeNumber (quoteCurrency, 'min_size'), 'max': undefined, }, }, @@ -48857,7 +48702,7 @@ module.exports = class coinbase extends Exchange { 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min_size'), + 'min': this.safeNumber (currency, 'min_size'), 'max': undefined, }, 'price': { @@ -48888,9 +48733,9 @@ module.exports = class coinbase extends Exchange { const buy = await this.publicGetPricesSymbolBuy (request); const sell = await this.publicGetPricesSymbolSell (request); const spot = await this.publicGetPricesSymbolSpot (request); - const ask = this.safeFloat (buy['data'], 'amount'); - const bid = this.safeFloat (sell['data'], 'amount'); - const last = this.safeFloat (spot['data'], 'amount'); + const ask = this.safeNumber (buy['data'], 'amount'); + const bid = this.safeNumber (sell['data'], 'amount'); + const last = this.safeNumber (spot['data'], 'amount'); return { 'symbol': symbol, 'timestamp': timestamp, @@ -48933,7 +48778,7 @@ module.exports = class coinbase extends Exchange { if (this.inArray (balance['type'], accounts)) { const currencyId = this.safeString (balance['balance'], 'currency'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance['balance'], 'amount'); + const total = this.safeNumber (balance['balance'], 'amount'); const free = total; const used = undefined; if (code in result) { @@ -49234,7 +49079,7 @@ module.exports = class coinbase extends Exchange { // } // const amountInfo = this.safeValue (item, 'amount', {}); - let amount = this.safeFloat (amountInfo, 'amount'); + let amount = this.safeNumber (amountInfo, 'amount'); let direction = undefined; if (amount < 0) { direction = 'out'; @@ -49260,7 +49105,7 @@ module.exports = class coinbase extends Exchange { if (feeInfo !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId, currency); - const feeAmount = this.safeFloat (feeInfo, 'amount'); + const feeAmount = this.safeNumber (feeInfo, 'amount'); fee = { 'cost': feeAmount, 'currency': feeCurrencyCode, @@ -49424,7 +49269,7 @@ module.exports = class coinbase extends Exchange { }; -},{"./base/Exchange":6,"./base/errors":8}],62:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],61:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -49457,7 +49302,7 @@ module.exports = class coinbaseprime extends coinbasepro { } }; -},{"./coinbasepro.js":63}],63:[function(require,module,exports){ +},{"./coinbasepro.js":62}],62:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -49465,6 +49310,7 @@ module.exports = class coinbaseprime extends coinbasepro { const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ArgumentsRequired, ExchangeError, InvalidOrder, InvalidAddress, AuthenticationError, NotSupported, OrderNotFound, OnMaintenance, PermissionDenied, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -49699,7 +49545,7 @@ module.exports = class coinbasepro extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const details = this.safeValue (currency, 'details', {}); - const precision = this.safeFloat (currency, 'max_precision'); + const precision = this.safeNumber (currency, 'max_precision'); const status = this.safeString (currency, 'status'); const active = (status === 'online'); result[code] = { @@ -49713,7 +49559,7 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (details, 'min_size'), + 'min': this.safeNumber (details, 'min_size'), 'max': undefined, }, 'price': { @@ -49725,7 +49571,7 @@ module.exports = class coinbasepro extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (details, 'min_withdrawal_amount'), + 'min': this.safeNumber (details, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -49769,12 +49615,12 @@ module.exports = class coinbasepro extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const priceLimits = { - 'min': this.safeFloat (market, 'quote_increment'), + 'min': this.safeNumber (market, 'quote_increment'), 'max': undefined, }; const precision = { - 'amount': this.safeFloat (market, 'base_increment'), - 'price': this.safeFloat (market, 'quote_increment'), + 'amount': this.safeNumber (market, 'base_increment'), + 'price': this.safeNumber (market, 'quote_increment'), }; const status = this.safeString (market, 'status'); const active = (status === 'online'); @@ -49788,13 +49634,13 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': priceLimits, 'cost': { - 'min': this.safeFloat (market, 'min_market_funds'), - 'max': this.safeFloat (market, 'max_market_funds'), + 'min': this.safeNumber (market, 'min_market_funds'), + 'max': this.safeNumber (market, 'max_market_funds'), }, }, 'active': active, @@ -49851,14 +49697,13 @@ module.exports = class coinbasepro extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'hold'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'hold'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -49915,29 +49760,29 @@ module.exports = class coinbasepro extends Exchange { // } // const timestamp = this.parse8601 (this.safeValue (ticker, 'time')); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'price'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'price'); const symbol = (market === undefined) ? undefined : market['symbol']; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': undefined, 'ask': ask, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -50010,7 +49855,7 @@ module.exports = class coinbasepro extends Exchange { if (market !== undefined) { const feeCurrencyId = this.safeStringLower (market, 'quoteId'); const costField = feeCurrencyId + '_value'; - cost = this.safeFloat (trade, costField); + cost = this.safeNumber (trade, costField); feeCurrency = market['quote']; const liquidity = this.safeString (trade, 'liquidity'); if (liquidity !== undefined) { @@ -50018,7 +49863,7 @@ module.exports = class coinbasepro extends Exchange { feeRate = market[takerOrMaker]; } } - const feeCost = this.safeFloat2 (trade, 'fill_fees', 'fee'); + const feeCost = this.safeNumber2 (trade, 'fill_fees', 'fee'); const fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -50032,10 +49877,12 @@ module.exports = class coinbasepro extends Exchange { if (orderId !== undefined) { side = (trade['side'] === 'buy') ? 'buy' : 'sell'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - cost = amount * price; + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -50097,11 +49944,11 @@ module.exports = class coinbasepro extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -50181,17 +50028,11 @@ module.exports = class coinbasepro extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'filled_size'); - const amount = this.safeFloat (order, 'size', filled); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'executed_value'); - const feeCost = this.safeFloat (order, 'fill_fees'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'filled_size'); + const amount = this.safeNumber (order, 'size', filled); + const cost = this.safeNumber (order, 'executed_value'); + const feeCost = this.safeNumber (order, 'fill_fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -50209,9 +50050,9 @@ module.exports = class coinbasepro extends Exchange { const side = this.safeString (order, 'side'); const timeInForce = this.safeString (order, 'time_in_force'); const postOnly = this.safeValue (order, 'post_only'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -50229,11 +50070,11 @@ module.exports = class coinbasepro extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -50323,7 +50164,7 @@ module.exports = class coinbasepro extends Exchange { request['client_oid'] = clientOrderId; params = this.omit (params, [ 'clientOrderId', 'client_oid' ]); } - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop_price'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stop_price'); if (stopPrice !== undefined) { request['stop_price'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, [ 'stopPrice', 'stop_price' ]); @@ -50337,7 +50178,7 @@ module.exports = class coinbasepro extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['size'] = this.amountToPrecision (symbol, amount); } else if (type === 'market') { - let cost = this.safeFloat2 (params, 'cost', 'funds'); + let cost = this.safeNumber2 (params, 'cost', 'funds'); if (cost === undefined) { if (price !== undefined) { cost = amount * price; @@ -50408,19 +50249,6 @@ module.exports = class coinbasepro extends Exchange { return await this.privateDeleteOrders (this.extend (request, params)); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - const cost = amount * price; - const currency = market['quote']; - return { - 'type': takerOrMaker, - 'currency': currency, - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (currency, rate * cost)), - }; - } - async fetchPaymentMethods (params = {}) { return await this.privateGetPaymentMethods (params); } @@ -50559,7 +50387,7 @@ module.exports = class coinbasepro extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (transaction); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let type = this.safeString (transaction, 'type'); let address = this.safeString (details, 'crypto_address'); const tag = this.safeString (details, 'destination_tag'); @@ -50568,7 +50396,7 @@ module.exports = class coinbasepro extends Exchange { if (type === 'withdraw') { type = 'withdrawal'; address = this.safeString (details, 'sent_to_address', address); - const feeCost = this.safeFloat (details, 'fee'); + const feeCost = this.safeNumber (details, 'fee'); if (feeCost !== undefined) { if (amount !== undefined) { amount -= feeCost; @@ -50682,13 +50510,14 @@ module.exports = class coinbasepro extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],64:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],63:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -50812,12 +50641,12 @@ module.exports = class coincheck extends Exchange { if (currencyId in balances) { const account = this.account (); const reserved = currencyId + '_reserved'; - account['free'] = this.safeFloat (balances, currencyId); - account['used'] = this.safeFloat (balances, reserved); + account['free'] = this.safeString (balances, currencyId); + account['used'] = this.safeString (balances, reserved); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -50855,23 +50684,13 @@ module.exports = class coincheck extends Exchange { const id = this.safeString (order, 'id'); const side = this.safeString (order, 'order_type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const amount = this.safeFloat (order, 'pending_amount'); - const remaining = this.safeFloat (order, 'pending_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = Math.max (amount - remaining, 0); - if (price !== undefined) { - cost = filled * price; - } - } - } + const amount = this.safeNumber (order, 'pending_amount'); + const remaining = this.safeNumber (order, 'pending_amount'); + const price = this.safeNumber (order, 'rate'); const status = undefined; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -50879,7 +50698,7 @@ module.exports = class coincheck extends Exchange { 'lastTradeTimestamp': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'side': side, 'type': undefined, 'timeInForce': undefined, @@ -50888,12 +50707,12 @@ module.exports = class coincheck extends Exchange { 'symbol': symbol, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'info': order, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -50917,16 +50736,16 @@ module.exports = class coincheck extends Exchange { }; const ticker = await this.publicGetTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -50936,7 +50755,7 @@ module.exports = class coincheck extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -50945,7 +50764,7 @@ module.exports = class coincheck extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'rate'); + const priceString = this.safeString (trade, 'rate'); const marketId = this.safeString (trade, 'pair'); market = this.safeValue (this.markets_by_id, marketId, market); let symbol = undefined; @@ -50972,7 +50791,7 @@ module.exports = class coincheck extends Exchange { } } let takerOrMaker = undefined; - let amount = undefined; + let amountString = undefined; let cost = undefined; let side = undefined; let fee = undefined; @@ -50984,24 +50803,22 @@ module.exports = class coincheck extends Exchange { takerOrMaker = 'maker'; } const funds = this.safeValue (trade, 'funds', {}); - amount = this.safeFloat (funds, baseId); - cost = this.safeFloat (funds, quoteId); + amountString = this.safeString (funds, baseId); + cost = this.safeNumber (funds, quoteId); fee = { 'currency': this.safeString (trade, 'fee_currency'), - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), }; side = this.safeString (trade, 'side'); orderId = this.safeString (trade, 'order_id'); } else { - amount = this.safeFloat (trade, 'amount'); + amountString = this.safeString (trade, 'amount'); side = this.safeString (trade, 'order_type'); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -51072,6 +50889,10 @@ module.exports = class coincheck extends Exchange { return await this.privateDeleteExchangeOrdersId (this.extend (request, params)); } + nonce () { + return this.milliseconds (); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let url = this.urls['api'] + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); @@ -51118,13 +50939,14 @@ module.exports = class coincheck extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],65:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],64:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -51335,8 +51157,8 @@ module.exports = class coinegg extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; let change = undefined; let average = undefined; @@ -51350,11 +51172,11 @@ module.exports = class coinegg extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -51364,8 +51186,8 @@ module.exports = class coinegg extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVol'), 'info': ticker, }; } @@ -51394,15 +51216,12 @@ module.exports = class coinegg extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const type = 'limit'; const side = this.safeString (trade, 'type'); const id = this.safeString (trade, 'tid'); @@ -51449,9 +51268,9 @@ module.exports = class coinegg extends Exchange { result[code] = this.account (); } const type = (accountType === 'lock') ? 'used' : 'free'; - result[code][type] = this.safeFloat (balances, key); + result[code][type] = this.safeString (balances, key); } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -51460,15 +51279,9 @@ module.exports = class coinegg extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let status = this.safeString (order, 'status'); if (status === 'cancelled') { status = 'canceled'; @@ -51479,7 +51292,7 @@ module.exports = class coinegg extends Exchange { const type = 'limit'; const side = this.safeString (order, 'type'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -51495,13 +51308,13 @@ module.exports = class coinegg extends Exchange { 'stopPrice': undefined, 'cost': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'trades': undefined, 'fee': undefined, 'info': info, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -51637,13 +51450,14 @@ module.exports = class coinegg extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],66:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],65:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -51836,13 +51650,13 @@ module.exports = class coinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': this.safeFloat (market, 'taker_fee_rate'), - 'maker': this.safeFloat (market, 'maker_fee_rate'), + 'taker': this.safeNumber (market, 'taker_fee_rate'), + 'maker': this.safeNumber (market, 'maker_fee_rate'), 'info': market, 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -51862,16 +51676,16 @@ module.exports = class coinex extends Exchange { symbol = market['symbol']; } ticker = this.safeValue (ticker, 'ticker', {}); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -51881,7 +51695,7 @@ module.exports = class coinex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat2 (ticker, 'vol', 'volume'), + 'baseVolume': this.safeNumber2 (ticker, 'vol', 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -51941,16 +51755,18 @@ module.exports = class coinex extends Exchange { } const tradeId = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market); - let cost = this.safeFloat (trade, 'deal_money'); - if (!cost) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); + let cost = this.safeNumber (trade, 'deal_money'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_asset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -52003,11 +51819,11 @@ module.exports = class coinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -52068,11 +51884,11 @@ module.exports = class coinex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -52111,11 +51927,11 @@ module.exports = class coinex extends Exchange { // } // const timestamp = this.safeTimestamp (order, 'create_time'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'deal_money'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'deal_amount'); - const average = this.safeFloat (order, 'avg_price'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'deal_money'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'deal_amount'); + const average = this.safeNumber (order, 'avg_price'); let symbol = undefined; const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); @@ -52127,11 +51943,11 @@ module.exports = class coinex extends Exchange { feeCurrency = market['quote']; } } - const remaining = this.safeFloat (order, 'left'); + const remaining = this.safeNumber (order, 'left'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -52153,10 +51969,10 @@ module.exports = class coinex extends Exchange { 'trades': undefined, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'deal_fee'), + 'cost': this.safeNumber (order, 'deal_fee'), }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -52402,8 +52218,8 @@ module.exports = class coinex extends Exchange { const timestamp = this.safeTimestamp (transaction, 'create_time'); const type = ('coin_withdraw_id' in transaction) ? 'withdraw' : 'deposit'; const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'tx_fee'); + let amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'tx_fee'); if (type === 'deposit') { feeCost = 0; } @@ -52594,13 +52410,14 @@ module.exports = class coinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],67:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],66:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, RateLimitExceeded, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -52733,11 +52550,11 @@ module.exports = class coinfalcon extends Exchange { 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'change_in_24h'), + 'change': this.safeNumber (ticker, 'change_in_24h'), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -52774,20 +52591,17 @@ module.exports = class coinfalcon extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } const tradeId = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'order_id'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = this.safeString (trade, 'fee_currency_code'); fee = { @@ -52855,14 +52669,13 @@ module.exports = class coinfalcon extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available_balance'), - 'used': this.safeFloat (balance, 'hold_balance'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'hold_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -52897,19 +52710,9 @@ module.exports = class coinfalcon extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'size_filled'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (price !== undefined) { - cost = filled * price; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'size_filled'); const status = this.parseOrderStatus (this.safeString (order, 'status')); let type = this.safeString (order, 'operation_type'); if (type !== undefined) { @@ -52918,7 +52721,7 @@ module.exports = class coinfalcon extends Exchange { } const side = this.safeString (order, 'order_type'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -52931,16 +52734,16 @@ module.exports = class coinfalcon extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'lastTradeTimestamp': undefined, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -53050,13 +52853,14 @@ module.exports = class coinfalcon extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],68:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],67:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ExchangeError, InvalidNonce, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -53158,14 +52962,14 @@ module.exports = class coinfloor extends Exchange { const baseIdLower = this.safeStringLower (market, 'baseId'); const quoteIdLower = this.safeStringLower (market, 'quoteId'); result[base] = { - 'free': this.safeFloat (response, baseIdLower + '_available'), - 'used': this.safeFloat (response, baseIdLower + '_reserved'), - 'total': this.safeFloat (response, baseIdLower + '_balance'), + 'free': this.safeNumber (response, baseIdLower + '_available'), + 'used': this.safeNumber (response, baseIdLower + '_reserved'), + 'total': this.safeNumber (response, baseIdLower + '_balance'), }; result[quote] = { - 'free': this.safeFloat (response, quoteIdLower + '_available'), - 'used': this.safeFloat (response, quoteIdLower + '_reserved'), - 'total': this.safeFloat (response, quoteIdLower + '_balance'), + 'free': this.safeNumber (response, quoteIdLower + '_available'), + 'used': this.safeNumber (response, quoteIdLower + '_reserved'), + 'total': this.safeNumber (response, quoteIdLower + '_balance'), }; return this.parseBalance (result); } @@ -53186,22 +52990,22 @@ module.exports = class coinfloor extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -53230,14 +53034,11 @@ module.exports = class coinfloor extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -53355,8 +53156,8 @@ module.exports = class coinfloor extends Exchange { const parts = key.split ('_'); const numParts = parts.length; if (numParts === 2) { - const tmpBaseAmount = this.safeFloat (item, parts[0]); - const tmpQuoteAmount = this.safeFloat (item, parts[1]); + const tmpBaseAmount = this.safeNumber (item, parts[0]); + const tmpQuoteAmount = this.safeNumber (item, parts[1]); if (tmpBaseAmount !== undefined && tmpQuoteAmount !== undefined) { baseId = parts[0]; quoteId = parts[1]; @@ -53372,7 +53173,7 @@ module.exports = class coinfloor extends Exchange { const referenceId = this.safeString (item, 'id'); const timestamp = this.parse8601 (this.safeString (item, 'datetime')); let fee = undefined; - const feeCost = this.safeFloat (item, 'fee'); + const feeCost = this.safeNumber (item, 'fee'); const result = { 'id': undefined, 'timestamp': timestamp, @@ -53476,8 +53277,8 @@ module.exports = class coinfloor extends Exchange { 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, 'type': type, - 'price': this.safeFloat (response, 'price'), - 'remaining': this.safeFloat (response, 'amount'), + 'price': this.safeNumber (response, 'price'), + 'remaining': this.safeNumber (response, 'amount'), 'info': response, }; } @@ -53502,19 +53303,14 @@ module.exports = class coinfloor extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let side = undefined; const status = this.safeString (order, 'status'); - if (order['type'] === 0) { + const rawType = this.safeString (order, 'type'); + if (rawType === '0') { side = 'buy'; - } else if (order['type'] === 1) { + } else if (rawType === '1') { side = 'sell'; } let symbol = undefined; @@ -53522,7 +53318,7 @@ module.exports = class coinfloor extends Exchange { symbol = market['symbol']; } const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -53540,11 +53336,11 @@ module.exports = class coinfloor extends Exchange { 'amount': undefined, 'filled': undefined, 'remaining': amount, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -53603,13 +53399,14 @@ module.exports = class coinfloor extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],69:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],68:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -53771,14 +53568,14 @@ module.exports = class coingi extends Exchange { const currencyId = this.safeString (balance['currency'], 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - const blocked = this.safeFloat (balance, 'blocked'); - const inOrders = this.safeFloat (balance, 'inOrders'); - const withdrawing = this.safeFloat (balance, 'withdrawing'); - account['used'] = this.sum (blocked, inOrders, withdrawing); + account['free'] = this.safeString (balance, 'available'); + const blocked = this.safeString (balance, 'blocked'); + const inOrders = this.safeString (balance, 'inOrders'); + const withdrawing = this.safeString (balance, 'withdrawing'); + account['used'] = Precise.stringAdd (Precise.stringAdd (blocked, inOrders), withdrawing); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = 512, params = {}) { @@ -53804,11 +53601,11 @@ module.exports = class coingi extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -53818,8 +53615,8 @@ module.exports = class coingi extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'counterVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'counterVolume'), 'info': ticker, }; } @@ -53852,14 +53649,11 @@ module.exports = class coingi extends Exchange { } parseTrade (trade, market = undefined) { - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const id = this.safeString (trade, 'id'); const marketId = this.safeString (trade, 'currencyPair'); @@ -53953,7 +53747,7 @@ module.exports = class coingi extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],70:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],69:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -54164,16 +53958,16 @@ module.exports = class coinmarketcap extends Exchange { if (timestamp === undefined) { timestamp = this.milliseconds (); } - const change = this.safeFloat (ticker, 'percent_change_24h'); + const change = this.safeNumber (ticker, 'percent_change_24h'); let last = undefined; let symbol = undefined; let volume = undefined; if (market !== undefined) { symbol = market['symbol']; const priceKey = 'price_' + market['quoteId']; - last = this.safeFloat (ticker, priceKey); + last = this.safeNumber (ticker, priceKey); const volumeKey = '24h_volume_' + market['quoteId']; - volume = this.safeFloat (ticker, volumeKey); + volume = this.safeNumber (ticker, volumeKey); } return { 'symbol': symbol, @@ -54302,13 +54096,14 @@ module.exports = class coinmarketcap extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],71:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],70:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder, OrderNotFound, RateLimitExceeded, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -54535,7 +54330,7 @@ module.exports = class coinmate extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -54563,12 +54358,12 @@ module.exports = class coinmate extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -54591,16 +54386,16 @@ module.exports = class coinmate extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'data'); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'vwap': undefined, 'askVolume': undefined, 'open': undefined, @@ -54610,7 +54405,7 @@ module.exports = class coinmate extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'amount'), + 'baseVolume': this.safeNumber (ticker, 'amount'), 'quoteVolume': undefined, 'info': ticker, }; @@ -54679,8 +54474,8 @@ module.exports = class coinmate extends Exchange { // } // const timestamp = this.safeInteger (item, 'timestamp'); - const amount = this.safeFloat (item, 'amount'); - const fee = this.safeFloat (item, 'fee'); + const amount = this.safeNumber (item, 'amount'); + const fee = this.safeNumber (item, 'fee'); const txid = this.safeString (item, 'txid'); const address = this.safeString (item, 'destination'); const tag = this.safeString (item, 'destinationTag'); @@ -54758,21 +54553,18 @@ module.exports = class coinmate extends Exchange { // const marketId = this.safeString (trade, 'currencyPair'); market = this.safeMarket (marketId, market, '_'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeStringLower2 (trade, 'type', 'tradeType'); const type = this.safeStringLower (trade, 'orderType'); const orderId = this.safeString (trade, 'orderId'); const id = this.safeString (trade, 'transactionId'); const timestamp = this.safeInteger2 (trade, 'timestamp', 'createdTimestamp'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -54913,11 +54705,11 @@ module.exports = class coinmate extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.safeInteger (order, 'timestamp'); const side = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'originalAmount'); - let remaining = this.safeFloat (order, 'remainingAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'originalAmount'); + let remaining = this.safeNumber (order, 'remainingAmount'); if (remaining === undefined) { - remaining = this.safeFloat (order, 'amount'); + remaining = this.safeNumber (order, 'amount'); } let status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.parseOrderType (this.safeString (order, 'orderTradeType')); @@ -54932,11 +54724,11 @@ module.exports = class coinmate extends Exchange { cost = filled * price; } } - const average = this.safeFloat (order, 'avgPrice'); + const average = this.safeNumber (order, 'avgPrice'); const marketId = this.safeString (order, 'currencyPair'); const symbol = this.safeSymbol (marketId, market, '_'); const clientOrderId = this.safeString (order, 'clientOrderId'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); return { 'id': id, 'clientOrderId': clientOrderId, @@ -55064,13 +54856,14 @@ module.exports = class coinmate extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],72:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],71:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, BadRequest, ExchangeError, ArgumentsRequired, OrderNotFound, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -55209,11 +55002,11 @@ module.exports = class coinone extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'avail'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -55266,13 +55059,13 @@ module.exports = class coinone extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const first = this.safeFloat (ticker, 'first'); - const last = this.safeFloat (ticker, 'last'); + const first = this.safeNumber (ticker, 'first'); + const last = this.safeNumber (ticker, 'last'); let average = undefined; if (first !== undefined && last !== undefined) { average = this.sum (first, last) / 2; } - const previousClose = this.safeFloat (ticker, 'yesterday_last'); + const previousClose = this.safeNumber (ticker, 'yesterday_last'); let change = undefined; let percentage = undefined; if (last !== undefined && previousClose !== undefined) { @@ -55286,8 +55079,8 @@ module.exports = class coinone extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -55300,7 +55093,7 @@ module.exports = class coinone extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -55346,20 +55139,17 @@ module.exports = class coinone extends Exchange { side = 'buy'; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'fee'); + let feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); - let feeRate = this.safeFloat (trade, 'feeRate'); + let feeRate = this.safeNumber (trade, 'feeRate'); feeRate = Math.abs (feeRate); let feeCurrencyCode = undefined; if (market !== undefined) { @@ -55519,7 +55309,7 @@ module.exports = class coinone extends Exchange { // } // const id = this.safeString (order, 'orderId'); - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); const timestamp = this.safeTimestamp (order, 'timestamp'); let side = this.safeString (order, 'type'); if (side === 'ask') { @@ -55527,9 +55317,8 @@ module.exports = class coinone extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const remaining = this.safeFloat (order, 'remainQty'); - let filled = undefined; - const amount = this.safeFloat (order, 'qty'); + const remaining = this.safeNumber (order, 'remainQty'); + const amount = this.safeNumber (order, 'qty'); let status = this.safeString (order, 'status'); // https://github.com/ccxt/ccxt/pull/7067 if (status === 'live') { @@ -55539,14 +55328,7 @@ module.exports = class coinone extends Exchange { } } } - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (amount - remaining); - } status = this.parseOrderStatus (status); - let cost = undefined; - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } let symbol = undefined; let base = undefined; let quote = undefined; @@ -55566,16 +55348,16 @@ module.exports = class coinone extends Exchange { quote = market['quote']; } let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = (side === 'sell') ? quote : base; fee = { 'cost': feeCost, - 'rate': this.safeFloat (order, 'feeRate'), + 'rate': this.safeNumber (order, 'feeRate'), 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -55589,15 +55371,15 @@ module.exports = class coinone extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': amount, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -55672,8 +55454,8 @@ module.exports = class coinone extends Exchange { // eslint-disable-next-line quotes throw new ArgumentsRequired (this.id + " cancelOrder() requires a symbol argument. To cancel the order, pass a symbol argument and {'price': 12345, 'qty': 1.2345, 'is_ask': 0} in the params argument of cancelOrder."); } - const price = this.safeFloat (params, 'price'); - const qty = this.safeFloat (params, 'qty'); + const price = this.safeNumber (params, 'price'); + const qty = this.safeNumber (params, 'qty'); const isAsk = this.safeInteger (params, 'is_ask'); if ((price === undefined) || (qty === undefined) || (isAsk === undefined)) { // eslint-disable-next-line quotes @@ -55748,13 +55530,14 @@ module.exports = class coinone extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],73:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],72:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -55874,7 +55657,7 @@ module.exports = class coinspot extends Exchange { const balance = currencies[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } } @@ -55884,11 +55667,11 @@ module.exports = class coinspot extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -55908,16 +55691,16 @@ module.exports = class coinspot extends Exchange { id = id.toLowerCase (); const ticker = response['prices'][id]; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -55965,11 +55748,13 @@ module.exports = class coinspot extends Exchange { // "market":"BTC/AUD" // } // - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'total'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger (trade, 'solddate'); const marketId = this.safeString (trade, 'market'); @@ -56037,13 +55822,15 @@ module.exports = class coinspot extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],74:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],73:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, InvalidNonce, RequestTimeout, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, AuthenticationError, BadSymbol } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -56150,6 +55937,7 @@ module.exports = class crex24 extends Exchange { ], }, }, + 'precisionMode': TICK_SIZE, 'fees': { 'trading': { 'tierBased': true, @@ -56170,6 +55958,7 @@ module.exports = class crex24 extends Exchange { 'BIT': 'BitMoney', 'BULL': 'BuySell', 'CREDIT': 'TerraCredit', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'GHOST': 'GHOSTPRISM', 'IQ': 'IQ.Cash', 'PUT': 'PutinCoin', @@ -56203,6 +55992,7 @@ module.exports = class crex24 extends Exchange { 'API Key': AuthenticationError, // "API Key '9edc48de-d5b0-4248-8e7e-f59ffcd1c7f1' doesn't exist." 'Insufficient funds': InsufficientFunds, // "Insufficient funds: new order requires 10 ETH which is more than the available balance." 'has been delisted.': BadSymbol, // {"errorDescription":"Instrument '$PAC-BTC' has been delisted."} + 'is currently suspended.': BadSymbol, // {"errorDescription":"Trading in BITG-BTC is currently suspended."} 'Mandatory parameter': BadRequest, // {"errorDescription":"Mandatory parameter 'feeCurrency' is missing."} }, }, @@ -56244,12 +56034,12 @@ module.exports = class crex24 extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const tickSize = this.safeValue (market, 'tickSize'); - const minPrice = this.safeValue (market, 'minPrice'); - const minAmount = this.safeFloat (market, 'minVolume'); + const tickSize = this.safeNumber (market, 'tickSize'); + const minPrice = this.safeNumber (market, 'minPrice'); + const minAmount = this.safeNumber (market, 'minVolume'); const precision = { - 'amount': this.precisionFromString (this.numberToString (minAmount)), - 'price': this.precisionFromString (this.numberToString (tickSize)), + 'amount': minAmount, + 'price': tickSize, }; const active = (market['state'] === 'active'); result.push ({ @@ -56314,7 +56104,8 @@ module.exports = class crex24 extends Exchange { const currency = response[i]; const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); - const precision = this.safeInteger (currency, 'withdrawalPrecision'); + const withdrawalPrecision = this.safeInteger (currency, 'withdrawalPrecision'); + const precision = Math.pow (10, -withdrawalPrecision); const address = this.safeValue (currency, 'BaseAddress'); const active = (currency['depositsAllowed'] && currency['withdrawalsAllowed'] && !currency['isDelisted']); const type = currency['isFiat'] ? 'fiat' : 'crypto'; @@ -56326,7 +56117,7 @@ module.exports = class crex24 extends Exchange { 'type': type, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'flatWithdrawalFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'flatWithdrawalFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -56342,12 +56133,12 @@ module.exports = class crex24 extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -56377,11 +56168,11 @@ module.exports = class crex24 extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -56433,16 +56224,16 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); const marketId = this.safeString (ticker, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -56450,10 +56241,10 @@ module.exports = class crex24 extends Exchange { 'last': last, 'previousClose': undefined, // previous day close 'change': undefined, - 'percentage': this.safeFloat (ticker, 'percentChange'), + 'percentage': this.safeNumber (ticker, 'percentChange'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -56523,14 +56314,6 @@ module.exports = class crex24 extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - parseTrade (trade, market = undefined) { // // public fetchTrades @@ -56555,14 +56338,11 @@ module.exports = class crex24 extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'orderId'); @@ -56571,7 +56351,7 @@ module.exports = class crex24 extends Exchange { let fee = undefined; const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCode = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -56632,11 +56412,11 @@ module.exports = class crex24 extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -56705,50 +56485,19 @@ module.exports = class crex24 extends Exchange { const marketId = this.safeString (order, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remainingVolume'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remainingVolume'); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'lastUpdate')); - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = amount - remaining; - if (this.options['parseOrderToPrecision']) { - filled = parseFloat (this.amountToPrecision (symbol, filled)); - } - filled = Math.max (filled, 0.0); - if (price !== undefined) { - cost = price * filled; - } - } - } const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeString (order, 'side'); const fee = undefined; const trades = undefined; - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const average = undefined; const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -56762,14 +56511,14 @@ module.exports = class crex24 extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -56804,7 +56553,7 @@ module.exports = class crex24 extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -57223,8 +56972,8 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'createdAt')); const updated = this.parse8601 (this.safeString (transaction, 'processedAt')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); const fee = { 'cost': feeCost, 'currency': code, @@ -57349,14 +57098,15 @@ module.exports = class crex24 extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],75:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],74:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -57444,6 +57194,7 @@ module.exports = class currencycom extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.002, @@ -57602,7 +57353,7 @@ module.exports = class currencycom extends Exchange { const filtersByType = this.indexBy (filters, 'filterType'); const precision = { 'amount': 1 / Math.pow (1, this.safeInteger (market, 'baseAssetPrecision')), - 'price': this.safeFloat (market, 'tickSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'TRADING'); @@ -57635,14 +57386,14 @@ module.exports = class currencycom extends Exchange { 'max': undefined, }, 'cost': { - 'min': -1 * Math.log10 (precision['amount']), + 'min': -Math.log10 (precision['amount']), 'max': undefined, }, }, }; - const exchangeFee = this.safeFloat2 (market, 'exchangeFee', 'tradingFee'); - const makerFee = this.safeFloat (market, 'makerFee', exchangeFee); - const takerFee = this.safeFloat (market, 'takerFee', exchangeFee); + const exchangeFee = this.safeNumber2 (market, 'exchangeFee', 'tradingFee'); + const makerFee = this.safeNumber (market, 'makerFee', exchangeFee); + const takerFee = this.safeNumber (market, 'takerFee', exchangeFee); if (makerFee !== undefined) { entry['maker'] = makerFee / 100; } @@ -57651,65 +57402,44 @@ module.exports = class currencycom extends Exchange { } if ('PRICE_FILTER' in filtersByType) { const filter = this.safeValue (filtersByType, 'PRICE_FILTER', {}); - entry['precision']['price'] = this.safeFloat (filter, 'tickSize'); + entry['precision']['price'] = this.safeNumber (filter, 'tickSize'); // PRICE_FILTER reports zero values for maxPrice // since they updated filter types in November 2018 // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } } if ('LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'LOT_SIZE', {}); - entry['precision']['amount'] = this.safeFloat (filter, 'stepSize'); + entry['precision']['amount'] = this.safeNumber (filter, 'stepSize'); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat (filter, 'minNotional'); + entry['limits']['cost']['min'] = this.safeNumber (filter, 'minNotional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { const response = await this.privateGetAccount (params); // @@ -57756,8 +57486,8 @@ module.exports = class currencycom extends Exchange { const response = await this.privateGetAccount (params); return { 'info': response, - 'maker': this.safeFloat (response, 'makerCommission'), - 'taker': this.safeFloat (response, 'takerCommission'), + 'maker': this.safeNumber (response, 'makerCommission'), + 'taker': this.safeNumber (response, 'takerCommission'), }; } @@ -57791,11 +57521,11 @@ module.exports = class currencycom extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -57894,8 +57624,8 @@ module.exports = class currencycom extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); - const open = this.safeFloat (ticker, 'openPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); let average = undefined; if ((open !== undefined) && (last !== undefined)) { average = this.sum (open, last) / 2; @@ -57904,22 +57634,22 @@ module.exports = class currencycom extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), 'open': open, 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -57954,14 +57684,6 @@ module.exports = class currencycom extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24hr (params); @@ -57994,11 +57716,11 @@ module.exports = class currencycom extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -58064,8 +57786,11 @@ module.exports = class currencycom extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -58081,7 +57806,7 @@ module.exports = class currencycom extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -58103,7 +57828,7 @@ module.exports = class currencycom extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': fee, }; } @@ -58179,66 +57904,21 @@ module.exports = class currencycom extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); + const remaining = undefined; + const cost = this.safeNumber (order, 'cummulativeQuoteQty'); const id = this.safeString (order, 'orderId'); const type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeStringLower (order, 'side'); - let fee = undefined; let trades = undefined; const fills = this.safeValue (order, 'fills'); if (fills !== undefined) { trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'timestamp': timestamp, @@ -58252,13 +57932,13 @@ module.exports = class currencycom extends Exchange { 'stopPrice': undefined, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -58470,7 +58150,7 @@ module.exports = class currencycom extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],76:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],75:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -58478,6 +58158,7 @@ module.exports = class currencycom extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, BadRequest, BadSymbol, InvalidOrder, AuthenticationError, ArgumentsRequired, OrderNotFound, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -58731,14 +58412,14 @@ module.exports = class delta extends Exchange { 'name': this.safeString (currency, 'name'), 'info': currency, // the original payload 'active': active, - 'fee': this.safeFloat (currency, 'base_withdrawal_fee'), + 'fee': this.safeNumber (currency, 'base_withdrawal_fee'), 'precision': 1 / Math.pow (10, precision), 'limits': { 'amount': { 'min': undefined, 'max': undefined }, 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal_amount'), + 'min': this.safeNumber (currency, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -58872,26 +58553,26 @@ module.exports = class delta extends Exchange { } const precision = { 'amount': 1.0, // number of contracts - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; const limits = { 'amount': { 'min': 1.0, - 'max': this.safeFloat (market, 'position_size_limit'), + 'max': this.safeNumber (market, 'position_size_limit'), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; const state = this.safeString (market, 'state'); const active = (state === 'live'); - const maker = this.safeFloat (market, 'maker_commission_rate'); - const taker = this.safeFloat (market, 'taker_commission_rate'); + const maker = this.safeNumber (market, 'maker_commission_rate'); + const taker = this.safeNumber (market, 'taker_commission_rate'); result.push ({ 'id': id, 'numericId': numericId, @@ -58939,8 +58620,8 @@ module.exports = class delta extends Exchange { const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.001); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; let percentage = undefined; @@ -58951,15 +58632,15 @@ module.exports = class delta extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'turnover'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'turnover'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -59129,12 +58810,11 @@ module.exports = class delta extends Exchange { const orderId = this.safeString (trade, 'order_id'); let timestamp = this.parse8601 (this.safeString (trade, 'created_at')); timestamp = this.safeIntegerProduct (trade, 'timestamp', 0.001, timestamp); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const product = this.safeValue (trade, 'product', {}); const marketId = this.safeString (product, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -59153,7 +58833,7 @@ module.exports = class delta extends Exchange { if (type !== undefined) { type = type.replace ('_order', ''); } - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { const settlingAsset = this.safeValue (product, 'settling_asset', {}); @@ -59220,11 +58900,11 @@ module.exports = class delta extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -59294,11 +58974,11 @@ module.exports = class delta extends Exchange { const currency = this.safeValue (currenciesByNumericId, currencyId); const code = (currency === undefined) ? currencyId : currency['code']; const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchPosition (symbol, params = undefined) { @@ -59322,7 +59002,7 @@ module.exports = class delta extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPositionsMargined (params); // @@ -59403,20 +59083,12 @@ module.exports = class delta extends Exchange { const side = this.safeString (order, 'side'); let type = this.safeString (order, 'order_type'); type = type.replace ('_order', ''); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'unfilled_size'); - let filled = undefined; - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let cost = undefined; - const average = this.safeFloat (order, 'average_fill_price'); - if ((average !== undefined) && filled) { - cost = average * filled; - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'unfilled_size'); + const average = this.safeNumber (order, 'average_fill_price'); let fee = undefined; - const feeCost = this.safeFloat (order, 'paid_commission'); + const feeCost = this.safeNumber (order, 'paid_commission'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -59429,7 +59101,7 @@ module.exports = class delta extends Exchange { 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -59441,14 +59113,14 @@ module.exports = class delta extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -59847,9 +59519,9 @@ module.exports = class delta extends Exchange { const currenciesByNumericId = this.safeValue (this.options, 'currenciesByNumericId'); currency = this.safeValue (currenciesByNumericId, currencyId, currency); const code = (currency === undefined) ? undefined : currency['code']; - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'created_at')); - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const before = Math.max (0, after - amount); const status = 'ok'; return { @@ -59955,7 +59627,7 @@ module.exports = class delta extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],77:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],76:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -59963,6 +59635,7 @@ module.exports = class delta extends Exchange { const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, ExchangeError, ArgumentsRequired, PermissionDenied, InvalidOrder, OrderNotFound, DDoSProtection, NotSupported, ExchangeNotAvailable, InsufficientFunds, BadRequest, InvalidAddress, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -60393,8 +60066,8 @@ module.exports = class deribit extends Exchange { const future = (type === 'future'); const option = (type === 'option'); const active = this.safeValue (market, 'is_active'); - const minTradeAmount = this.safeFloat (market, 'min_trade_amount'); - const tickSize = this.safeFloat (market, 'tick_size'); + const minTradeAmount = this.safeNumber (market, 'min_trade_amount'); + const tickSize = this.safeNumber (market, 'tick_size'); const precision = { 'amount': minTradeAmount, 'price': tickSize, @@ -60406,8 +60079,8 @@ module.exports = class deribit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_commission'), - 'maker': this.safeFloat (market, 'maker_commission'), + 'taker': this.safeNumber (market, 'taker_commission'), + 'maker': this.safeNumber (market, 'maker_commission'), 'limits': { 'amount': { 'min': minTradeAmount, @@ -60490,11 +60163,11 @@ module.exports = class deribit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const currencyCode = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableFunds'); - account['used'] = this.safeFloat (balance, 'maintenanceMargin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'maintenanceMargin'); + account['total'] = this.safeString (balance, 'equity'); result[currencyCode] = account; - return this.parseBalance (result); + return this.parseBalance (result, false); } async createDepositAddress (code, params = {}) { @@ -60612,18 +60285,18 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger2 (ticker, 'timestamp', 'creation_timestamp'); const marketId = this.safeString (ticker, 'instrument_name'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat2 (ticker, 'last_price', 'last'); + const last = this.safeNumber2 (ticker, 'last_price', 'last'); const stats = this.safeValue (ticker, 'stats', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (stats, 'high', 'max_price'), - 'low': this.safeFloat2 (stats, 'low', 'min_price'), - 'bid': this.safeFloat2 (ticker, 'best_bid_price', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_amount'), - 'ask': this.safeFloat2 (ticker, 'best_ask_price', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_amount'), + 'high': this.safeNumber2 (stats, 'high', 'max_price'), + 'low': this.safeNumber2 (stats, 'low', 'min_price'), + 'bid': this.safeNumber2 (ticker, 'best_bid_price', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_amount'), + 'ask': this.safeNumber2 (ticker, 'best_ask_price', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_amount'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -60633,7 +60306,7 @@ module.exports = class deribit extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (stats, 'volume'), + 'quoteVolume': this.safeNumber (stats, 'volume'), 'info': ticker, }; } @@ -60820,21 +60493,18 @@ module.exports = class deribit extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const liquidity = this.safeString (trade, 'liquidity'); let takerOrMaker = undefined; if (liquidity !== undefined) { // M = maker, T = taker, MT = both takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -61014,31 +60684,21 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger (order, 'creation_timestamp'); const lastUpdate = this.safeInteger (order, 'last_update_timestamp'); const id = this.safeString (order, 'order_id'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); let lastTradeTimestamp = undefined; if (filled !== undefined) { if (filled > 0) { lastTradeTimestamp = lastUpdate; } } - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = price * filled; - } - } const status = this.parseOrderStatus (this.safeString (order, 'order_state')); const marketId = this.safeString (order, 'instrument_name'); market = this.safeMarket (marketId, market); const side = this.safeStringLower (order, 'direction'); - let feeCost = this.safeFloat (order, 'commission'); + let feeCost = this.safeNumber (order, 'commission'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); @@ -61056,7 +60716,7 @@ module.exports = class deribit extends Exchange { const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); const stopPrice = this.safeValue (order, 'stop_price'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -61071,14 +60731,14 @@ module.exports = class deribit extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -61155,7 +60815,7 @@ module.exports = class deribit extends Exchange { } } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price or stopPrice param for a ' + type + ' order'); } else { @@ -61554,7 +61214,7 @@ module.exports = class deribit extends Exchange { const updated = this.safeInteger (transaction, 'updated_timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let type = 'deposit'; let fee = undefined; if (feeCost !== undefined) { @@ -61577,7 +61237,7 @@ module.exports = class deribit extends Exchange { 'tagTo': undefined, 'tagFrom': undefined, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -61623,7 +61283,7 @@ module.exports = class deribit extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.codeFromOptions ('fetchPositions'); const currency = this.currency (code); @@ -61744,13 +61404,14 @@ module.exports = class deribit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],78:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],77:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); -const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -61808,11 +61469,6 @@ module.exports = class digifinex extends Exchange { 'referral': 'https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp', }, 'api': { - 'v2': { - 'get': [ - 'ticker', - ], - }, 'public': { 'get': [ '{market}/symbols', @@ -61938,6 +61594,7 @@ module.exports = class digifinex extends Exchange { }, 'commonCurrencies': { 'BHT': 'Black House Test', + 'EPS': 'Epanus', 'MBN': 'Mobilian Coin', 'TEL': 'TEL666', }, @@ -61992,7 +61649,7 @@ module.exports = class digifinex extends Exchange { const depositStatus = this.safeValue (currency, 'deposit_status', 1); const withdrawStatus = this.safeValue (currency, 'withdraw_status', 1); const active = depositStatus && withdrawStatus; - const fee = this.safeFloat (currency, 'withdraw_fee_rate'); + const fee = this.safeNumber (currency, 'withdraw_fee_rate'); if (code in result) { if (Array.isArray (result[code]['info'])) { result[code]['info'].push (currency); @@ -62023,7 +61680,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw_amount'), + 'min': this.safeNumber (currency, 'min_withdraw_amount'), 'max': undefined, }, }, @@ -62077,7 +61734,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), 'max': undefined, }, 'price': { @@ -62085,7 +61742,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), + 'min': this.safeNumber (market, 'minimum_value'), 'max': undefined, }, }; @@ -62099,7 +61756,7 @@ module.exports = class digifinex extends Exchange { // const status = this.safeString (market, 'status'); // const active = (status === 'TRADING'); // - const isAllowed = this.safeValue (market, 'is_allow', 1); + const isAllowed = this.safeInteger (market, 'is_allow', 1); const active = isAllowed ? true : false; const type = 'spot'; const spot = (type === 'spot'); @@ -62155,7 +61812,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), + 'min': this.safeNumber (market, 'min_volume'), 'max': undefined, }, 'price': { @@ -62163,7 +61820,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, }; @@ -62208,12 +61865,12 @@ module.exports = class digifinex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -62247,87 +61904,67 @@ module.exports = class digifinex extends Exchange { } async fetchTickers (symbols = undefined, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTickers() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); - const request = { - 'apiKey': apiKey, - }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (params); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const result = {}; - const tickers = this.safeValue (response, 'ticker', {}); + const tickers = this.safeValue (response, 'ticker', []); const date = this.safeInteger (response, 'date'); - const reversedMarketIds = Object.keys (tickers); - for (let i = 0; i < reversedMarketIds.length; i++) { - const reversedMarketId = reversedMarketIds[i]; - const ticker = this.extend ({ + for (let i = 0; i < tickers.length; i++) { + const rawTicker = this.extend ({ 'date': date, - }, tickers[reversedMarketId]); - const [ quoteId, baseId ] = reversedMarketId.split ('_'); - const marketId = baseId.toUpperCase () + '_' + quoteId.toUpperCase (); - const market = this.safeMarket (marketId, undefined, '_'); - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); + }, tickers[i]); + const ticker = this.parseTicker (rawTicker); + const symbol = ticker['symbol']; + result[symbol] = ticker; } return this.filterByArray (result, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTicker() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); const market = this.market (symbol); - // reversed base/quote in v2 - const marketId = market['quoteId'].toLowerCase () + '_' + market['baseId'].toLowerCase (); const request = { - 'symbol': marketId, - 'apiKey': apiKey, + 'symbol': market['id'], }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (this.extend (request, params)); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const date = this.safeInteger (response, 'date'); - const ticker = this.safeValue (response, 'ticker', {}); - let result = this.safeValue (ticker, marketId, {}); - result = this.extend ({ 'date': date }, result); + const tickers = this.safeValue (response, 'ticker', []); + const firstTicker = this.safeValue (tickers, 0, {}); + const result = this.extend ({ 'date': date }, firstTicker); return this.parseTicker (result, market); } @@ -62337,6 +61974,7 @@ module.exports = class digifinex extends Exchange { // // { // "last":0.021957, + // "symbol": "btc_usdt", // "base_vol":2249.3521732227, // "change":-0.6, // "vol":102443.5111, @@ -62347,22 +61985,20 @@ module.exports = class digifinex extends Exchange { // "date"1564518452, // injected from fetchTicker/fetchTickers // } // - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeStringUpper (ticker, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -62372,8 +62008,8 @@ module.exports = class digifinex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'base_vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'base_vol'), 'info': ticker, }; } @@ -62409,18 +62045,15 @@ module.exports = class digifinex extends Exchange { const orderId = this.safeString (trade, 'order_id'); const timestamp = this.safeTimestamp2 (trade, 'date', 'timestamp'); const side = this.safeString2 (trade, 'type', 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); const takerOrMaker = this.safeValue (trade, 'is_maker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -62522,11 +62155,11 @@ module.exports = class digifinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 5), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 1), // volume + this.safeNumber (ohlcv, 5), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 1), // volume ]; } @@ -62717,21 +62350,11 @@ module.exports = class digifinex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_price'); - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - return { + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -62747,13 +62370,13 @@ module.exports = class digifinex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'average': average, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -62947,7 +62570,7 @@ module.exports = class digifinex extends Exchange { const code = this.safeCurrencyCode (this.safeString (item, 'currency_mark'), currency); const timestamp = this.safeTimestamp (item, 'time'); const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -63010,16 +62633,6 @@ module.exports = class digifinex extends Exchange { return this.parseLedger (items, currency, since, limit); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -63172,8 +62785,8 @@ module.exports = class digifinex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_date')); const updated = this.parse8601 (this.safeString (transaction, 'finished_date')); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -63223,7 +62836,7 @@ module.exports = class digifinex extends Exchange { } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const version = (api === 'v2') ? api : this.version; + const version = this.version; let url = this.urls['api'] + '/' + version + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); const urlencoded = this.urlencode (this.keysort (query)); @@ -63275,1283 +62888,7 @@ module.exports = class digifinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],79:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, BadRequest, InsufficientFunds, PermissionDenied, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class dsx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'dsx', - 'name': 'DSX', - 'countries': [ 'UK' ], - 'rateLimit': 1500, - 'version': 'v3', - 'has': { - 'cancelOrder': true, - 'CORS': false, - 'createDepositAddress': true, - 'createMarketOrder': false, - 'createOrder': true, - 'fetchBalance': true, - 'fetchClosedOrders': false, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOHLCV': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchOrderBooks': true, - 'fetchOrders': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTransactions': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg', - 'api': { - 'public': 'https://dsxglobal.com/mapi', // market data - 'private': 'https://dsxglobal.com/tapi', // trading - 'dwapi': 'https://dsxglobal.com/dwapi', // deposit/withdraw - }, - 'www': 'https://dsxglobal.com', - 'doc': [ - 'https://dsxglobal.com/developers/publicApi', - ], - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'maker': 0.15 / 100, - 'taker': 0.25 / 100, - }, - }, - 'timeframes': { - '1m': 'm', - '1h': 'h', - '1d': 'd', - }, - 'api': { - // market data (public) - 'public': { - 'get': [ - 'barsFromMoment/{pair}/{period}/{start}', - 'depth/{pair}', - 'info', - 'lastBars/{pair}/{period}/{amount}', // period is 'm', 'h' or 'd' - 'periodBars/{pair}/{period}/{start}/{end}', - 'ticker/{pair}', - 'trades/{pair}', - ], - }, - // trading (private) - 'private': { - 'post': [ - 'info/account', - 'history/transactions', - 'history/trades', - 'history/orders', - 'orders', - 'order/cancel', - // 'order/cancel/all', - 'order/status', - 'order/new', - 'volume', - 'fees', // trading fee schedule - ], - }, - // deposit / withdraw (private) - 'dwapi': { - 'post': [ - 'deposit/cryptoaddress', - 'withdraw/crypto', - 'withdraw/fiat', - 'withdraw/submit', - // 'withdraw/cancel', - 'transaction/status', // see 'history/transactions' in private tapi above - ], - }, - }, - 'exceptions': { - 'exact': { - 'Sign is invalid': AuthenticationError, // {"success":0,"error":"Sign is invalid"} - 'Order was rejected. Incorrect price.': InvalidOrder, // {"success":0,"error":"Order was rejected. Incorrect price."} - "Order was rejected. You don't have enough money.": InsufficientFunds, // {"success":0,"error":"Order was rejected. You don't have enough money."} - 'This method is blocked for your pair of keys': PermissionDenied, // {"success":0,"error":"This method is blocked for your pair of keys"} - }, - 'broad': { - 'INVALID_PARAMETER': BadRequest, - 'Invalid pair name': ExchangeError, // {"success":0,"error":"Invalid pair name: btc_eth"} - 'invalid api key': AuthenticationError, - 'invalid sign': AuthenticationError, - 'api key dont have trade permission': AuthenticationError, - 'invalid parameter': InvalidOrder, - 'invalid order': InvalidOrder, - 'Requests too often': DDoSProtection, - 'not available': ExchangeNotAvailable, - 'data unavailable': ExchangeNotAvailable, - 'external service unavailable': ExchangeNotAvailable, - 'nonce is invalid': InvalidNonce, // {"success":0,"error":"Parameter: nonce is invalid"} - 'Incorrect volume': InvalidOrder, // {"success": 0,"error":"Order was rejected. Incorrect volume."} - }, - }, - 'options': { - 'fetchTickersMaxLength': 250, - }, - 'commonCurrencies': { - 'DSH': 'DASH', - }, - }); - } - - async fetchMarkets (params = {}) { - const response = await this.publicGetInfo (params); - // - // { - // "server_time": 1522057909, - // "pairs": { - // "ethusd": { - // "decimal_places": 5, - // "min_price": 100, - // "max_price": 1500, - // "min_amount": 0.01, - // "hidden": 0, - // "fee": 0, - // "amount_decimal_places": 4, - // "quoted_currency": "USD", - // "base_currency": "ETH" - // } - // } - // } - // - const markets = this.safeValue (response, 'pairs'); - const keys = Object.keys (markets); - const result = []; - for (let i = 0; i < keys.length; i++) { - const id = keys[i]; - const market = markets[id]; - const baseId = this.safeString (market, 'base_currency'); - const quoteId = this.safeString (market, 'quoted_currency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const precision = { - 'amount': this.safeInteger (market, 'decimal_places'), - 'price': this.safeInteger (market, 'decimal_places'), - }; - const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), - }; - const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), - }; - const costLimits = { - 'min': this.safeFloat (market, 'min_total'), - }; - const limits = { - 'amount': amountLimits, - 'price': priceLimits, - 'cost': costLimits, - }; - const hidden = this.safeInteger (market, 'hidden'); - const active = (hidden === 0); - // see parseMarket below - // https://github.com/ccxt/ccxt/pull/5786 - const otherId = base.toLowerCase () + quote.toLowerCase (); - result.push ({ - 'id': id, - 'otherId': otherId, // https://github.com/ccxt/ccxt/pull/5786 - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': active, - 'precision': precision, - 'limits': limits, - 'info': market, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostInfoAccount (); - // - // { - // "success" : 1, - // "return" : { - // "funds" : { - // "BTC" : { - // "total" : 0, - // "available" : 0 - // }, - // "USD" : { - // "total" : 0, - // "available" : 0 - // }, - // "USDT" : { - // "total" : 0, - // "available" : 0 - // } - // }, - // "rights" : { - // "info" : 1, - // "trade" : 1 - // }, - // "transactionCount" : 0, - // "openOrders" : 0, - // "serverTime" : 1537451465 - // } - // } - // - const balances = this.safeValue (response, 'return'); - const result = { 'info': response }; - const funds = this.safeValue (balances, 'funds'); - const currencyIds = Object.keys (funds); - for (let i = 0; i < currencyIds.length; i++) { - const currencyId = currencyIds[i]; - const code = this.safeCurrencyCode (currencyId); - const balance = this.safeValue (funds, currencyId, {}); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseTicker (ticker, market = undefined) { - // - // { high: 0.03492, - // low: 0.03245, - // avg: 29.46133, - // vol: 500.8661, - // vol_cur: 17.000797104, - // last: 0.03364, - // buy: 0.03362, - // sell: 0.03381, - // updated: 1537521993, - // pair: "ethbtc" } - // - const timestamp = this.safeTimestamp (ticker, 'updated'); - let symbol = undefined; - const marketId = this.safeString (ticker, 'pair'); - market = this.parseMarket (marketId); - if (market !== undefined) { - symbol = market['symbol']; - } - // dsx average is inverted, liqui average is not - let average = this.safeFloat (ticker, 'avg'); - if (average !== undefined) { - if (average > 0) { - average = 1 / average; - } - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_cur'), - 'info': ticker, - }; - } - - parseTrade (trade, market = undefined) { - // - // fetchTrades (public) - // - // { - // "amount" : 0.0128, - // "price" : 6483.99000, - // "timestamp" : 1540334614, - // "tid" : 35684364, - // "type" : "ask" - // } - // - // fetchMyTrades (private) - // - // { - // "number": "36635882", // <-- this is present if the trade has come from the '/order/status' call - // "id": "36635882", // <-- this may have been artifically added by the parseTrades method - // "pair": "btcusd", - // "type": "buy", - // "volume": 0.0595, - // "rate": 9750, - // "orderId": 77149299, - // "timestamp": 1519612317, - // "commission": 0.00020825, - // "commissionCurrency": "btc" - // } - // - const timestamp = this.safeTimestamp (trade, 'timestamp'); - let side = this.safeString (trade, 'type'); - if (side === 'ask') { - side = 'sell'; - } else if (side === 'bid') { - side = 'buy'; - } - const price = this.safeFloat2 (trade, 'rate', 'price'); - const id = this.safeString2 (trade, 'number', 'id'); - const orderId = this.safeString (trade, 'orderId'); - const marketId = this.safeString (trade, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const amount = this.safeFloat2 (trade, 'amount', 'volume'); - const type = 'limit'; // all trades are still limit trades - let takerOrMaker = undefined; - let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const isYourOrder = this.safeValue (trade, 'is_your_order'); - if (isYourOrder !== undefined) { - takerOrMaker = 'taker'; - if (isYourOrder) { - takerOrMaker = 'maker'; - } - if (fee === undefined) { - fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); - } - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - return { - 'id': id, - 'order': orderId, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': type, - 'side': side, - 'takerOrMaker': takerOrMaker, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - 'info': trade, - }; - } - - parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - let result = []; - if (Array.isArray (trades)) { - for (let i = 0; i < trades.length; i++) { - result.push (this.parseTrade (trades[i], market)); - } - } else { - const ids = Object.keys (trades); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const trade = this.parseTrade (trades[id], market); - result.push (this.extend (trade, { 'id': id }, params)); - } - } - result = this.sortBy (result, 'timestamp'); - const symbol = (market !== undefined) ? market['symbol'] : undefined; - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const market_id_in_reponse = (market['id'] in response); - if (!market_id_in_reponse) { - throw new ExchangeError (this.id + ' ' + market['symbol'] + ' order book is empty or not available'); - } - const orderbook = response[market['id']]; - return this.parseOrderBook (orderbook); - } - - async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let ids = undefined; - if (symbols === undefined) { - ids = this.ids.join ('-'); - // max URL length is 2083 symbols, including http schema, hostname, tld, etc... - if (ids.length > 2048) { - const numIds = this.ids.length; - throw new ExchangeError (this.id + ' has ' + numIds.toString () + ' symbols exceeding max URL length, you are required to specify a list of symbols in the first argument to fetchOrderBooks'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const result = {}; - ids = Object.keys (response); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let symbol = id; - if (id in this.markets_by_id) { - const market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseOrderBook (response[id]); - } - return result; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - let ids = this.ids; - if (symbols === undefined) { - const numIds = ids.length; - ids = ids.join ('-'); - const maxLength = this.safeInteger (this.options, 'fetchTickersMaxLength', 2048); - // max URL length is 2048 symbols, including http schema, hostname, tld, etc... - if (ids.length > this.options['fetchTickersMaxLength']) { - throw new ArgumentsRequired (this.id + ' has ' + numIds.toString () + ' markets exceeding max URL length for this endpoint (' + maxLength.toString () + ' characters), please, specify a list of symbols of interest in the first argument to fetchTickers'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - const tickers = await this.publicGetTickerPair (this.extend (request, params)); - // - // { - // "bchbtc" : { - // "high" : 0.02989, - // "low" : 0.02736, - // "avg" : 33.90585, - // "vol" : 0.65982205, - // "vol_cur" : 0.0194604180960, - // "last" : 0.03000, - // "buy" : 0.02980, - // "sell" : 0.03001, - // "updated" : 1568104614, - // "pair" : "bchbtc" - // }, - // "ethbtc" : { - // "high" : 0.01772, - // "low" : 0.01742, - // "avg" : 56.89082, - // "vol" : 229.247115044, - // "vol_cur" : 4.02959737298943, - // "last" : 0.01769, - // "buy" : 0.01768, - // "sell" : 0.01776, - // "updated" : 1568104614, - // "pair" : "ethbtc" - // } - // } - // - const result = {}; - const keys = Object.keys (tickers); - for (let k = 0; k < keys.length; k++) { - const id = keys[k]; - const ticker = tickers[id]; - let symbol = id; - let market = undefined; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseTicker (ticker, market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - const tickers = await this.fetchTickers ([ symbol ], params); - return tickers[symbol]; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; - } - const response = await this.publicGetTradesPair (this.extend (request, params)); - if (Array.isArray (response)) { - const numElements = response.length; - if (numElements === 0) { - return []; - } - } - return this.parseTrades (response[market['id']], market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // } - // - return [ - this.safeInteger (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - 'period': this.timeframes[timeframe], - }; - let method = 'publicGetLastBarsPairPeriodAmount'; - if (since === undefined) { - if (limit === undefined) { - limit = 100; // required, max 2000 - } - request['amount'] = limit; - } else { - method = 'publicGetPeriodBarsPairPeriodStartEnd'; - // in their docs they expect milliseconds - // but it returns empty arrays with milliseconds - // however, it does work properly with seconds - request['start'] = parseInt (since / 1000); - if (limit === undefined) { - request['end'] = this.seconds (); - } else { - const duration = this.parseTimeframe (timeframe) * 1000; - const end = this.sum (since, duration * limit); - request['end'] = parseInt (end / 1000); - } - } - const response = await this[method] (this.extend (request, params)); - // - // { - // "ethbtc": [ - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // }, - // { - // "high" : 0.01967, - // "open" : 0.01967, - // "low" : 0.01967, - // "close" : 0.01967, - // "amount" : 0, - // "timestamp" : 1565155680000 - // } - // ] - // } - // - const candles = this.safeValue (response, market['id'], []); - return this.parseOHLCVs (candles, market, timeframe, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (type === 'market' && price === undefined) { - throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument even for market orders, that is the worst price that you agree to fill your order for'); - } - const request = { - 'pair': market['id'], - 'type': side, - 'volume': this.amountToPrecision (symbol, amount), - 'rate': this.priceToPrecision (symbol, price), - 'orderType': type, - }; - price = parseFloat (price); - amount = parseFloat (amount); - const response = await this.privatePostOrderNew (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "received": 0, - // "remains": 10, - // "funds": { - // "BTC": { - // "total": 100, - // "available": 95 - // }, - // "USD": { - // "total": 10000, - // "available": 9995 - // }, - // "EUR": { - // "total": 1000, - // "available": 995 - // }, - // "LTC": { - // "total": 1000, - // "available": 995 - // } - // }, - // "orderId": 0, // https://github.com/ccxt/ccxt/issues/3677 - // } - // } - // - let status = 'open'; - let filled = 0.0; - let remaining = amount; - const responseReturn = this.safeValue (response, 'return'); - let id = this.safeString2 (responseReturn, 'orderId', 'order_id'); - if (id === '0') { - id = this.safeString (responseReturn, 'initOrderId', 'init_order_id'); - status = 'closed'; - } - filled = this.safeFloat (responseReturn, 'received', 0.0); - remaining = this.safeFloat (responseReturn, 'remains', amount); - const timestamp = this.milliseconds (); - return { - 'info': response, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'side': side, - 'price': price, - 'cost': price * filled, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'fee': undefined, - // 'trades': this.parseTrades (order['trades'], market), - }; - } - - parseOrderStatus (status) { - const statuses = { - '0': 'open', // Active - '1': 'closed', // Filled - '2': 'canceled', // Killed - '3': 'canceling', // Killing - '7': 'canceled', // Rejected - }; - return this.safeString (statuses, status, status); - } - - parseMarket (id) { - if (id in this.markets_by_id) { - return this.markets_by_id[id]; - } else { - // the following is a fix for - // https://github.com/ccxt/ccxt/pull/5786 - // https://github.com/ccxt/ccxt/issues/5770 - let markets_by_other_id = this.safeValue (this.options, 'markets_by_other_id'); - if (markets_by_other_id === undefined) { - this.options['markets_by_other_id'] = this.indexBy (this.markets, 'otherId'); - markets_by_other_id = this.options['markets_by_other_id']; - } - if (id in markets_by_other_id) { - return markets_by_other_id[id]; - } - } - return undefined; - } - - parseOrder (order, market = undefined) { - // - // fetchOrder - // - // { - // "number": 36635882, - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // - const id = this.safeString (order, 'id'); - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const timestamp = this.safeTimestamp (order, 'timestampCreated'); - const marketId = this.safeString (order, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const remaining = this.safeFloat (order, 'remainingVolume'); - const amount = this.safeFloat (order, 'volume'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } - } - const orderType = this.safeString (order, 'orderType'); - const side = this.safeString (order, 'type'); - let fee = undefined; - const deals = this.safeValue (order, 'deals', []); - const numDeals = deals.length; - let trades = undefined; - let lastTradeTimestamp = undefined; - if (numDeals > 0) { - trades = this.parseTrades (deals); - let feeCost = undefined; - let feeCurrency = undefined; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - if (feeCost === undefined) { - feeCost = 0; - } - feeCost = this.sum (feeCost, trade['fee']['cost']); - feeCurrency = trade['fee']['currency']; - lastTradeTimestamp = trade['timestamp']; - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'type': orderType, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': undefined, - 'cost': cost, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'status': status, - 'fee': fee, - 'trades': trades, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': parseInt (id), - }; - const response = await this.privatePostOrderStatus (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // } - // - return this.parseOrder (this.extend ({ - 'id': id, - }, response['return'])); - } - - parseOrdersById (orders, symbol = undefined, since = undefined, limit = undefined) { - const ids = Object.keys (orders); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.parseOrder (this.extend ({ - 'id': id.toString (), - }, orders[id])); - result.push (order); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - const response = await this.privatePostOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': id, - }; - const response = await this.privatePostOrderCancel (this.extend (request, params)); - return response; - } - - parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { - const result = []; - const ids = Object.keys (orders); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.extend ({ 'id': id }, orders[id]); - result.push (this.extend (this.parseOrder (order, market), params)); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - const orders = await this.fetchOrders (symbol, since, limit, params); - return this.filterBy (orders, 'status', 'closed'); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let market = undefined; - // some derived classes use camelcase notation for request fields - const request = { - // 'from': 123456789, // trade ID, from which the display starts numerical 0 (test result: liqui ignores this field) - // 'count': 1000, // the number of trades for display numerical, default = 1000 - // 'from_id': trade ID, from which the display starts numerical 0 - // 'end_id': trade ID on which the display ends numerical ∞ - // 'order': 'ASC', // sorting, default = DESC (test result: liqui ignores this field, most recent trade always goes last) - // 'since': 1234567890, // UTC start time, default = 0 (test result: liqui ignores this field) - // 'end': 1234567890, // UTC end time, default = ∞ (test result: liqui ignores this field) - // 'pair': 'eth_btc', // default = all markets - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['pair'] = market['id']; - } - if (limit !== undefined) { - request['count'] = parseInt (limit); - } - if (since !== undefined) { - request['since'] = parseInt (since / 1000); - } - const response = await this.privatePostHistoryTrades (this.extend (request, params)); - let trades = []; - if ('return' in response) { - trades = response['return']; - } - return this.parseTrades (trades, market, since, limit); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let currency = undefined; - const request = {}; - if (code !== undefined) { - currency = this.currency (code); - request['currency'] = currency['id']; - } - if (since !== undefined) { - request['since'] = since; - } - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryTransactions (this.extend (request, params)); - // - // { - // "success": 1, - // "return": [ - // { - // "id": 1, - // "timestamp": 11, - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // ] - // } - // - const transactions = this.safeValue (response, 'return', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - '1': 'failed', - '2': 'ok', - '3': 'pending', - '4': 'failed', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // "id": 1, - // "timestamp": 11, // 11 in their docs ( - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // - const timestamp = this.safeTimestamp (transaction, 'timestamp'); - let type = this.safeString (transaction, 'type'); - if (type !== undefined) { - if (type === 'Incoming') { - type = 'deposit'; - } else if (type === 'Withdraw') { - type = 'withdrawal'; - } - } - const currencyId = this.safeString (transaction, 'currency'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - return { - 'id': this.safeString (transaction, 'id'), - 'txid': this.safeString (transaction, 'txid'), - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'address': this.safeString (transaction, 'address'), - 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), - 'currency': code, - 'status': status, - 'fee': { - 'currency': code, - 'cost': this.safeFloat (transaction, 'commission'), - 'rate': undefined, - }, - 'info': transaction, - }; - } - - async createDepositAddress (code, params = {}) { - const request = { - 'new': 1, - }; - const response = await this.fetchDepositAddress (code, this.extend (request, params)); - return response; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency': currency['id'], - }; - const response = await this.dwapiPostDepositCryptoaddress (this.extend (request, params)); - const result = this.safeValue (response, 'return', {}); - const address = this.safeString (result, 'address'); - this.checkAddress (address); - return { - 'currency': code, - 'address': address, - 'tag': undefined, // not documented in DSX API - 'info': response, - }; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - const commission = this.safeValue (params, 'commission'); - if (commission === undefined) { - throw new ArgumentsRequired (this.id + ' withdraw() requires a `commission` (withdrawal fee) parameter (string)'); - } - params = this.omit (params, commission); - const request = { - 'currency': currency['id'], - 'amount': parseFloat (amount), - 'address': address, - 'commission': commission, - }; - if (tag !== undefined) { - request['address'] += ':' + tag; - } - const response = await this.dwapiPostWithdrawCrypto (this.extend (request, params)); - // - // [ - // { - // "success": 1, - // "return": { - // "transactionId": 2863073 - // } - // } - // ] - // - const data = this.safeValue (response, 'return', {}); - const id = this.safeString (data, 'transactionId'); - return { - 'info': response, - 'id': id, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'][api]; - const query = this.omit (params, this.extractParams (path)); - if (api === 'private' || api === 'dwapi') { - url += '/' + this.version + '/' + this.implodeParams (path, params); - this.checkRequiredCredentials (); - const nonce = this.nonce (); - body = this.urlencode (this.extend ({ - 'nonce': nonce, - }, query)); - const signature = this.hmac (this.encode (body), this.encode (this.secret), 'sha512', 'base64'); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': signature, - }; - } else if (api === 'public') { - url += '/' + this.implodeParams (path, params); - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - url += '/' + this.implodeParams (path, params); - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - if (Object.keys (query).length) { - body = this.json (query); - headers = { - 'Content-Type': 'application/json', - }; - } - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - if ('success' in response) { - // - // 1 - Liqui only returns the integer 'success' key from their private API - // - // { "success": 1, ... } httpCode === 200 - // { "success": 0, ... } httpCode === 200 - // - // 2 - However, exchanges derived from Liqui, can return non-integers - // - // It can be a numeric string - // { "sucesss": "1", ... } - // { "sucesss": "0", ... }, httpCode >= 200 (can be 403, 502, etc) - // - // Or just a string - // { "success": "true", ... } - // { "success": "false", ... }, httpCode >= 200 - // - // Or a boolean - // { "success": true, ... } - // { "success": false, ... }, httpCode >= 200 - // - // 3 - Oversimplified, Python PEP8 forbids comparison operator (===) of different types - // - // 4 - We do not want to copy-paste and duplicate the code of this handler to other exchanges derived from Liqui - // - // To cover points 1, 2, 3 and 4 combined this handler should work like this: - // - let success = this.safeValue (response, 'success', false); - if (typeof success === 'string') { - if ((success === 'true') || (success === '1')) { - success = true; - } else { - success = false; - } - } - if (!success) { - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'error'); - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],80:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],78:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -64775,7 +63112,7 @@ module.exports = class equos extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeVol'), + 'min': this.safeNumber (market, 'minTradeVol'), 'max': undefined, }, 'price': { @@ -64841,7 +63178,7 @@ module.exports = class equos extends Exchange { const name = this.safeString (currency, 6); const status = this.safeInteger (currency, 4); const active = (status === 1); - const fee = this.safeFloat (currency, 5); // withdraw_fee + const fee = this.safeNumber (currency, 5); // withdraw_fee return { 'id': id, 'info': currency, @@ -64933,8 +63270,8 @@ module.exports = class equos extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); return [ this.convertFromScale (price, market['precision']['price']), this.convertFromScale (amount, market['precision']['amount']), @@ -65080,9 +63417,9 @@ module.exports = class equos extends Exchange { orderId = this.safeString (trade, 'orderId'); side = this.safeStringLower (trade, 'side'); type = this.parseOrderType (this.safeString (trade, 'ordType')); - price = this.safeFloat (trade, 'lastPx'); - amount = this.safeFloat (trade, 'quoteQty'); - let feeCost = this.safeFloat (trade, 'commission'); + price = this.safeNumber (trade, 'lastPx'); + amount = this.safeNumber (trade, 'quoteQty'); + let feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { feeCost = -feeCost; const feeCurrencyId = this.safeString (trade, 'commCurrency'); @@ -65153,8 +63490,8 @@ module.exports = class equos extends Exchange { if (assetType === 'ASSET') { const currencyId = this.safeString (position, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const quantity = this.safeFloat (position, 'quantity'); - const availableQuantity = this.safeFloat (position, 'availableQuantity'); + const quantity = this.safeNumber (position, 'quantity'); + const availableQuantity = this.safeNumber (position, 'availableQuantity'); const scale = this.safeInteger (position, 'quantity_scale'); const account = this.account (); account['free'] = this.convertFromScale (availableQuantity, scale); @@ -65200,7 +63537,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -65297,7 +63634,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -65670,7 +64007,7 @@ module.exports = class equos extends Exchange { address = undefined; } const type = this.safeString (transaction, 'type'); - let amount = this.safeFloat (transaction, 'balance_change'); + let amount = this.safeNumber (transaction, 'balance_change'); if (amount === undefined) { amount = this.safeInteger (transaction, 'quantity'); const amountScale = this.safeInteger (transaction, 'quantity_scale'); @@ -65753,8 +64090,8 @@ module.exports = class equos extends Exchange { for (let i = 0; i < tradingFees.length; i++) { const tradingFee = tradingFees[i]; if (this.safeString (tradingFee, 'tier') !== undefined) { - taker[tradingFee['tier']] = this.safeFloat (tradingFee, 'taker'); - maker[tradingFee['tier']] = this.safeFloat (tradingFee, 'maker'); + taker[tradingFee['tier']] = this.safeNumber (tradingFee, 'taker'); + maker[tradingFee['tier']] = this.safeNumber (tradingFee, 'maker'); } } return { @@ -65885,28 +64222,6 @@ module.exports = class equos extends Exchange { let remaining = this.safeInteger (order, 'leavesQty'); const remainingScale = this.safeInteger (order, 'leavesQty_scale'); remaining = this.convertFromScale (remaining, remainingScale); - if (remaining <= 0) { - if ((filled !== undefined) && (amount !== undefined) && (filled < amount)) { - remaining = undefined; - } - } - if ((remaining === undefined) && (amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0); - } - let average = this.safeInteger (order, 'price', 0); - if (average === 0) { - average = undefined; - } - const averageScale = this.safeInteger (order, 'price_scale'); - average = this.convertFromScale (average, averageScale); - let cost = undefined; - if (filled !== 0) { - if (average > 0) { - cost = average * filled; - } else if (price > 0) { - cost = price * filled; - } - } let fee = undefined; const currencyId = this.safeInteger (order, 'feeInstrumentId'); const feeCurrencyCode = this.safeCurrencyCode (currencyId); @@ -65929,7 +64244,7 @@ module.exports = class equos extends Exchange { } const stopPriceScale = this.safeInteger (order, 'stopPx_scale', 0); const stopPrice = this.convertFromScale (this.safeInteger (order, 'stopPx'), stopPriceScale); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -65944,14 +64259,14 @@ module.exports = class equos extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -66101,7 +64416,7 @@ module.exports = class equos extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],81:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],79:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -66109,6 +64424,7 @@ module.exports = class equos extends Exchange { const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, InvalidOrder, ExchangeError, BadRequest, BadSymbol } = require ('./base/errors'); const { TRUNCATE, SIGNIFICANT_DIGITS } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -66321,7 +64637,7 @@ module.exports = class eterbase extends Exchange { const rule = rules[i]; const attribute = this.safeString (rule, 'attribute'); const condition = this.safeString (rule, 'condition'); - const value = this.safeFloat (rule, 'value'); + const value = this.safeNumber (rule, 'value'); if ((attribute === 'Qty') && (condition === 'Min')) { minAmount = value; } else if ((attribute === 'Qty') && (condition === 'Max')) { @@ -66411,7 +64727,7 @@ module.exports = class eterbase extends Exchange { 'type': type, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -66427,8 +64743,8 @@ module.exports = class eterbase extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMin'), - 'max': this.safeFloat (currency, 'withdrawalMax'), + 'min': this.safeNumber (currency, 'withdrawalMin'), + 'max': this.safeNumber (currency, 'withdrawalMax'), }, }, }; @@ -66455,17 +64771,17 @@ module.exports = class eterbase extends Exchange { const marketId = this.safeString (ticker, 'marketId'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const last = this.safeFloat (ticker, 'price'); - const baseVolume = this.safeFloat (ticker, 'volumeBase'); - const quoteVolume = this.safeFloat (ticker, 'volume'); + const last = this.safeNumber (ticker, 'price'); + const baseVolume = this.safeNumber (ticker, 'volumeBase'); + const quoteVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const percentage = this.safeFloat (ticker, 'change'); + const percentage = this.safeNumber (ticker, 'change'); const result = { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -66507,14 +64823,6 @@ module.exports = class eterbase extends Exchange { return this.parseTicker (response, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { @@ -66569,10 +64877,12 @@ module.exports = class eterbase extends Exchange { // "filledAt": 1556355722341 // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -66581,9 +64891,9 @@ module.exports = class eterbase extends Exchange { 'currency': feeCurrencyCode, }; } - let cost = this.safeFloat (trade, 'qty'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + let cost = this.safeNumber (trade, 'qty'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger2 (trade, 'executedAt', 'filledAt'); const tradeSide = this.safeString (trade, 'side'); @@ -66681,11 +64991,11 @@ module.exports = class eterbase extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -66748,14 +65058,13 @@ module.exports = class eterbase extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetId'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'reserved'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -66882,18 +65191,18 @@ module.exports = class eterbase extends Exchange { } else { type = 'stoplimit'; } - let price = this.safeFloat (order, 'limitPrice'); - const amount = this.safeFloat (order, 'qty'); - let remaining = this.safeFloat (order, 'remainingQty'); + let price = this.safeNumber (order, 'limitPrice'); + const amount = this.safeNumber (order, 'qty'); + let remaining = this.safeNumber (order, 'remainingQty'); let filled = undefined; - const remainingCost = this.safeFloat (order, 'remainingCost'); + const remainingCost = this.safeNumber (order, 'remainingCost'); if ((remainingCost !== undefined) && (remainingCost === 0.0)) { remaining = 0; } if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); } - const cost = this.safeFloat (order, 'cost'); + const cost = this.safeNumber (order, 'cost'); if (type === 'market') { if (price === 0.0) { if ((cost !== undefined) && (filled !== undefined)) { @@ -66910,7 +65219,7 @@ module.exports = class eterbase extends Exchange { } } const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -67083,7 +65392,7 @@ module.exports = class eterbase extends Exchange { } if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) { // for market buy it requires the amount of quote currency to spend - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); if (this.options['createMarketBuyOrderRequiresPrice']) { if (cost === undefined) { if (price !== undefined) { @@ -67246,7 +65555,7 @@ module.exports = class eterbase extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],82:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],80:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -67361,6 +65670,7 @@ module.exports = class exmo extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.2 / 100, @@ -67830,18 +66140,18 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = marketId.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const maxAmount = this.safeFloat (limit, 'max_q'); - const maxPrice = this.safeFloat (limit, 'max_p'); - const maxCost = this.safeFloat (limit, 'max_a'); - const minAmount = this.safeFloat (limit, 'min_q'); - const minPrice = this.safeFloat (limit, 'min_p'); - const minCost = this.safeFloat (limit, 'min_a'); - minAmounts[base] = Math.min (this.safeFloat (minAmounts, base, minAmount), minAmount); - maxAmounts[base] = Math.max (this.safeFloat (maxAmounts, base, maxAmount), maxAmount); - minPrices[quote] = Math.min (this.safeFloat (minPrices, quote, minPrice), minPrice); - minCosts[quote] = Math.min (this.safeFloat (minCosts, quote, minCost), minCost); - maxPrices[quote] = Math.max (this.safeFloat (maxPrices, quote, maxPrice), maxPrice); - maxCosts[quote] = Math.max (this.safeFloat (maxCosts, quote, maxCost), maxCost); + const maxAmount = this.safeNumber (limit, 'max_q'); + const maxPrice = this.safeNumber (limit, 'max_p'); + const maxCost = this.safeNumber (limit, 'max_a'); + const minAmount = this.safeNumber (limit, 'min_q'); + const minPrice = this.safeNumber (limit, 'min_p'); + const minCost = this.safeNumber (limit, 'min_a'); + minAmounts[base] = Math.min (this.safeNumber (minAmounts, base, minAmount), minAmount); + maxAmounts[base] = Math.max (this.safeNumber (maxAmounts, base, maxAmount), maxAmount); + minPrices[quote] = Math.min (this.safeNumber (minPrices, quote, minPrice), minPrice); + minCosts[quote] = Math.min (this.safeNumber (minCosts, quote, minCost), minCost); + maxPrices[quote] = Math.max (this.safeNumber (maxPrices, quote, maxPrice), maxPrice); + maxCosts[quote] = Math.max (this.safeNumber (maxCosts, quote, maxCost), maxCost); } const result = {}; for (let i = 0; i < ids.length; i++) { @@ -67858,16 +66168,16 @@ module.exports = class exmo extends Exchange { 'precision': 8, 'limits': { 'amount': { - 'min': this.safeFloat (minAmounts, code), - 'max': this.safeFloat (maxAmounts, code), + 'min': this.safeNumber (minAmounts, code), + 'max': this.safeNumber (maxAmounts, code), }, 'price': { - 'min': this.safeFloat (minPrices, code), - 'max': this.safeFloat (maxPrices, code), + 'min': this.safeNumber (minPrices, code), + 'max': this.safeNumber (maxPrices, code), }, 'cost': { - 'min': this.safeFloat (minCosts, code), - 'max': this.safeFloat (maxCosts, code), + 'min': this.safeNumber (minCosts, code), + 'max': this.safeNumber (maxCosts, code), }, }, 'info': id, @@ -67902,8 +66212,8 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = symbol.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const taker = this.safeFloat (market, 'commission_taker_percent'); - const maker = this.safeFloat (market, 'commission_maker_percent'); + const taker = this.safeNumber (market, 'commission_taker_percent'); + const maker = this.safeNumber (market, 'commission_maker_percent'); result.push ({ 'id': id, 'symbol': symbol, @@ -67916,16 +66226,16 @@ module.exports = class exmo extends Exchange { 'maker': maker / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, }, 'precision': { @@ -67998,11 +66308,11 @@ module.exports = class exmo extends Exchange { // return [ this.safeInteger (ohlcv, 't'), - this.safeFloat (ohlcv, 'o'), - this.safeFloat (ohlcv, 'h'), - this.safeFloat (ohlcv, 'l'), - this.safeFloat (ohlcv, 'c'), - this.safeFloat (ohlcv, 'v'), + this.safeNumber (ohlcv, 'o'), + this.safeNumber (ohlcv, 'h'), + this.safeNumber (ohlcv, 'l'), + this.safeNumber (ohlcv, 'c'), + this.safeNumber (ohlcv, 'v'), ]; } @@ -68018,14 +66328,14 @@ module.exports = class exmo extends Exchange { const currencyId = this.currencyId (code); const account = this.account (); if (currencyId in free) { - account['free'] = this.safeFloat (free, currencyId); + account['free'] = this.safeString (free, currencyId); } if (currencyId in used) { - account['used'] = this.safeFloat (used, currencyId); + account['used'] = this.safeString (used, currencyId); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -68083,16 +66393,16 @@ module.exports = class exmo extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -68101,9 +66411,9 @@ module.exports = class exmo extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_curr'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'vol_curr'), 'info': ticker, }; } @@ -68164,9 +66474,9 @@ module.exports = class exmo extends Exchange { let symbol = undefined; const id = this.safeString (trade, 'trade_id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'quantity'); + const cost = this.safeNumber (trade, 'amount'); const side = this.safeString (trade, 'type'); const type = undefined; const marketId = this.safeString (trade, 'pair'); @@ -68185,11 +66495,11 @@ module.exports = class exmo extends Exchange { } const takerOrMaker = this.safeString (trade, 'exec_type'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission_amount'); + const feeCost = this.safeNumber (trade, 'commission_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commission_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (trade, 'commission_percent'); + let feeRate = this.safeNumber (trade, 'commission_percent'); if (feeRate !== undefined) { feeRate /= 1000; } @@ -68488,13 +66798,13 @@ module.exports = class exmo extends Exchange { market = this.markets_by_id[marketId]; } } - let amount = this.safeFloat (order, 'quantity'); + let amount = this.safeNumber (order, 'quantity'); if (amount === undefined) { const amountField = (side === 'buy') ? 'in_amount' : 'out_amount'; - amount = this.safeFloat (order, amountField); + amount = this.safeNumber (order, amountField); } - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'amount'); + let price = this.safeNumber (order, 'price'); + let cost = this.safeNumber (order, 'amount'); let filled = 0.0; const trades = []; const transactions = this.safeValue (order, 'trades', []); @@ -68615,24 +66925,6 @@ module.exports = class exmo extends Exchange { return undefined; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -68677,7 +66969,7 @@ module.exports = class exmo extends Exchange { // } // const timestamp = this.safeTimestamp (transaction, 'dt'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -68707,7 +66999,7 @@ module.exports = class exmo extends Exchange { // fixed funding fees only (for now) if (!this.fees['funding']['percentage']) { const key = (type === 'withdrawal') ? 'withdraw' : 'deposit'; - let feeCost = this.safeFloat (this.options['fundingFees'][key], code); + let feeCost = this.safeNumber (this.options['fundingFees'][key], code); // users don't pay for cashbacks, no fees for that const provider = this.safeString (transaction, 'provider'); if (provider === 'cashback') { @@ -68854,13 +67146,14 @@ module.exports = class exmo extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],83:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],81:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ExchangeNotAvailable, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -69005,26 +67298,26 @@ module.exports = class exx extends Exchange { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); ticker = ticker['ticker']; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'riseRate'), + 'change': this.safeNumber (ticker, 'riseRate'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -69074,14 +67367,11 @@ module.exports = class exx extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -69126,14 +67416,13 @@ module.exports = class exx extends Exchange { const currencyId = currencies[i]; const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'balance'), - 'used': this.safeFloat (balance, 'freeze'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -69153,11 +67442,10 @@ module.exports = class exx extends Exchange { // const symbol = market['symbol']; const timestamp = parseInt (order['trade_date']); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'trade_money'); - const amount = this.safeFloat (order, 'total_amount'); - const filled = this.safeFloat (order, 'trade_amount', 0.0); - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'trade_money'); + const amount = this.safeNumber (order, 'total_amount'); + const filled = this.safeNumber (order, 'trade_amount', 0.0); let status = this.safeInteger (order, 'status'); if (status === 1) { status = 'canceled'; @@ -69169,11 +67457,11 @@ module.exports = class exx extends Exchange { let fee = undefined; if ('fees' in order) { fee = { - 'cost': this.safeFloat (order, 'fees'), + 'cost': this.safeNumber (order, 'fees'), 'currency': market['quote'], }; } - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -69190,12 +67478,12 @@ module.exports = class exx extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -69320,13 +67608,14 @@ module.exports = class exx extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],84:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],82:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, ArgumentsRequired, InsufficientFunds, InvalidOrder, RateLimitExceeded, InvalidNonce, AuthenticationError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -69546,8 +67835,8 @@ module.exports = class fcoin extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'limit_amount_min'), - 'max': this.safeFloat (market, 'limit_amount_max'), + 'min': this.safeNumber (market, 'limit_amount_min'), + 'max': this.safeNumber (market, 'limit_amount_max'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -69642,12 +67931,12 @@ module.exports = class fcoin extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidsAsks (orders, priceKey = 0, amountKey = 1) { @@ -69660,8 +67949,8 @@ module.exports = class fcoin extends Exchange { const priceField = this.sum (index, priceKey); const amountField = this.sum (index, amountKey); result.push ([ - this.safeFloat (orders, priceField), - this.safeFloat (orders, amountField), + this.safeNumber (orders, priceField), + this.safeNumber (orders, amountField), ]); } return result; @@ -69709,17 +67998,17 @@ module.exports = class fcoin extends Exchange { } } const values = ticker['ticker']; - const last = this.safeFloat (values, 0); + const last = this.safeNumber (values, 0); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (values, 7), - 'low': this.safeFloat (values, 8), - 'bid': this.safeFloat (values, 2), - 'bidVolume': this.safeFloat (values, 3), - 'ask': this.safeFloat (values, 4), - 'askVolume': this.safeFloat (values, 5), + 'high': this.safeNumber (values, 7), + 'low': this.safeNumber (values, 8), + 'bid': this.safeNumber (values, 2), + 'bidVolume': this.safeNumber (values, 3), + 'ask': this.safeNumber (values, 4), + 'askVolume': this.safeNumber (values, 5), 'vwap': undefined, 'open': undefined, 'close': last, @@ -69728,8 +68017,8 @@ module.exports = class fcoin extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (values, 9), - 'quoteVolume': this.safeFloat (values, 10), + 'baseVolume': this.safeNumber (values, 9), + 'quoteVolume': this.safeNumber (values, 10), 'info': ticker, }; } @@ -69742,14 +68031,11 @@ module.exports = class fcoin extends Exchange { const timestamp = this.safeInteger (trade, 'ts'); const side = this.safeStringLower (trade, 'side'); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = undefined; return { 'id': id, @@ -69874,38 +68160,25 @@ module.exports = class fcoin extends Exchange { const symbol = market['symbol']; const orderType = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'created_at'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'executed_value'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'executed_value'); let feeCurrency = undefined; let feeCost = undefined; - const feeRebate = this.safeFloat (order, 'fees_income'); + const feeRebate = this.safeNumber (order, 'fees_income'); if ((feeRebate !== undefined) && (feeRebate > 0)) { if (market !== undefined) { feeCurrency = (side === 'buy') ? market['quote'] : market['base']; } feeCost = -feeRebate; } else { - feeCost = this.safeFloat (order, 'fill_fees'); + feeCost = this.safeNumber (order, 'fill_fees'); if (market !== undefined) { feeCurrency = (side === 'buy') ? market['base'] : market['quote']; } } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -69921,7 +68194,7 @@ module.exports = class fcoin extends Exchange { 'stopPrice': undefined, 'cost': cost, 'amount': amount, - 'remaining': remaining, + 'remaining': undefined, 'filled': filled, 'average': undefined, 'status': status, @@ -69930,7 +68203,7 @@ module.exports = class fcoin extends Exchange { 'currency': feeCurrency, }, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -69972,11 +68245,11 @@ module.exports = class fcoin extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_vol'), ]; } @@ -70065,7 +68338,7 @@ module.exports = class fcoin extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],85:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],83:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -70091,13 +68364,14 @@ module.exports = class fcoinjp extends fcoin { } }; -},{"./fcoin.js":84}],86:[function(require,module,exports){ +},{"./fcoin.js":82}],84:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70225,11 +68499,11 @@ module.exports = class flowbtc extends Exchange { const currencyId = balance['name']; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['total'] = this.safeFloat (balance, 'hold'); + account['free'] = this.safeString (balance, 'balance'); + account['total'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -70250,16 +68524,16 @@ module.exports = class flowbtc extends Exchange { }; const ticker = await this.publicPostGetTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -70269,8 +68543,8 @@ module.exports = class flowbtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume24hr'), - 'quoteVolume': this.safeFloat (ticker, 'volume24hrProduct2'), + 'baseVolume': this.safeNumber (ticker, 'volume24hr'), + 'quoteVolume': this.safeNumber (ticker, 'volume24hrProduct2'), 'info': ticker, }; } @@ -70279,14 +68553,11 @@ module.exports = class flowbtc extends Exchange { const timestamp = this.safeTimestamp (trade, 'unixtime'); const side = (trade['incomingOrderSide'] === 0) ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'px'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'px'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'timestamp': timestamp, @@ -70377,13 +68648,14 @@ module.exports = class flowbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],87:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],85:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70469,11 +68741,11 @@ module.exports = class foxbit extends Exchange { // otherwise we will lose the info if the currency balance has been funded or traded or not if (currencyId in balances) { const account = this.account (); - let used = this.safeFloat (balances, currencyId + '_locked'); + let used = this.safeNumber (balances, currencyId + '_locked'); if (used !== undefined) { used *= 1e-8; } - let total = this.safeFloat (balances, currencyId); + let total = this.safeNumber (balances, currencyId); if (total !== undefined) { total *= 1e-8; } @@ -70508,16 +68780,16 @@ module.exports = class foxbit extends Exchange { const timestamp = this.milliseconds (); const lowercaseQuote = market['quote'].toLowerCase (); const quoteVolume = 'vol_' + lowercaseQuote; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -70527,8 +68799,8 @@ module.exports = class foxbit extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -70541,14 +68813,11 @@ module.exports = class foxbit extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -70642,14 +68911,15 @@ module.exports = class foxbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],88:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],86:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending } = require ('./base/errors'); +const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending, ArgumentsRequired, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70888,6 +69158,7 @@ module.exports = class ftx extends Exchange { 'An unexpected error occurred': ExchangeNotAvailable, // {"error":"An unexpected error occurred, please try again later (58BC21C795).","success":false} 'Please retry request': ExchangeNotAvailable, // {"error":"Please retry request","success":false} 'Please try again': ExchangeNotAvailable, // {"error":"Please try again","success":false} + 'Only have permissions for subaccount': PermissionDenied, // {"success":false,"error":"Only have permissions for subaccount *sub_name*"} }, }, 'precisionMode': TICK_SIZE, @@ -71011,8 +69282,8 @@ module.exports = class ftx extends Exchange { // check if a market is a spot or future market const symbol = (type === 'future') ? this.safeString (market, 'name') : (base + '/' + quote); const active = this.safeValue (market, 'enabled'); - const sizeIncrement = this.safeFloat (market, 'sizeIncrement'); - const priceIncrement = this.safeFloat (market, 'priceIncrement'); + const sizeIncrement = this.safeNumber (market, 'sizeIncrement'); + const priceIncrement = this.safeNumber (market, 'priceIncrement'); const precision = { 'amount': sizeIncrement, 'price': priceIncrement, @@ -71090,28 +69361,28 @@ module.exports = class ftx extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); const timestamp = this.safeTimestamp (ticker, 'time', this.milliseconds ()); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'change24h'), + 'percentage': this.safeNumber (ticker, 'change24h'), 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24h'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24h'), 'info': ticker, }; } @@ -71151,14 +69422,6 @@ module.exports = class ftx extends Exchange { return this.parseTicker (result, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetMarkets (params); @@ -71237,11 +69500,11 @@ module.exports = class ftx extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -71362,6 +69625,45 @@ module.exports = class ftx extends Exchange { // "type": "otc" // } // + // with -ve fee + // { + // "id": 1171258927, + // "fee": -0.0000713875, + // "side": "sell", + // "size": 1, + // "time": "2021-03-11T13:34:35.523627+00:00", + // "type": "order", + // "price": 14.2775, + // "future": null, + // "market": "SOL/USD", + // "feeRate": -0.000005, + // "orderId": 33182929044, + // "tradeId": 582936801, + // "liquidity": "maker", + // "feeCurrency": "USD", + // "baseCurrency": "SOL", + // "quoteCurrency": "USD" + // } + // + // // from OTC order + // { + // "id": 1172129651, + // "fee": 0, + // "side": "sell", + // "size": 1.47568846, + // "time": "2021-03-11T15:04:46.893383+00:00", + // "type": "otc", + // "price": 14.60932598, + // "future": null, + // "market": null, + // "feeRate": 0, + // "orderId": null, + // "tradeId": null, + // "liquidity": "taker", + // "feeCurrency": "USD", + // "baseCurrency": "BCHA", + // "quoteCurrency": "USD" + // } const id = this.safeString (trade, 'id'); const takerOrMaker = this.safeString (trade, 'liquidity'); const marketId = this.safeString (trade, 'market'); @@ -71379,25 +69681,24 @@ module.exports = class ftx extends Exchange { } } const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } const orderId = this.safeString (trade, 'orderId'); @@ -71503,8 +69804,8 @@ module.exports = class ftx extends Exchange { const result = this.safeValue (response, 'result', {}); return { 'info': response, - 'maker': this.safeFloat (result, 'makerFee'), - 'taker': this.safeFloat (result, 'takerFee'), + 'maker': this.safeNumber (result, 'makerFee'), + 'taker': this.safeNumber (result, 'takerFee'), }; } @@ -71531,11 +69832,11 @@ module.exports = class ftx extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'coin')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -71658,9 +69959,9 @@ module.exports = class ftx extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); let status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filledSize'); - let remaining = this.safeFloat (order, 'remainingSize'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filledSize'); + let remaining = this.safeNumber (order, 'remainingSize'); if ((remaining === 0.0) && (amount !== undefined) && (filled !== undefined)) { remaining = Math.max (amount - filled, 0); if (remaining > 0) { @@ -71684,15 +69985,15 @@ module.exports = class ftx extends Exchange { } const side = this.safeString (order, 'side'); const type = this.safeString (order, 'type'); - const average = this.safeFloat (order, 'avgFillPrice'); - const price = this.safeFloat2 (order, 'price', 'triggerPrice', average); + const average = this.safeNumber (order, 'avgFillPrice'); + const price = this.safeNumber2 (order, 'price', 'triggerPrice', average); let cost = undefined; if (filled !== undefined && price !== undefined) { cost = filled * price; } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'triggeredAt')); const clientOrderId = this.safeString (order, 'clientId'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -71738,22 +70039,28 @@ module.exports = class ftx extends Exchange { request['clientId'] = clientOrderId; params = this.omit (params, [ 'clientId', 'clientOrderId' ]); } - let priceToPrecision = undefined; - if (price !== undefined) { - priceToPrecision = parseFloat (this.priceToPrecision (symbol, price)); - } - let method = 'privatePostConditionalOrders'; + let method = undefined; if (type === 'limit') { method = 'privatePostOrders'; - request['price'] = priceToPrecision; + request['price'] = parseFloat (this.priceToPrecision (symbol, price)); } else if (type === 'market') { method = 'privatePostOrders'; request['price'] = null; } else if ((type === 'stop') || (type === 'takeProfit')) { - request['triggerPrice'] = priceToPrecision; - // request['orderPrice'] = number; // optional, order type is limit if this is specified, otherwise market + method = 'privatePostConditionalOrders'; + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerPrice'); + if (stopPrice === undefined) { + throw new ArgumentsRequired (this.id + ' createOrder () requires a stopPrice parameter or a triggerPrice parameter for ' + type + ' orders'); + } else { + params = this.omit (params, [ 'stopPrice', 'triggerPrice' ]); + request['triggerPrice'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + } + if (price !== undefined) { + request['orderPrice'] = parseFloat (this.priceToPrecision (symbol, price)); // optional, order type is limit if this is specified, otherwise market + } } else if (type === 'trailingStop') { - request['trailValue'] = priceToPrecision; // negative for "sell", positive for "buy" + method = 'privatePostConditionalOrders'; + request['trailValue'] = parseFloat (this.priceToPrecision (symbol, price)); // negative for "sell", positive for "buy" } else { throw new InvalidOrder (this.id + ' createOrder () does not support order type ' + type + ', only limit, market, stop, trailingStop, or takeProfit orders are supported'); } @@ -71819,9 +70126,9 @@ module.exports = class ftx extends Exchange { const request = {}; let method = undefined; const clientOrderId = this.safeString2 (params, 'client_order_id', 'clientOrderId'); - const triggerPrice = this.safeFloat (params, 'triggerPrice'); - const orderPrice = this.safeFloat (params, 'orderPrice'); - const trailValue = this.safeFloat (params, 'trailValue'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); + const orderPrice = this.safeNumber (params, 'orderPrice'); + const trailValue = this.safeNumber (params, 'trailValue'); params = this.omit (params, [ 'client_order_id', 'clientOrderId', 'triggerPrice', 'orderPrice', 'trailValue' ]); const triggerPriceIsDefined = (triggerPrice !== undefined); const orderPriceIsDefined = (orderPrice !== undefined); @@ -72184,7 +70491,7 @@ module.exports = class ftx extends Exchange { return this.parseTransaction (result, currency); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetAccount (params); // @@ -72317,7 +70624,7 @@ module.exports = class ftx extends Exchange { // const code = this.safeCurrencyCode (this.safeString (transaction, 'coin')); const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'size'); + const amount = this.safeNumber (transaction, 'size'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const txid = this.safeString (transaction, 'txid'); @@ -72334,7 +70641,7 @@ module.exports = class ftx extends Exchange { address = notes.slice (12); } } - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -72469,13 +70776,14 @@ module.exports = class ftx extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],89:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],87:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, ArgumentsRequired, InvalidAddress, OrderNotFound, NotSupported, DDoSProtection, InsufficientFunds, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -72636,9 +70944,12 @@ module.exports = class gateio extends Exchange { }, }, 'commonCurrencies': { + '88MPH': 'MPH', + 'BIFI': 'Bitcoin File', 'BOX': 'DefiBox', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', + 'MPH': 'Morpher', // conflict with 88MPH 'SBTC': 'Super Bitcoin', 'TNC': 'Trinity Network Credit', }, @@ -72685,9 +70996,9 @@ module.exports = class gateio extends Exchange { const currency = coin[id]; const code = this.safeCurrencyCode (id); const delisted = this.safeValue (currency, 'delisted', 0); - const withdrawDisabled = this.safeValue (currency, 'withdraw_disabled', 0); - const depositDisabled = this.safeValue (currency, 'deposit_disabled', 0); - const tradeDisabled = this.safeValue (currency, 'trade_disabled', 0); + const withdrawDisabled = this.safeInteger2 (currency, 'withdraw_disabled', 0); + const depositDisabled = this.safeInteger2 (currency, 'deposit_disabled', 0); + const tradeDisabled = this.safeInteger2 (currency, 'trade_disabled', 0); const listed = (delisted === 0); const withdrawEnabled = (withdrawDisabled === 0); const depositEnabled = (depositDisabled === 0); @@ -72776,7 +71087,7 @@ module.exports = class gateio extends Exchange { 'price': this.safeInteger (details, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (details, 'min_amount'), + 'min': this.safeNumber (details, 'min_amount'), 'max': undefined, }; const priceLimits = { @@ -72784,7 +71095,7 @@ module.exports = class gateio extends Exchange { 'max': undefined, }; const defaultCost = amountLimits['min'] * priceLimits['min']; - const minCost = this.safeFloat (this.options['limits']['cost']['min'], quote, defaultCost); + const minCost = this.safeNumber (this.options['limits']['cost']['min'], quote, defaultCost); const costLimits = { 'min': minCost, 'max': undefined, @@ -72794,10 +71105,10 @@ module.exports = class gateio extends Exchange { 'price': priceLimits, 'cost': costLimits, }; - const disabled = this.safeValue (details, 'trade_disabled'); + const disabled = this.safeInteger (details, 'trade_disabled'); const active = !disabled; const uppercaseId = id.toUpperCase (); - const fee = this.safeFloat (details, 'fee'); + const fee = this.safeNumber (details, 'fee'); result.push ({ 'id': id, 'uppercaseId': uppercaseId, @@ -72831,11 +71142,11 @@ module.exports = class gateio extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (available, currencyId); - account['used'] = this.safeFloat (locked, currencyId); + account['free'] = this.safeString (available, currencyId); + account['used'] = this.safeString (locked, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -72851,11 +71162,11 @@ module.exports = class gateio extends Exchange { // they return [ Timestamp, Volume, Close, High, Low, Open ] return [ this.safeInteger (ohlcv, 0), // t - this.safeFloat (ohlcv, 5), // o - this.safeFloat (ohlcv, 3), // h - this.safeFloat (ohlcv, 4), // l - this.safeFloat (ohlcv, 2), // c - this.safeFloat (ohlcv, 1), // v + this.safeNumber (ohlcv, 5), // o + this.safeNumber (ohlcv, 3), // h + this.safeNumber (ohlcv, 4), // l + this.safeNumber (ohlcv, 2), // c + this.safeNumber (ohlcv, 1), // v ]; } @@ -72867,11 +71178,11 @@ module.exports = class gateio extends Exchange { 'group_sec': this.timeframes[timeframe], }; // max limit = 1001 - if (limit !== undefined) { - const periodDurationInSeconds = this.parseTimeframe (timeframe); - const hours = parseInt ((periodDurationInSeconds * limit) / 3600); - request['range_hour'] = Math.max (0, hours - 1); - } + // if (limit !== undefined) { + // const periodDurationInSeconds = this.parseTimeframe (timeframe); + // const hours = parseInt ((periodDurationInSeconds * limit) / 3600); + // request['range_hour'] = Math.max (1, hours - 1); + // } const response = await this.publicGetCandlestick2Id (this.extend (request, params)); // // { @@ -72895,8 +71206,8 @@ module.exports = class gateio extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'percentChange'); let open = undefined; let change = undefined; let average = undefined; @@ -72906,17 +71217,17 @@ module.exports = class gateio extends Exchange { change = last - open; average = this.sum (last, open) / 2; } - open = this.safeFloat (ticker, 'open', open); - change = this.safeFloat (ticker, 'change', change); + open = this.safeNumber (ticker, 'open', open); + change = this.safeNumber (ticker, 'change', change); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high24hr', 'high'), - 'low': this.safeFloat2 (ticker, 'low24hr', 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber2 (ticker, 'high24hr', 'high'), + 'low': this.safeNumber2 (ticker, 'low24hr', 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -72926,8 +71237,8 @@ module.exports = class gateio extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), // gateio has them reversed - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), // gateio has them reversed + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -72973,27 +71284,24 @@ module.exports = class gateio extends Exchange { const id = this.safeString2 (trade, 'tradeID', 'id'); // take either of orderid or orderId const orderId = this.safeString2 (trade, 'orderid', 'orderNumber'); - const price = this.safeFloat2 (trade, 'rate', 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString2 (trade, 'rate', 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'role'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } let fee = undefined; let feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee_coin')); - let feeCost = this.safeFloat (trade, 'point_fee'); + let feeCost = this.safeNumber (trade, 'point_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'gt_fee'); + feeCost = this.safeNumber (trade, 'gt_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'fee'); + feeCost = this.safeNumber (trade, 'fee'); } else { feeCurrency = this.safeCurrencyCode ('GT'); } @@ -73137,23 +71445,20 @@ module.exports = class gateio extends Exchange { } else if (side === '2') { side = 'buy'; } - const price = this.safeFloat2 (order, 'initialRate', 'rate'); - const average = this.safeFloat (order, 'filledRate'); - const amount = this.safeFloat2 (order, 'initialAmount', 'amount'); - const filled = this.safeFloat (order, 'filledAmount'); + const price = this.safeNumber2 (order, 'initialRate', 'rate'); + const average = this.safeNumber (order, 'filledRate'); + const amount = this.safeNumber2 (order, 'initialAmount', 'amount'); + const filled = this.safeNumber (order, 'filledAmount'); // In the order status response, this field has a different name. - let remaining = this.safeFloat2 (order, 'leftAmount', 'left'); - if (remaining === undefined) { - remaining = amount - filled; - } - const feeCost = this.safeFloat (order, 'feeValue'); + const remaining = this.safeNumber2 (order, 'leftAmount', 'left'); + const feeCost = this.safeNumber (order, 'feeValue'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (order, 'feePercentage'); + let feeRate = this.safeNumber (order, 'feePercentage'); if (feeRate !== undefined) { feeRate = feeRate / 100; } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -73179,7 +71484,7 @@ module.exports = class gateio extends Exchange { 'rate': feeRate, }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -73370,7 +71675,7 @@ module.exports = class gateio extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'txid'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); if (address === 'false') { address = undefined; @@ -73378,7 +71683,7 @@ module.exports = class gateio extends Exchange { const timestamp = this.safeTimestamp (transaction, 'timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.parseTransactionType (id[0]); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -73467,7 +71772,7 @@ module.exports = class gateio extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],90:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],88:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -73475,6 +71780,7 @@ module.exports = class gateio extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidOrder, InvalidNonce, InsufficientFunds, AuthenticationError, PermissionDenied, NotSupported, OnMaintenance, RateLimitExceeded, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -73691,16 +71997,16 @@ module.exports = class gemini extends Exchange { // const base = this.safeCurrencyCode (baseId); const minAmountString = cells[1].replace ('', ''); const minAmountParts = minAmountString.split (' '); - const minAmount = this.safeFloat (minAmountParts, 0); + const minAmount = this.safeNumber (minAmountParts, 0); const amountPrecisionString = cells[2].replace ('', ''); const amountPrecisionParts = amountPrecisionString.split (' '); - const amountPrecision = this.safeFloat (amountPrecisionParts, 0); + const amountPrecision = this.safeNumber (amountPrecisionParts, 0); const idLength = marketId.length - 0; const quoteId = marketId.slice (idLength - 3, idLength); const quote = this.safeCurrencyCode (quoteId); const pricePrecisionString = cells[3].replace ('', ''); const pricePrecisionParts = pricePrecisionString.split (' '); - const pricePrecision = this.safeFloat (pricePrecisionParts, 0); + const pricePrecision = this.safeNumber (pricePrecisionParts, 0); const baseId = marketId.replace (quoteId, ''); const base = this.safeCurrencyCode (baseId); const symbol = base + '/' + quote; @@ -73928,11 +72234,11 @@ module.exports = class gemini extends Exchange { base = market['base']; quote = market['quote']; } - const price = this.safeFloat (ticker, 'price'); - const last = this.safeFloat2 (ticker, 'last', 'close', price); - let percentage = this.safeFloat (ticker, 'percentChange24h'); + const price = this.safeNumber (ticker, 'price'); + const last = this.safeNumber2 (ticker, 'last', 'close', price); + let percentage = this.safeNumber (ticker, 'percentChange24h'); let change = undefined; - let open = this.safeFloat (ticker, 'open'); + let open = this.safeNumber (ticker, 'open'); let average = undefined; if (last !== undefined) { if (open !== undefined) { @@ -73949,18 +72255,18 @@ module.exports = class gemini extends Exchange { average = this.sum (last, open) / 2; } } - const baseVolume = this.safeFloat (volume, baseId); - const quoteVolume = this.safeFloat (volume, quoteId); + const baseVolume = this.safeNumber (volume, baseId); + const quoteVolume = this.safeNumber (volume, quoteId); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -73976,14 +72282,6 @@ module.exports = class gemini extends Exchange { }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetV1Pricefeed (params); @@ -74024,17 +72322,14 @@ module.exports = class gemini extends Exchange { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); const fee = { - 'cost': this.safeFloat (trade, 'fee_amount'), + 'cost': this.safeNumber (trade, 'fee_amount'), 'currency': feeCurrencyCode, }; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeStringLower (trade, 'type'); const symbol = this.safeSymbol (undefined, market); @@ -74087,18 +72382,18 @@ module.exports = class gemini extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'timestampms'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const filled = this.safeFloat (order, 'executed_amount'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const filled = this.safeNumber (order, 'executed_amount'); let status = 'closed'; if (order['is_live']) { status = 'open'; @@ -74106,14 +72401,8 @@ module.exports = class gemini extends Exchange { if (order['is_cancelled']) { status = 'canceled'; } - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_execution_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_execution_price'); let type = this.safeString (order, 'type'); if (type === 'exchange limit') { type = 'limit'; @@ -74128,7 +72417,7 @@ module.exports = class gemini extends Exchange { const id = this.safeString (order, 'order_id'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'client_order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -74144,13 +72433,13 @@ module.exports = class gemini extends Exchange { 'price': price, 'stopPrice': undefined, 'average': average, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -74265,7 +72554,7 @@ module.exports = class gemini extends Exchange { status = 'ok'; } let fee = undefined; - const feeAmount = this.safeFloat (transaction, 'feeAmount'); + const feeAmount = this.safeNumber (transaction, 'feeAmount'); if (feeAmount !== undefined) { fee = { 'cost': feeAmount, @@ -74281,7 +72570,7 @@ module.exports = class gemini extends Exchange { 'address': address, 'tag': undefined, // or is it defined? 'type': type, // direction of the transaction, ('deposit' | 'withdraw') - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': undefined, @@ -74380,7 +72669,7 @@ module.exports = class gemini extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],91:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],89:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -74388,6 +72677,7 @@ module.exports = class gemini extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound, InvalidAddress, BadRequest } = require ('./base/errors'); const { TRUNCATE, ROUND, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -74601,8 +72891,8 @@ module.exports = class gopax extends Exchange { const minimums = this.safeValue (market, 'restApiOrderAmountMin', {}); const marketAsk = this.safeValue (minimums, 'marketAsk', {}); const marketBid = this.safeValue (minimums, 'marketBid', {}); - const takerFeePercent = this.safeFloat (market, 'takerFeePercent'); - const makerFeePercent = this.safeFloat (market, 'makerFeePercent'); + const takerFeePercent = this.safeNumber (market, 'takerFeePercent'); + const makerFeePercent = this.safeNumber (market, 'makerFeePercent'); const taker = parseFloat (this.decimalToPrecision (takerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); const maker = parseFloat (this.decimalToPrecision (makerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); result.push ({ @@ -74620,15 +72910,15 @@ module.exports = class gopax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (marketAsk, 'amount'), + 'min': this.safeNumber (marketAsk, 'amount'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'priceMin'), + 'min': this.safeNumber (market, 'priceMin'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (marketBid, 'amount'), + 'min': this.safeNumber (marketBid, 'amount'), 'max': undefined, }, }, @@ -74663,8 +72953,8 @@ module.exports = class gopax extends Exchange { const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'name'); - const fee = this.safeFloat (currency, 'withdrawalFee'); - const precision = this.safeFloat (currency, 'scale'); + const fee = this.safeNumber (currency, 'withdrawalFee'); + const precision = this.safeNumber (currency, 'scale'); result[code] = { 'id': id, 'info': currency, @@ -74687,7 +72977,7 @@ module.exports = class gopax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalAmountMin'), + 'min': this.safeNumber (currency, 'withdrawalAmountMin'), 'max': undefined, }, }, @@ -74755,8 +73045,8 @@ module.exports = class gopax extends Exchange { const marketId = this.safeString (ticker, 'name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (ticker, 'time')); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat2 (ticker, 'price', 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'price', 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -74767,20 +73057,20 @@ module.exports = class gopax extends Exchange { percentage = change / open * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidVolume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askVolume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidVolume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askVolume'), 'vwap': vwap, 'open': open, 'close': last, @@ -74816,14 +73106,6 @@ module.exports = class gopax extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTradingPairsStats (params); @@ -74845,8 +73127,8 @@ module.exports = class gopax extends Exchange { parsePublicTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let symbol = undefined; if ('symbol' in market) { symbol = this.safeString (market, 'symbol'); @@ -74872,14 +73154,14 @@ module.exports = class gopax extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const symbol = this.safeString (trade, 'tradingPairName').replace ('-', '/'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'baseAmount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'baseAmount'); let feeCurrency = symbol.slice (0, 3); if (side === 'sell') { feeCurrency = symbol.slice (4); } const fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': feeCurrency, 'rate': undefined, }; @@ -74961,15 +73243,15 @@ module.exports = class gopax extends Exchange { } else if (type === '2') { type = 'market'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'baseAmount'); - let cost = this.safeFloat (trade, 'quoteAmount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'baseAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteAmount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -75036,11 +73318,11 @@ module.exports = class gopax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -75080,14 +73362,14 @@ module.exports = class gopax extends Exchange { const balance = response[i]; const currencyId = this.safeString2 (balance, 'asset', 'isoAlpha3'); const code = this.safeCurrencyCode (currencyId); - const hold = this.safeFloat (balance, 'hold'); - const pendingWithdrawal = this.safeFloat (balance, 'pendingWithdrawal'); + const hold = this.safeString (balance, 'hold'); + const pendingWithdrawal = this.safeString (balance, 'pendingWithdrawal'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.sum (hold, pendingWithdrawal); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = Precise.stringAdd (hold, pendingWithdrawal); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -75164,42 +73446,36 @@ module.exports = class gopax extends Exchange { const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); const timeInForce = this.safeStringUpper (order, 'timeInForce'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - const remaining = this.safeFloat (order, 'remaining'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const stopPrice = this.safeNumber (order, 'stopPrice'); + const remaining = this.safeNumber (order, 'remaining'); const marketId = this.safeString (order, 'tradingPairName'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const balanceChange = this.safeValue (order, 'balanceChange', {}); - let filled = this.safeFloat (balanceChange, 'baseNet'); - let cost = this.safeFloat (balanceChange, 'quoteNet'); + const filled = this.safeNumber (balanceChange, 'baseNet'); + let cost = this.safeNumber (balanceChange, 'quoteNet'); if (cost !== undefined) { cost = Math.abs (cost); } let updated = undefined; - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } if ((filled !== undefined) && (filled > 0)) { updated = this.parse8601 (this.safeString (order, 'updatedAt')); } - if ((cost === undefined) && (price !== undefined) && (filled !== undefined)) { - cost = filled * price; - } let fee = undefined; if (side === 'buy') { const baseFee = this.safeValue (balanceChange, 'baseFee', {}); - const taking = this.safeFloat (baseFee, 'taking'); - const making = this.safeFloat (baseFee, 'making'); + const taking = this.safeNumber (baseFee, 'taking'); + const making = this.safeNumber (baseFee, 'making'); fee = { 'currency': market['base'], 'cost': this.sum (taking, making), }; } else { const quoteFee = this.safeValue (balanceChange, 'quoteFee', {}); - const taking = this.safeFloat (quoteFee, 'taking'); - const making = this.safeFloat (quoteFee, 'making'); + const taking = this.safeNumber (quoteFee, 'taking'); + const making = this.safeNumber (quoteFee, 'making'); fee = { 'currency': market['quote'], 'cost': this.sum (taking, making), @@ -75209,7 +73485,7 @@ module.exports = class gopax extends Exchange { if (timeInForce !== undefined) { postOnly = (timeInForce === 'PO'); } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'datetime': this.iso8601 (timestamp), @@ -75231,7 +73507,7 @@ module.exports = class gopax extends Exchange { 'trades': undefined, 'fee': fee, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -75379,7 +73655,7 @@ module.exports = class gopax extends Exchange { request['clientOrderId'] = clientOrderId; params = this.omit (params, 'clientOrderId'); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -75508,18 +73784,6 @@ module.exports = class gopax extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetCryptoDepositAddresses (params); @@ -75584,8 +73848,8 @@ module.exports = class gopax extends Exchange { } else if ((type === 'crypto_deposit' || type === 'fiat_deposit')) { type = 'deposit'; } - const amount = this.safeFloat (transaction, 'netAmount'); - const feeCost = this.safeFloat (transaction, 'feeAmount'); + const amount = this.safeNumber (transaction, 'netAmount'); + const feeCost = this.safeNumber (transaction, 'feeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -75729,7 +73993,7 @@ module.exports = class gopax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],92:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],90:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -75737,6 +74001,7 @@ module.exports = class gopax extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, OrderNotFound, ArgumentsRequired, BadSymbol, BadRequest, NullResponse, InvalidOrder, BadResponse, NotSupported, ExchangeNotAvailable, RequestTimeout, RateLimitExceeded, PermissionDenied, InsufficientFunds, InvalidAddress } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -76036,23 +74301,23 @@ module.exports = class hbtc extends Exchange { const filter = filters[j]; const filterType = this.safeString (filter, 'filterType'); if (filterType === 'LOT_SIZE') { - amountMin = this.safeFloat (filter, 'minQty'); - amountMax = this.safeFloat (filter, 'maxQty'); + amountMin = this.safeNumber (filter, 'minQty'); + amountMax = this.safeNumber (filter, 'maxQty'); } if (filterType === 'PRICE_FILTER') { - priceMin = this.safeFloat (filter, 'minPrice'); - priceMax = this.safeFloat (filter, 'maxPrice'); + priceMin = this.safeNumber (filter, 'minPrice'); + priceMax = this.safeNumber (filter, 'maxPrice'); } if (filterType === 'MIN_NOTIONAL') { - costMin = this.safeFloat (filter, 'minNotional'); + costMin = this.safeNumber (filter, 'minNotional'); } } if ((costMin === undefined) && (amountMin !== undefined) && (priceMin !== undefined)) { costMin = amountMin * priceMin; } const precision = { - 'price': this.safeFloat2 (market, 'quotePrecision', 'quoteAssetPrecision'), - 'amount': this.safeFloat (market, 'baseAssetPrecision'), + 'price': this.safeNumber2 (market, 'quotePrecision', 'quoteAssetPrecision'), + 'amount': this.safeNumber (market, 'baseAssetPrecision'), }; const limits = { 'amount': { @@ -76290,14 +74555,6 @@ module.exports = class hbtc extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidAsk (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -76449,8 +74706,8 @@ module.exports = class hbtc extends Exchange { const currencyId = this.safeString2 (balance, 'asset', 'tokenName'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -76460,12 +74717,12 @@ module.exports = class hbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = response[currencyId]; const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableMargin'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'availableMargin'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTrades (symbol, since = undefined, limit = 50, params = {}) { @@ -76506,11 +74763,11 @@ module.exports = class hbtc extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -77196,8 +75453,8 @@ module.exports = class hbtc extends Exchange { // const currencyId = this.safeString (item, 'tokenId'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'change'); - const after = this.safeFloat (item, 'total'); + const amount = this.safeNumber (item, 'change'); + const after = this.safeNumber (item, 'total'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -77337,8 +75594,8 @@ module.exports = class hbtc extends Exchange { } else { type = 'withdrawal'; } - const amount = this.safeFloat (transaction, 'quantity'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'quantity'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'feeTokenId'); @@ -77399,8 +75656,8 @@ module.exports = class hbtc extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'openPrice'); - const close = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; let average = undefined; @@ -77411,19 +75668,19 @@ module.exports = class hbtc extends Exchange { percentage = (change / open) * 100; } } - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat2 (ticker, 'bestBidPrice', 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat2 (ticker, 'bestAskPrice', 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber2 (ticker, 'bestBidPrice', 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber2 (ticker, 'bestAskPrice', 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': vwap, 'open': open, 'close': close, @@ -77473,17 +75730,14 @@ module.exports = class hbtc extends Exchange { // } // const id = this.safeString (trade, 'id'); - const timestamp = this.safeFloat (trade, 'time'); + const timestamp = this.safeNumber (trade, 'time'); const type = undefined; const orderId = this.safeString (trade, 'orderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let side = undefined; let takerOrMaker = undefined; if ('isBuyerMaker' in trade) { @@ -77497,7 +75751,7 @@ module.exports = class hbtc extends Exchange { side = isBuyer ? 'buy' : 'sell'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -77603,30 +75857,30 @@ module.exports = class hbtc extends Exchange { const symbol = this.safeSymbol (marketId, market); let type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'avgPrice'); + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'avgPrice'); let amount = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); + let cost = this.safeNumber (order, 'cummulativeQuoteQty'); let filled = undefined; let remaining = undefined; if (type === undefined) { type = this.safeStringLower (order, 'orderType'); if ((market !== undefined) && market['inverse']) { - cost = this.safeFloat (order, 'executedQty'); + cost = this.safeNumber (order, 'executedQty'); amount = undefined; } if (cost === 0.0) { filled = 0; } } else { - amount = this.safeFloat (order, 'origQty'); + amount = this.safeNumber (order, 'origQty'); if (type === 'market') { price = undefined; if (side === 'buy') { amount = undefined; } } - filled = this.safeFloat (order, 'executedQty'); + filled = this.safeNumber (order, 'executedQty'); if (filled !== undefined) { if (amount !== undefined) { remaining = amount - filled; @@ -77638,7 +75892,7 @@ module.exports = class hbtc extends Exchange { } const status = this.parseOrderStatus (this.safeString (order, 'status')); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const result = { 'info': order, 'id': id, @@ -77667,7 +75921,7 @@ module.exports = class hbtc extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'fee'); + const feeCost = this.safeNumber (fees[i], 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'feeToken'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -77740,7 +75994,7 @@ module.exports = class hbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],93:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],91:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -77748,6 +76002,7 @@ module.exports = class hbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, PermissionDenied, ExchangeError, ExchangeNotAvailable, OrderNotFound, InsufficientFunds, InvalidOrder, RequestTimeout, AuthenticationError } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -77787,6 +76042,7 @@ module.exports = class hitbtc extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': 'M1', @@ -77824,10 +76080,10 @@ module.exports = class hitbtc extends Exchange { 'api': { 'public': { 'get': [ - 'symbol', // Available Currency Symbols - 'symbol/{symbol}', // Get symbol info 'currency', // Available Currencies 'currency/{currency}', // Get currency info + 'symbol', // Available Currency Symbols + 'symbol/{symbol}', // Get symbol info 'ticker', // Ticker list for all symbols 'ticker/{symbol}', // Ticker for symbol 'trades', @@ -77845,11 +76101,20 @@ module.exports = class hitbtc extends Exchange { 'order/{clientOrderId}', // Get a single order by clientOrderId 'trading/fee/all', // Get trading fee rate 'trading/fee/{symbol}', // Get trading fee rate + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', 'history/order', // Get historical orders 'history/trades', // Get historical trades 'history/order/{orderId}/trades', // Get historical trades by specified order 'account/balance', // Get main acccount balance - 'account/crypto/address/{currency}', // Get deposit crypro address + 'account/crypto/address/{currency}', // Get current address + 'account/crypto/addresses/{currency}', // Get last 10 deposit addresses for currency + 'account/crypto/used-addresses/{currency}', // Get last 10 unique addresses used for withdraw by currency + 'account/crypto/estimate-withdraw', 'account/crypto/is-mine/{address}', 'account/transactions', // Get account transactions 'account/transactions/{id}', // Get account transaction by id @@ -77860,23 +76125,33 @@ module.exports = class hitbtc extends Exchange { ], 'post': [ 'order', // Create new order - 'account/crypto/address/{currency}', // Create new deposit crypro address - 'account/crypto/withdraw', // Withdraw crypro + 'margin/order', + 'account/crypto/address/{currency}', // Create new crypto deposit address + 'account/crypto/withdraw', // Withdraw crypto 'account/crypto/transfer-convert', - 'account/transfer', // Transfer amount to trading + 'account/transfer', // Transfer amount to trading account or to main account + 'account/transfer/internal', 'sub-acc/freeze', 'sub-acc/activate', 'sub-acc/transfer', ], 'put': [ 'order/{clientOrderId}', // Create new order - 'account/crypto/withdraw/{id}', // Commit withdraw crypro + 'margin/account/{symbol}', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Commit crypto withdrawal 'sub-acc/acl/{subAccountUserId}', ], 'delete': [ 'order', // Cancel all open orders 'order/{clientOrderId}', // Cancel order - 'account/crypto/withdraw/{id}', // Rollback withdraw crypro + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Rollback crypto withdrawal ], // outdated? 'patch': [ @@ -77895,8 +76170,20 @@ module.exports = class hitbtc extends Exchange { }, 'options': { 'defaultTimeInForce': 'FOK', + 'accountsByType': { + 'bank': 'bank', + 'exchange': 'exchange', + 'main': 'bank', // alias of the above + 'trading': 'exchange', + }, + 'fetchBalanceMethod': { + 'account': 'account', + 'main': 'account', + 'trading': 'trading', + }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BCC': 'BCC', // initial symbol for Bitcoin Cash, now inactive 'BET': 'DAO.Casino', 'BOX': 'BOX Token', @@ -77923,7 +76210,6 @@ module.exports = class hitbtc extends Exchange { '20002': OrderNotFound, // canceling non-existent order '20001': InsufficientFunds, // {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}} }, - 'orders': {}, // orders cache / emulation }); } @@ -77960,14 +76246,14 @@ module.exports = class hitbtc extends Exchange { if (id.indexOf ('_') >= 0) { symbol = id; } - const lot = this.safeFloat (market, 'quantityIncrement'); - const step = this.safeFloat (market, 'tickSize'); + const lot = this.safeNumber (market, 'quantityIncrement'); + const step = this.safeNumber (market, 'tickSize'); const precision = { 'price': step, 'amount': lot, }; - const taker = this.safeFloat (market, 'takeLiquidityRate'); - const maker = this.safeFloat (market, 'provideLiquidityRate'); + const taker = this.safeNumber (market, 'takeLiquidityRate'); + const maker = this.safeNumber (market, 'provideLiquidityRate'); const feeCurrencyId = this.safeString (market, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); result.push (this.extend (this.fees['trading'], { @@ -78002,6 +76288,49 @@ module.exports = class hitbtc extends Exchange { return result; } + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // account can be "exchange" or "bank", with aliases "main" or "trading" respectively + await this.loadMarkets (); + const currency = this.currency (code); + const requestAmount = this.currencyToPrecision (code, amount); + const request = { + 'currency': currency['id'], + 'amount': requestAmount, + }; + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + const keys = Object.keys (accountsByType); + if (fromId === undefined) { + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ') + ' instead of ' + fromId); + } + if (toId === undefined) { + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ') + ' instead of ' + toId); + } + if (fromId === toId) { + throw new ExchangeError (this.id + ' from and to cannot be the same account'); + } + type = fromId + 'To' + this.capitalize (toId); + } + request['type'] = type; + const response = await this.privatePostAccountTransfer (this.extend (request, params)); + // { id: '2db6ebab-fb26-4537-9ef8-1a689472d236' } + const id = this.safeString (response, 'id'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'amount': requestAmount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': undefined, + }; + } + async fetchCurrencies (params = {}) { const response = await this.publicGetCurrency (params); // @@ -78057,7 +76386,7 @@ module.exports = class hitbtc extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'payoutFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'payoutFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -78097,15 +76426,20 @@ module.exports = class hitbtc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } async fetchBalance (params = {}) { await this.loadMarkets (); const type = this.safeString (params, 'type', 'trading'); - const method = 'privateGet' + this.capitalize (type) + 'Balance'; + const fetchBalanceAccounts = this.safeValue (this.options, 'fetchBalanceMethod', {}); + const typeId = this.safeString (fetchBalanceAccounts, type); + if (typeId === undefined) { + throw new ExchangeError (this.id + ' fetchBalance account type must be either main or trading'); + } + const method = 'privateGet' + this.capitalize (typeId) + 'Balance'; const query = this.omit (params, 'type'); const response = await this[method] (query); const result = { 'info': response }; @@ -78114,11 +76448,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -78135,11 +76469,11 @@ module.exports = class hitbtc extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'max'), - this.safeFloat (ohlcv, 'min'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'max'), + this.safeNumber (ohlcv, 'min'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -78185,10 +76519,10 @@ module.exports = class hitbtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); let change = undefined; let percentage = undefined; let average = undefined; @@ -78204,11 +76538,11 @@ module.exports = class hitbtc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -78284,7 +76618,7 @@ module.exports = class hitbtc extends Exchange { market = this.safeMarket (marketId, market); const symbol = market['symbol']; let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = market ? market['feeCurrency'] : undefined; fee = { @@ -78296,9 +76630,11 @@ module.exports = class hitbtc extends Exchange { // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const orderId = this.safeString (trade, 'clientOrderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); const id = this.safeString (trade, 'id'); return { @@ -78397,11 +76733,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'hash'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -78589,66 +76925,25 @@ module.exports = class hitbtc extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'cumQuantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'cumQuantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); // we use clientOrderId as the order id with this exchange intentionally // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const id = this.safeString (order, 'clientOrderId'); const clientOrderId = id; - let price = this.safeFloat (order, 'price'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - if (price !== undefined) { - cost = filled * price; - } - } - } + const price = this.safeNumber (order, 'price'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); let trades = this.safeValue (order, 'tradesReport'); - let fee = undefined; - let average = this.safeValue (order, 'avgPrice'); + const fee = undefined; + const average = this.safeNumber (order, 'avgPrice'); if (trades !== undefined) { trades = this.parseTrades (trades, market); - let feeCost = undefined; - const numTrades = trades.length; - let tradesCost = 0; - for (let i = 0; i < numTrades; i++) { - if (feeCost === undefined) { - feeCost = 0; - } - tradesCost = this.sum (tradesCost, trades[i]['cost']); - const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); - if (tradeFeeCost !== undefined) { - feeCost = this.sum (feeCost, tradeFeeCost); - } - } - cost = tradesCost; - if ((filled !== undefined) && (filled > 0)) { - if (average === undefined) { - average = cost / filled; - } - if (type === 'market') { - if (price === undefined) { - price = average; - } - } - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, // https://github.com/ccxt/ccxt/issues/5674 'timestamp': created, @@ -78663,13 +76958,13 @@ module.exports = class hitbtc extends Exchange { 'stopPrice': undefined, 'average': average, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -78930,7 +77225,7 @@ module.exports = class hitbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],94:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],92:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -78938,6 +77233,7 @@ module.exports = class hitbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { BadRequest, AuthenticationError, NetworkError, ArgumentsRequired, OrderNotFound, InsufficientFunds } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -78948,7 +77244,7 @@ module.exports = class hollaex extends Exchange { 'name': 'HollaEx', 'countries': [ 'KR' ], 'rateLimit': 333, - 'version': 'v1', + 'version': 'v2', 'has': { 'CORS': false, 'fetchMarkets': true, @@ -78968,13 +77264,13 @@ module.exports = class hollaex extends Exchange { 'cancelOrder': true, 'cancelAllOrders': true, 'fetchOpenOrders': true, - 'fetchClosedOrders': false, + 'fetchClosedOrders': true, 'fetchOpenOrder': true, 'fetchOrder': false, 'fetchDeposits': true, 'fetchWithdrawals': true, 'fetchTransactions': false, - 'fetchOrders': false, + 'fetchOrders': true, 'fetchMyTrades': true, 'withdraw': true, 'fetchDepositAddress': true, @@ -78999,13 +77295,17 @@ module.exports = class hollaex extends Exchange { 'public': { 'get': [ 'health', - 'constant', + 'constants', + 'kit', + 'tiers', 'ticker', - 'ticker/all', + 'tickers', + 'orderbook', 'orderbooks', 'trades', 'chart', - // TradingView data + 'charts', + // TradingView 'udf/config', 'udf/history', 'udf/symbols', @@ -79015,20 +77315,20 @@ module.exports = class hollaex extends Exchange { 'get': [ 'user', 'user/balance', - 'user/trades', - 'user/orders', - 'user/orders/{order_id}', 'user/deposits', 'user/withdrawals', - 'user/withdraw/{currency}/fee', + 'user/withdrawal/fee', + 'user/trades', + 'orders', + 'orders/{order_id}', ], 'post': [ 'user/request-withdrawal', 'order', ], 'delete': [ - 'user/orders', - 'user/orders/{order_id}', + 'order/all', + 'order', ], }, }, @@ -79063,7 +77363,7 @@ module.exports = class hollaex extends Exchange { } async fetchMarkets (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); // // { // coins: { @@ -79130,17 +77430,17 @@ module.exports = class hollaex extends Exchange { 'quoteId': quoteId, 'active': active, 'precision': { - 'price': this.safeFloat (market, 'increment_price'), - 'amount': this.safeFloat (market, 'increment_size'), + 'price': this.safeNumber (market, 'increment_price'), + 'amount': this.safeNumber (market, 'increment_size'), }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, 'max': undefined }, }, @@ -79151,7 +77451,7 @@ module.exports = class hollaex extends Exchange { } async fetchCurrencies (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); const coins = this.safeValue (response, 'coins', {}); const keys = Object.keys (coins); const result = {}; @@ -79163,8 +77463,8 @@ module.exports = class hollaex extends Exchange { const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'fullname'); const active = this.safeValue (currency, 'active'); - const fee = this.safeFloat (currency, 'withdrawal_fee'); - const precision = this.safeFloat (currency, 'increment_unit'); + const fee = this.safeNumber (currency, 'withdrawal_fee'); + const precision = this.safeNumber (currency, 'increment_unit'); const withdrawalLimits = this.safeValue (currency, 'withdrawal_limits', []); result[code] = { 'id': id, @@ -79177,8 +77477,8 @@ module.exports = class hollaex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min'), - 'max': this.safeFloat (currency, 'max'), + 'min': this.safeNumber (currency, 'min'), + 'max': this.safeNumber (currency, 'max'), }, 'price': { 'min': undefined, @@ -79267,7 +77567,7 @@ module.exports = class hollaex extends Exchange { async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.publicGetTickerAll (this.extend (params)); + const response = await this.publicGetTickers (this.extend (params)); // // { // "bch-usdt": { @@ -79330,27 +77630,27 @@ module.exports = class hollaex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString2 (ticker, 'time', 'timestamp')); - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const result = { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, - 'last': this.safeFloat (ticker, 'last', close), + 'last': this.safeNumber (ticker, 'last', close), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, }; return result; @@ -79408,15 +77708,12 @@ module.exports = class hollaex extends Exchange { const datetime = this.safeString (trade, 'timestamp'); const timestamp = this.parse8601 (datetime); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const quote = market['quote']; @@ -79501,11 +77798,11 @@ module.exports = class hollaex extends Exchange { // return [ this.parse8601 (this.safeString (response, 'time')), - this.safeFloat (response, 'open'), - this.safeFloat (response, 'high'), - this.safeFloat (response, 'low'), - this.safeFloat (response, 'close'), - this.safeFloat (response, 'volume'), + this.safeNumber (response, 'open'), + this.safeNumber (response, 'high'), + this.safeNumber (response, 'low'), + this.safeNumber (response, 'close'), + this.safeNumber (response, 'volume'), ]; } @@ -79530,11 +77827,11 @@ module.exports = class hollaex extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (response, currencyId + '_available'); - account['total'] = this.safeFloat (response, currencyId + '_balance'); + account['free'] = this.safeString (response, currencyId + '_available'); + account['total'] = this.safeString (response, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrder (id, symbol = undefined, params = {}) { @@ -79542,67 +77839,146 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateGetUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateGetOrdersOrderId (this.extend (request, params)); // // { - // "created_at": "2018-03-23T04:14:08.663Z", - // "title": "string", - // "side": "sell", - // "type": "limit", - // "price": 0, - // "size": 0, - // "symbol": "xht-usdt", // "id": "string", - // "created_by": 1, - // "filled": 0 + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } // } // return this.parseOrder (response); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'open': true, + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'status': 'filled', + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = undefined; - const request = {}; + const request = { + // 'symbol': market['id'], + // 'side': 'buy', // 'sell' + // 'status': 'new', // 'filled', 'pfilled', 'canceled' + // 'open': true, + // 'limit': limit, // default 50, max 100 + // 'page': 1, + // 'order_by': 'created_at', // id, ... + // 'order': 'asc', // 'desc' + // 'start_date': this.iso8601 (since), + // 'end_date': this.iso8601 (this.milliseconds ()), + }; if (symbol !== undefined) { market = this.market (symbol); request['symbol'] = market['id']; } - const response = await this.privateGetUserOrders (this.extend (request, params)); + if (since !== undefined) { + request['start_date'] = this.iso8601 (since); + } + if (limit !== undefined) { + request['limit'] = limit; // default 50, max 100 + } + const response = await this.privateGetOrders (this.extend (request, params)); // - // [ - // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 - // } - // ] + // { + // "count": 1, + // "data": [ + // { + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } + // } + // ] + // } // - return this.parseOrders (response, market); + const data = this.safeValue (response, 'data', []); + return this.parseOrders (data, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'new': 'open', + 'pfilled': 'open', + 'filled': 'closed', + 'canceled': 'canceled', + }; + return this.safeString (statuses, status, status); } parseOrder (order, market = undefined) { // - // fetchOpenOrder, fetchOpenOrders + // createOrder, fetchOpenOrder, fetchOpenOrders // // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // }, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, // } // const marketId = this.safeString (order, 'symbol'); @@ -79611,21 +77987,11 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filled'); - let cost = undefined; - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = filled * price; - } - } - const status = (type === 'market') ? 'closed' : 'open'; - const result = { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filled'); + const status = this.parseOrderStatus (this.safeString (order, 'status')); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -79641,40 +78007,56 @@ module.exports = class hollaex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; - return result; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); - const order = { + const request = { 'symbol': market['id'], 'side': side, 'size': amount, 'type': type, + // 'stop': parseFloat (this.priceToPrecision (symbol, stopPrice)), + // 'meta': {}, // other options such as post_only }; if (type !== 'market') { - order['price'] = price; + request['price'] = price; } - const response = await this.privatePostOrder (this.extend (order, params)); + const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop'); + if (stopPrice !== undefined) { + request['stop'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + params = this.omit (params, [ 'stopPrice', 'stop' ]); + } + const response = await this.privatePostOrder (this.extend (request, params)); // // { + // "fee": 0, + // "meta": {}, // "symbol": "xht-usdt", // "side": "sell", - // "size": 1, + // "size": 0.1, // "type": "limit", - // "price": 0.1, + // "price": 1, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, + // "fee_coin": "usdt", // "id": "string", - // "created_by": 34, + // "created_by": 116, // "filled": 0, - // "status": "pending" + // "status": "new", + // "updated_at": "2021-02-17T03:03:19.231Z", + // "created_at": "2021-02-17T03:03:19.231Z", + // "stop": null // } // return this.parseOrder (response, market); @@ -79685,7 +78067,7 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateDeleteUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateDeleteOrder (this.extend (request, params)); // // { // "title": "string", @@ -79710,7 +78092,7 @@ module.exports = class hollaex extends Exchange { market = this.markets (symbol); request['symbol'] = market['id']; } - const response = await this.privateDeleteUserOrders (this.extend (request, params)); + const response = await this.privateDeleteOrderAll (this.extend (request, params)); // // [ // { @@ -79976,7 +78358,7 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_at')); const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const type = this.safeString (transaction, 'type'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); let addressTo = undefined; const addressFrom = undefined; @@ -80006,7 +78388,7 @@ module.exports = class hollaex extends Exchange { } const fee = { 'currency': code, - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), }; return { 'info': transaction, @@ -80105,7 +78487,7 @@ module.exports = class hollaex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],95:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],93:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -80146,7 +78528,7 @@ module.exports = class huobijp extends huobipro { } }; -},{"./base/errors":8,"./huobipro.js":96}],96:[function(require,module,exports){ +},{"./base/errors":9,"./huobipro.js":94}],94:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -80154,6 +78536,7 @@ module.exports = class huobijp extends huobipro { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, ArgumentsRequired, BadSymbol, BadRequest, RequestTimeout, NetworkError } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -80171,7 +78554,9 @@ module.exports = class huobipro extends Exchange { 'hostname': 'api.huobi.pro', // api.testnet.huobi.pro 'pro': true, 'has': { + 'cancelAllOrders': true, 'cancelOrder': true, + 'cancelOrders': true, 'CORS': false, 'createOrder': true, 'fetchBalance': true, @@ -80338,6 +78723,7 @@ module.exports = class huobipro extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.002, @@ -80401,6 +78787,7 @@ module.exports = class huobipro extends Exchange { // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/ 'PNT': 'Penta', 'SBTC': 'Super Bitcoin', + 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706 }, }); } @@ -80465,8 +78852,8 @@ module.exports = class huobipro extends Exchange { 'info': limits, 'limits': { 'amount': { - 'min': this.safeFloat (limits, 'limit-order-must-greater-than'), - 'max': this.safeFloat (limits, 'limit-order-must-less-than'), + 'min': this.safeNumber (limits, 'limit-order-must-greater-than'), + 'max': this.safeNumber (limits, 'limit-order-must-less-than'), }, }, }; @@ -80500,9 +78887,9 @@ module.exports = class huobipro extends Exchange { }; const maker = (base === 'OMG') ? 0 : 0.2 / 100; const taker = (base === 'OMG') ? 0 : 0.2 / 100; - const minAmount = this.safeFloat (market, 'min-order-amt', Math.pow (10, -precision['amount'])); - const maxAmount = this.safeFloat (market, 'max-order-amt'); - const minCost = this.safeFloat (market, 'min-order-value', 0); + const minAmount = this.safeNumber (market, 'min-order-amt', Math.pow (10, -precision['amount'])); + const maxAmount = this.safeNumber (market, 'max-order-amt'); + const minCost = this.safeNumber (market, 'min-order-value', 0); const state = this.safeString (market, 'state'); const active = (state === 'online'); result.push ({ @@ -80581,24 +78968,24 @@ module.exports = class huobipro extends Exchange { let askVolume = undefined; if ('bid' in ticker) { if (Array.isArray (ticker['bid'])) { - bid = this.safeFloat (ticker['bid'], 0); - bidVolume = this.safeFloat (ticker['bid'], 1); + bid = this.safeNumber (ticker['bid'], 0); + bidVolume = this.safeNumber (ticker['bid'], 1); } else { - bid = this.safeFloat (ticker, 'bid'); + bid = this.safeNumber (ticker, 'bid'); bidVolume = this.safeValue (ticker, 'bidSize'); } } if ('ask' in ticker) { if (Array.isArray (ticker['ask'])) { - ask = this.safeFloat (ticker['ask'], 0); - askVolume = this.safeFloat (ticker['ask'], 1); + ask = this.safeNumber (ticker['ask'], 0); + askVolume = this.safeNumber (ticker['ask'], 1); } else { - ask = this.safeFloat (ticker, 'ask'); + ask = this.safeNumber (ticker, 'ask'); askVolume = this.safeValue (ticker, 'askSize'); } } - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -80609,15 +78996,15 @@ module.exports = class huobipro extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -80706,7 +79093,7 @@ module.exports = class huobipro extends Exchange { // } // const ticker = this.parseTicker (response['tick'], market); - const timestamp = this.safeValue (response, 'ts'); + const timestamp = this.safeInteger (response, 'ts'); ticker['timestamp'] = timestamp; ticker['datetime'] = this.iso8601 (timestamp); return ticker; @@ -80775,21 +79162,18 @@ module.exports = class huobipro extends Exchange { type = typeParts[1]; } const takerOrMaker = this.safeString (trade, 'role'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'filled-amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'filled-amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - let feeCost = this.safeFloat (trade, 'filled-fees'); + let feeCost = this.safeNumber (trade, 'filled-fees'); let feeCurrency = undefined; if (market !== undefined) { feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-currency')); } - const filledPoints = this.safeFloat (trade, 'filled-points'); + const filledPoints = this.safeNumber (trade, 'filled-points'); if (filledPoints !== undefined) { if ((feeCost === undefined) || (feeCost === 0.0)) { feeCost = filledPoints; @@ -80903,11 +79287,11 @@ module.exports = class huobipro extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -81004,11 +79388,11 @@ module.exports = class huobipro extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'deposit-min-amount'), + 'min': this.safeNumber (currency, 'deposit-min-amount'), 'max': Math.pow (10, precision), }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw-min-amount'), + 'min': this.safeNumber (currency, 'withdraw-min-amount'), 'max': Math.pow (10, precision), }, }, @@ -81039,14 +79423,14 @@ module.exports = class huobipro extends Exchange { account = this.account (); } if (balance['type'] === 'trade') { - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); } if (balance['type'] === 'frozen') { - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrdersByStates (states, symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -81221,28 +79605,14 @@ module.exports = class huobipro extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (order, 'created-at'); - let amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount - if ((type === 'market') && (side === 'buy')) { - amount = (status === 'closed') ? filled : undefined; - } - let price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - const cost = this.safeFloat2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - // if cost is defined and filled is not zero - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - const feeCost = this.safeFloat2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees + const cost = this.safeNumber2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo + const feeCost = this.safeNumber2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -81254,7 +79624,7 @@ module.exports = class huobipro extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -81268,15 +79638,15 @@ module.exports = class huobipro extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -81350,26 +79720,82 @@ module.exports = class huobipro extends Exchange { }); } - currencyToPrecision (currency, fee) { - return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); + async cancelOrders (ids, symbol = undefined, params = {}) { + await this.loadMarkets (); + const clientOrderIds = this.safeValue2 (params, 'clientOrderIds', 'client-order-ids'); + params = this.omit (params, [ 'clientOrderIds', 'client-order-ids' ]); + const request = {}; + if (clientOrderIds === undefined) { + request['order-ids'] = ids; + } else { + request['client-order-ids'] = clientOrderIds; + } + const response = await this.privatePostOrderOrdersBatchcancel (this.extend (request, params)); + // + // { + // "status": "ok", + // "data": { + // "success": [ + // "5983466" + // ], + // "failed": [ + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "first" + // }, + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "second" + // }, + // { + // "err-msg": "The record is not found.", + // "order-id": "", + // "err-code": "base-not-found", + // "client-order-id": "third" + // } + // ] + // } + // } + // + return response; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (market[key], cost)), + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts + // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default + // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok + // 'side': 'buy', // or 'sell' + // 'size': 100, // the number of orders to cancel 1-100 }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.privatePostOrderOrdersBatchCancelOpenOrders (this.extend (request, params)); + // + // { + // code: 200, + // data: { + // "success-count": 2, + // "failed-count": 0, + // "next-id": 5454600 + // } + // } + // + return response; + } + + currencyToPrecision (currency, fee) { + return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); } parseDepositAddress (depositAddress, currency = undefined) { @@ -81511,7 +79937,7 @@ module.exports = class huobipro extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const tag = this.safeString (transaction, 'address-tag'); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -81524,7 +79950,7 @@ module.exports = class huobipro extends Exchange { 'address': this.safeString (transaction, 'address'), 'tag': tag, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -81654,504 +80080,7 @@ module.exports = class huobipro extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],97:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class ice3x extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'ice3x', - 'name': 'ICE3X', - 'countries': [ 'ZA' ], // South Africa - 'rateLimit': 1000, - 'version': 'v1', - 'has': { - 'cancelOrder': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchCurrencies': true, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTrades': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg', - 'api': 'https://ice3x.com/api', - 'www': 'https://ice3x.com', // 'https://ice3x.co.za', - 'doc': 'https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017', - 'fees': [ - 'https://help.ice3.com/support/solutions/articles/11000033293-trading-fees', - 'https://help.ice3.com/support/solutions/articles/11000033288-fees-explained', - 'https://help.ice3.com/support/solutions/articles/11000008131-what-are-your-fiat-deposit-and-withdrawal-fees-', - 'https://help.ice3.com/support/solutions/articles/11000033289-deposit-fees', - ], - 'referral': 'https://ice3x.com?ref=14341802', - }, - 'api': { - 'public': { - 'get': [ - 'currency/list', - 'currency/info', - 'pair/list', - 'pair/info', - 'stats/marketdepthfull', - 'stats/marketdepthbtcav', - 'stats/marketdepth', - 'orderbook/info', - 'trade/list', - 'trade/info', - ], - }, - 'private': { - 'post': [ - 'balance/list', - 'balance/info', - 'order/new', - 'order/cancel', - 'order/list', - 'order/info', - 'trade/list', - 'trade/info', - 'transaction/list', - 'transaction/info', - 'invoice/list', - 'invoice/info', - 'invoice/pdf', - ], - }, - }, - 'fees': { - 'trading': { - 'maker': 0.005, - 'taker': 0.005, - }, - }, - 'precision': { - 'amount': 8, - 'price': 8, - }, - }); - } - - async fetchCurrencies (params = {}) { - const response = await this.publicGetCurrencyList (params); - const currencies = response['response']['entities']; - const precision = this.precision['amount']; - const result = {}; - for (let i = 0; i < currencies.length; i++) { - const currency = currencies[i]; - const id = this.safeString (currency, 'currency_id'); - const currencyId = this.safeString (currency, 'iso'); - const code = this.safeCurrencyCode (currencyId); - result[code] = { - 'id': id, - 'code': code, - 'name': currency['name'], - 'active': true, - 'precision': precision, - 'limits': { - 'amount': { - 'min': undefined, - 'max': Math.pow (10, precision), - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': Math.pow (10, precision), - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - }, - 'info': currency, - 'fee': undefined, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - if (this.currencies_by_id === undefined) { - this.currencies = await this.fetchCurrencies (); - this.currencies_by_id = this.indexBy (this.currencies, 'id'); - } - const response = await this.publicGetPairList (params); - const markets = this.safeValue (response['response'], 'entities'); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = this.safeString (market, 'pair_id'); - const baseId = this.safeString (market, 'currency_id_from'); - const quoteId = this.safeString (market, 'currency_id_to'); - const baseCurrency = this.currencies_by_id[baseId]; - const quoteCurrency = this.currencies_by_id[quoteId]; - const base = baseCurrency['code']; - const quote = quoteCurrency['code']; - const symbol = base + '/' + quote; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': undefined, - 'info': market, - 'precision': this.precision, - 'limits': this.limits, - }); - } - return result; - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.milliseconds (); - const symbol = market['symbol']; - const last = this.safeFloat (ticker, 'last_price'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'max_bid'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'min_ask'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'vol'), - 'info': ticker, - }; - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetStatsMarketdepthfull (this.extend (request, params)); - const ticker = this.safeValue (response['response'], 'entity'); - return this.parseTicker (ticker, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetStatsMarketdepthfull (params); - const tickers = this.safeValue (response['response'], 'entities'); - const result = {}; - for (let i = 0; i < tickers.length; i++) { - const ticker = tickers[i]; - const marketId = this.safeString (ticker, 'pair_id'); - const market = this.safeValue (this.marketsById, marketId); - if (market !== undefined) { - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); - } - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'pair_id': this.marketId (symbol), - }; - if (limit !== undefined) { - const type = this.safeString (params, 'type'); - if ((type !== 'ask') && (type !== 'bid')) { - // eslint-disable-next-line quotes - throw new ArgumentsRequired (this.id + " fetchOrderBook() requires an exchange-specific extra 'type' param ('bid' or 'ask') when used with a limit"); - } else { - request['items_per_page'] = limit; - } - } - const response = await this.publicGetOrderbookInfo (this.extend (request, params)); - const orderbook = this.safeValue (response['response'], 'entities'); - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.safeTimestamp (trade, 'created'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } - const type = 'limit'; - const side = this.safeString (trade, 'type'); - const id = this.safeString (trade, 'trade_id'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'id': id, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': type, - 'side': side, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetTradeList (this.extend (request, params)); - const trades = this.safeValue (response['response'], 'entities'); - return this.parseTrades (trades, market, since, limit); - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostBalanceList (params); - const result = { 'info': response }; - const balances = this.safeValue (response['response'], 'entities', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - // currency ids are numeric strings - const currencyId = this.safeString (balance, 'currency_id'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseOrder (order, market = undefined) { - const pairId = this.safeInteger (order, 'pair_id'); - let symbol = undefined; - if (pairId && !market && (pairId in this.marketsById)) { - market = this.marketsById[pairId]; - symbol = market['symbol']; - } - const timestamp = this.safeTimestamp (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - let status = this.safeInteger (order, 'active'); - let remaining = this.safeFloat (order, 'remaining'); - let filled = undefined; - if (status === 1) { - status = 'open'; - } else { - status = 'closed'; - remaining = 0; - filled = amount; - } - let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - }; - if (market !== undefined) { - fee['currency'] = market['quote']; - } - } - return { - 'id': this.safeString (order, 'order_id'), - 'clientOrderId': undefined, - 'datetime': this.iso8601 (timestamp), - 'timestamp': timestamp, - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': 'limit', - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': this.safeString (order, 'type'), - 'price': price, - 'stopPrice': undefined, - 'cost': undefined, - 'amount': amount, - 'filled': filled, - 'remaining': remaining, - 'trades': undefined, - 'fee': fee, - 'info': order, - 'average': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - 'type': side, - 'amount': amount, - 'price': price, - }; - const response = await this.privatePostOrderNew (this.extend (request, params)); - const order = this.parseOrder ({ - 'order_id': response['response']['entity']['order_id'], - 'created': this.seconds (), - 'active': 1, - 'type': side, - 'price': price, - 'volume': amount, - 'remaining': amount, - 'info': response, - }, market); - return order; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - const request = { - 'order_id': id, - }; - return await this.privatePostOrderCancel (this.extend (request, params)); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'order _id': id, - }; - const response = await this.privatePostOrderInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const order = this.safeValue (data, 'entity'); - return this.parseOrder (order); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.privatePostOrderList (params); - const data = this.safeValue (response, 'response', {}); - const orders = this.safeValue (data, 'entities', []); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - return this.parseOrders (orders, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - if (limit !== undefined) { - request['items_per_page'] = limit; - } - if (since !== undefined) { - request['date_from'] = parseInt (since / 1000); - } - const response = await this.privatePostTradeList (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const trades = this.safeValue (data, 'entities', []); - return this.parseTrades (trades, market, since, limit); - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency_id': currency['id'], - }; - const response = await this.privatePostBalanceInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const balance = this.safeValue (data, 'entity', {}); - const address = this.safeString (balance, 'address'); - const status = address ? 'ok' : 'none'; - return { - 'currency': code, - 'address': address, - 'tag': undefined, - 'status': status, - 'info': response, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/' + this.version + '/' + path; - if (api === 'public') { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } - } else { - this.checkRequiredCredentials (); - body = this.urlencode (this.extend ({ - 'nonce': this.nonce (), - }, params)); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': this.hmac (this.encode (body), this.encode (this.secret), 'sha512'), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const response = await this.fetch2 (path, api, method, params, headers, body); - const errors = this.safeValue (response, 'errors'); - const data = this.safeValue (response, 'response'); - if (errors || !data) { - const authErrorKeys = [ 'Key', 'user_id', 'Sign' ]; - for (let i = 0; i < authErrorKeys.length; i++) { - const errorKey = authErrorKeys[i]; - const errorMessage = this.safeString (errors, errorKey); - if (!errorMessage) { - continue; - } - if (errorKey === 'user_id' && errorMessage.indexOf ('authorization') < 0) { - continue; - } - throw new AuthenticationError (errorMessage); - } - throw new ExchangeError (this.json (errors)); - } - return response; - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],98:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],95:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -82159,6 +80088,7 @@ module.exports = class ice3x extends Exchange { const Exchange = require ('./base/Exchange'); const { PAD_WITH_ZERO } = require ('./base/functions/number'); const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported, InvalidAddress, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -82395,14 +80325,6 @@ module.exports = class idex extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // { // market: 'DIL-ETH', @@ -82422,16 +80344,16 @@ module.exports = class idex extends Exchange { // } const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'baseVolume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'baseVolume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'open'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const close = this.safeFloat (ticker, 'close'); - const ask = this.safeFloat (ticker, 'ask'); - const bid = this.safeFloat (ticker, 'bid'); - let percentage = this.safeFloat (ticker, 'percentChange'); + const open = this.safeNumber (ticker, 'open'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const close = this.safeNumber (ticker, 'close'); + const ask = this.safeNumber (ticker, 'ask'); + const bid = this.safeNumber (ticker, 'bid'); + let percentage = this.safeNumber (ticker, 'percentChange'); if (percentage !== undefined) { percentage = 1 + percentage / 100; } @@ -82507,11 +80429,11 @@ module.exports = class idex extends Exchange { // sequence: 3853 // } const timestamp = this.safeInteger (ohlcv, 'start'); - const open = this.safeFloat (ohlcv, 'open'); - const high = this.safeFloat (ohlcv, 'high'); - const low = this.safeFloat (ohlcv, 'low'); - const close = this.safeFloat (ohlcv, 'close'); - const volume = this.safeFloat (ohlcv, 'volume'); + const open = this.safeNumber (ohlcv, 'open'); + const high = this.safeNumber (ohlcv, 'high'); + const low = this.safeNumber (ohlcv, 'low'); + const close = this.safeNumber (ohlcv, 'close'); + const volume = this.safeNumber (ohlcv, 'volume'); return [ timestamp, open, high, low, close, volume ]; } @@ -82573,9 +80495,14 @@ module.exports = class idex extends Exchange { // txStatus: 'mined' // } const id = this.safeString (trade, 'fillId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'quoteQuantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteQuantity'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const timestamp = this.safeInteger (trade, 'time'); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); @@ -82584,7 +80511,7 @@ module.exports = class idex extends Exchange { const oppositeSide = (makerSide === 'buy') ? 'sell' : 'buy'; const side = this.safeString (trade, 'side', oppositeSide); const takerOrMaker = this.safeString (trade, 'liquidity', 'taker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); @@ -82657,8 +80584,8 @@ module.exports = class idex extends Exchange { const result = []; for (let i = 0; i < bookSide.length; i++) { const order = bookSide[i]; - const price = this.safeFloat (order, 0); - const amount = this.safeFloat (order, 1); + const price = this.safeNumber (order, 0); + const amount = this.safeNumber (order, 1); const orderCount = this.safeInteger (order, 2); result.push ([ price, amount, orderCount ]); } @@ -82745,16 +80672,13 @@ module.exports = class idex extends Exchange { const entry = response[i]; const currencyId = this.safeString (entry, 'asset'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (entry, 'quantity'); - const free = this.safeFloat (entry, 'availableForTrade'); - const used = this.safeFloat (entry, 'locked'); - result[code] = { - 'free': free, - 'used': used, - 'total': total, - }; + const account = this.account (); + account['total'] = this.safeString (entry, 'quantity'); + account['free'] = this.safeString (entry, 'availableForTrade'); + account['used'] = this.safeString (entry, 'locked'); + result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -82975,10 +80899,10 @@ module.exports = class idex extends Exchange { const symbol = this.safeSymbol (marketId, market, '-'); const trades = this.parseTrades (fills, market); const type = this.safeString (order, 'type'); - const amount = this.safeFloat (order, 'originalQuantity'); - const filled = this.safeFloat (order, 'executedQuantity'); - const average = this.safeFloat (order, 'avgExecutionPrice'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'originalQuantity'); + const filled = this.safeNumber (order, 'executedQuantity'); + const average = this.safeNumber (order, 'avgExecutionPrice'); + const price = this.safeNumber (order, 'price'); const rawStatus = this.safeString (order, 'status'); const status = this.parseOrderStatus (rawStatus); const fee = { @@ -83087,7 +81011,7 @@ module.exports = class idex extends Exchange { throw new NotSupported (this.id + ' quoteOrderQuantity is not supported for ' + type + ' orders, only supported for market orders'); } amountEnum = 1; - amount = this.safeFloat (params, 'quoteOrderQuantity'); + amount = this.safeNumber (params, 'quoteOrderQuantity'); } const sideEnum = (side === 'buy') ? 0 : 1; const walletBytes = this.remove0xPrefix (this.walletAddress); @@ -83390,13 +81314,13 @@ module.exports = class idex extends Exchange { } const id = this.safeString2 (transaction, 'depositId', 'withdrawId'); const code = this.safeCurrencyCode (this.safeString (transaction, 'asset'), currency); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const txid = this.safeString (transaction, 'txId'); const timestamp = this.safeInteger (transaction, 'txTime'); let fee = undefined; if ('fee' in transaction) { fee = { - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), 'currency': 'ETH', }; } @@ -83454,12 +81378,13 @@ module.exports = class idex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],99:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],96:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -83583,11 +81508,11 @@ module.exports = class independentreserve extends Exchange { const currencyId = this.safeString (balance, 'CurrencyCode'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'AvailableBalance'); - account['total'] = this.safeFloat (balance, 'TotalBalance'); + account['free'] = this.safeString (balance, 'AvailableBalance'); + account['total'] = this.safeString (balance, 'TotalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -83608,16 +81533,16 @@ module.exports = class independentreserve extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'LastPrice'); + const last = this.safeNumber (ticker, 'LastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'DayHighestPrice'), - 'low': this.safeFloat (ticker, 'DayLowestPrice'), - 'bid': this.safeFloat (ticker, 'CurrentHighestBidPrice'), + 'high': this.safeNumber (ticker, 'DayHighestPrice'), + 'low': this.safeNumber (ticker, 'DayLowestPrice'), + 'bid': this.safeNumber (ticker, 'CurrentHighestBidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'CurrentLowestOfferPrice'), + 'ask': this.safeNumber (ticker, 'CurrentLowestOfferPrice'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -83626,8 +81551,8 @@ module.exports = class independentreserve extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'DayAvgPrice'), - 'baseVolume': this.safeFloat (ticker, 'DayVolumeXbtInSecondaryCurrrency'), + 'average': this.safeNumber (ticker, 'DayAvgPrice'), + 'baseVolume': this.safeNumber (ticker, 'DayVolumeXbtInSecondaryCurrrency'), 'quoteVolume': undefined, 'info': ticker, }; @@ -83706,20 +81631,10 @@ module.exports = class independentreserve extends Exchange { orderType = 'limit'; } const timestamp = this.parse8601 (this.safeString (order, 'CreatedTimestampUtc')); - const amount = this.safeFloat2 (order, 'VolumeOrdered', 'Volume'); - let filled = this.safeFloat (order, 'VolumeFilled'); - let remaining = this.safeFloat (order, 'Outstanding'); - if (filled === undefined) { - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (0, amount - remaining); - } - } - if (remaining === undefined) { - if ((filled !== undefined) && (amount !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const feeRate = this.safeFloat (order, 'FeePercent'); + const amount = this.safeNumber2 (order, 'VolumeOrdered', 'Volume'); + const filled = this.safeNumber (order, 'VolumeFilled'); + const remaining = this.safeNumber (order, 'Outstanding'); + const feeRate = this.safeNumber (order, 'FeePercent'); let feeCost = undefined; if (feeRate !== undefined) { feeCost = feeRate * filled; @@ -83731,10 +81646,10 @@ module.exports = class independentreserve extends Exchange { }; const id = this.safeString (order, 'OrderGuid'); const status = this.parseOrderStatus (this.safeString (order, 'Status')); - const cost = this.safeFloat (order, 'Value'); - const average = this.safeFloat (order, 'AvgPrice'); - const price = this.safeFloat (order, 'Price', average); - return { + const cost = this.safeNumber (order, 'Value'); + const average = this.safeNumber (order, 'AvgPrice'); + const price = this.safeNumber (order, 'Price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -83756,7 +81671,7 @@ module.exports = class independentreserve extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -83844,14 +81759,11 @@ module.exports = class independentreserve extends Exchange { const timestamp = this.parse8601 (trade['TradeTimestampUtc']); const id = this.safeString (trade, 'TradeGuid'); const orderId = this.safeString (trade, 'OrderGuid'); - const price = this.safeFloat2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); - const amount = this.safeFloat2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); + const amountString = this.safeString2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const baseId = this.safeString (trade, 'PrimaryCurrencyCode'); const quoteId = this.safeString (trade, 'SecondaryCurrencyCode'); let marketId = undefined; @@ -83964,13 +81876,14 @@ module.exports = class independentreserve extends Exchange { } }; -},{"./base/Exchange":6}],100:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],97:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, InvalidOrder, OrderNotFound, AuthenticationError, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -84131,7 +82044,7 @@ module.exports = class indodax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const taker = this.safeFloat (market, 'trade_fee_percent'); + const taker = this.safeNumber (market, 'trade_fee_percent'); const isMaintenance = this.safeInteger (market, 'is_maintenance'); const active = (isMaintenance) ? false : true; const pricePrecision = this.safeInteger (market, 'price_round'); @@ -84141,11 +82054,11 @@ module.exports = class indodax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'trade_min_traded_currency'), + 'min': this.safeNumber (market, 'trade_min_traded_currency'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'trade_min_base_currency'), + 'min': this.safeNumber (market, 'trade_min_base_currency'), 'max': undefined, }, 'cost': { @@ -84183,11 +82096,11 @@ module.exports = class indodax extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (used, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (used, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -84224,16 +82137,16 @@ module.exports = class indodax extends Exchange { const timestamp = this.safeTimestamp (ticker, 'server_time'); const baseVolume = 'vol_' + market['baseId'].toLowerCase (); const quoteVolume = 'vol_' + market['quoteId'].toLowerCase (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -84243,8 +82156,8 @@ module.exports = class indodax extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, baseVolume), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, baseVolume), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -84258,14 +82171,11 @@ module.exports = class indodax extends Exchange { } const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -84320,7 +82230,7 @@ module.exports = class indodax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status', 'open')); let symbol = undefined; let cost = undefined; - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let amount = undefined; let remaining = undefined; let filled = undefined; @@ -84334,18 +82244,18 @@ module.exports = class indodax extends Exchange { if ((market['baseId'] === 'idr') && ('remain_rp' in order)) { baseId = 'rp'; } - cost = this.safeFloat (order, 'order_' + quoteId); + cost = this.safeNumber (order, 'order_' + quoteId); if (cost) { amount = cost / price; - const remainingCost = this.safeFloat (order, 'remain_' + quoteId); + const remainingCost = this.safeNumber (order, 'remain_' + quoteId); if (remainingCost !== undefined) { remaining = remainingCost / price; filled = amount - remaining; } } else { - amount = this.safeFloat (order, 'order_' + baseId); + amount = this.safeNumber (order, 'order_' + baseId); cost = price * amount; - remaining = this.safeFloat (order, 'remain_' + baseId); + remaining = this.safeNumber (order, 'remain_' + baseId); filled = amount - remaining; } } @@ -84585,13 +82495,14 @@ module.exports = class indodax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],101:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],98:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -84702,25 +82613,25 @@ module.exports = class itbit extends Exchange { throw new ExchangeError (this.id + ' fetchTicker returned a bad response: ' + this.json (ticker)); } const timestamp = this.parse8601 (serverTimeUTC); - const vwap = this.safeFloat (ticker, 'vwap24h'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); + const vwap = this.safeNumber (ticker, 'vwap24h'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'openToday'), + 'open': this.safeNumber (ticker, 'openToday'), 'close': last, 'last': last, 'previousClose': undefined, @@ -84767,23 +82678,20 @@ module.exports = class itbit extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const side = this.safeString (trade, 'direction'); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'commissionPaid'); + let feeCost = this.safeNumber (trade, 'commissionPaid'); const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - let rebatesApplied = this.safeFloat (trade, 'rebatesApplied'); + let rebatesApplied = this.safeNumber (trade, 'rebatesApplied'); if (rebatesApplied !== undefined) { rebatesApplied = -rebatesApplied; } const rebateCurrencyId = this.safeString (trade, 'rebateCurrency'); const rebateCurrency = this.safeCurrencyCode (rebateCurrencyId); - const price = this.safeFloat2 (trade, 'price', 'rate'); - const amount = this.safeFloat2 (trade, 'currency1Amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'price', 'rate'); + const amountString = this.safeString2 (trade, 'currency1Amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; const marketId = this.safeString (trade, 'instrument'); if (marketId !== undefined) { @@ -84905,7 +82813,7 @@ module.exports = class itbit extends Exchange { 'txid': txnHash, 'type': transactionType, 'status': status, - 'amount': this.safeFloat (item, 'amount'), + 'amount': this.safeNumber (item, 'amount'), 'fee': undefined, 'info': item, }); @@ -85005,11 +82913,11 @@ module.exports = class itbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchWallets (params = {}) { @@ -85100,26 +83008,16 @@ module.exports = class itbit extends Exchange { const type = this.safeString (order, 'type'); const symbol = this.markets_by_id[order['instrument']]['symbol']; const timestamp = this.parse8601 (order['createdTime']); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'amountFilled'); - let remaining = undefined; - let cost = undefined; + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'amountFilled'); const fee = undefined; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'volumeWeightedAveragePrice'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'volumeWeightedAveragePrice'); const clientOrderId = this.safeString (order, 'clientOrderIdentifier'); const id = this.safeString (order, 'id'); const postOnlyString = this.safeString (order, 'postOnly'); const postOnly = (postOnlyString === 'True'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -85134,15 +83032,15 @@ module.exports = class itbit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, // 'trades': this.parseTrades (order['trades'], market), 'trades': undefined, - }; + }); } nonce () { @@ -85240,7 +83138,7 @@ module.exports = class itbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],102:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],99:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -85248,6 +83146,7 @@ module.exports = class itbit extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeNotAvailable, ArgumentsRequired, PermissionDenied, AuthenticationError, ExchangeError, OrderNotFound, DDoSProtection, InvalidNonce, InsufficientFunds, CancelPending, InvalidOrder, InvalidAddress, RateLimitExceeded } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -85540,26 +83439,38 @@ module.exports = class kraken extends Exchange { // } // } // - const keys = Object.keys (response['result']); + const markets = this.safeValue (response, 'result', {}); + const keys = Object.keys (markets); let result = []; for (let i = 0; i < keys.length; i++) { const id = keys[i]; - const market = response['result'][id]; - const baseId = market['base']; - const quoteId = market['quote']; + const market = markets[id]; + const baseId = this.safeString (market, 'base'); + const quoteId = this.safeString (market, 'quote'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const darkpool = id.indexOf ('.d') >= 0; - const symbol = darkpool ? market['altname'] : (base + '/' + quote); + const altname = this.safeString (market, 'altname'); + const symbol = darkpool ? altname : (base + '/' + quote); + const makerFees = this.safeValue (market, 'fees_maker', []); + const firstMakerFee = this.safeValue (makerFees, 0, []); + const firstMakerFeeRate = this.safeNumber (firstMakerFee, 1); let maker = undefined; - if ('fees_maker' in market) { - maker = parseFloat (market['fees_maker'][0][1]) / 100; + if (firstMakerFeeRate !== undefined) { + maker = parseFloat (firstMakerFeeRate) / 100; + } + const takerFees = this.safeValue (market, 'fees', []); + const firstTakerFee = this.safeValue (takerFees, 0, []); + const firstTakerFeeRate = this.safeNumber (firstTakerFee, 1); + let taker = undefined; + if (firstTakerFeeRate !== undefined) { + taker = parseFloat (firstTakerFeeRate) / 100; } const precision = { - 'amount': market['lot_decimals'], - 'price': market['pair_decimals'], + 'amount': this.safeInteger (market, 'lot_decimals'), + 'price': this.safeInteger (market, 'pair_decimals'), }; - const minAmount = this.safeFloat (market, 'ordermin'); + const minAmount = this.safeNumber (market, 'ordermin'); result.push ({ 'id': id, 'symbol': symbol, @@ -85571,7 +83482,7 @@ module.exports = class kraken extends Exchange { 'info': market, 'altname': market['altname'], 'maker': maker, - 'taker': parseFloat (market['fees'][0][1]) / 100, + 'taker': taker, 'active': true, 'precision': precision, 'limits': { @@ -85694,7 +83605,7 @@ module.exports = class kraken extends Exchange { await this.loadMarkets (); this.checkRequiredCredentials (); const response = await this.privatePostTradeVolume (params); - const tradedVolume = this.safeFloat (response['result'], 'volume'); + const tradedVolume = this.safeNumber (response['result'], 'volume'); const tiers = this.fees['trading']['tiers']; let taker = tiers['taker'][1]; let maker = tiers['maker'][1]; @@ -85716,8 +83627,8 @@ module.exports = class kraken extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); const timestamp = this.safeInteger (bidask, 2); return [ price, amount, timestamp ]; } @@ -85755,7 +83666,14 @@ module.exports = class kraken extends Exchange { // } // const result = this.safeValue (response, 'result', {}); - const orderbook = this.safeValue (result, market['id']); + let orderbook = this.safeValue (result, market['id']); + // sometimes kraken returns wsname instead of market id + // https://github.com/ccxt/ccxt/issues/8662 + const marketInfo = this.safeValue (market, 'info', {}); + const wsName = this.safeValue (marketInfo, 'wsname'); + if (wsName !== undefined) { + orderbook = this.safeValue (result, wsName, orderbook); + } return this.parseOrderBook (orderbook); } @@ -85783,7 +83701,7 @@ module.exports = class kraken extends Exchange { 'ask': parseFloat (ticker['a'][0]), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'o'), + 'open': this.safeNumber (ticker, 'o'), 'close': last, 'last': last, 'previousClose': undefined, @@ -85854,11 +83772,11 @@ module.exports = class kraken extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 6), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 6), ]; } @@ -85925,24 +83843,24 @@ module.exports = class kraken extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'asset'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); } else { direction = 'in'; } - const time = this.safeFloat (item, 'time'); + const time = this.safeNumber (item, 'time'); let timestamp = undefined; if (time !== undefined) { timestamp = parseInt (time * 1000); } const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -86066,9 +83984,8 @@ module.exports = class kraken extends Exchange { let timestamp = undefined; let side = undefined; let type = undefined; - let price = undefined; - let amount = undefined; - let cost = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; let orderId = undefined; let fee = undefined; @@ -86077,8 +83994,8 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 2); side = (trade[3] === 's') ? 'sell' : 'buy'; type = (trade[4] === 'l') ? 'limit' : 'market'; - price = this.safeFloat (trade, 0); - amount = this.safeFloat (trade, 1); + priceString = this.safeString (trade, 0); + amountString = this.safeString (trade, 1); const tradeLength = trade.length; if (tradeLength > 6) { id = this.safeString (trade, 6); // artificially added as per #1794 @@ -86099,15 +84016,15 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 'time'); side = this.safeString (trade, 'type'); type = this.safeString (trade, 'ordertype'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'vol'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'vol'); if ('fee' in trade) { let currency = undefined; if (market !== undefined) { currency = market['quote']; } fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': currency, }; } @@ -86115,11 +84032,9 @@ module.exports = class kraken extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': orderId, @@ -86194,10 +84109,10 @@ module.exports = class kraken extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -86226,15 +84141,15 @@ module.exports = class kraken extends Exchange { if (type === 'limit') { request['price'] = this.priceToPrecision (symbol, price); } else if ((type === 'stop-loss') || (type === 'take-profit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice', price); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice', price); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a price/stopPrice parameter for a ' + type + ' order'); } else { request['price'] = this.priceToPrecision (symbol, stopPrice); } } else if ((type === 'stop-loss-limit') || (type === 'take-profit-limit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice'); - const limitPrice = this.safeFloat (params, 'price2'); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice'); + const limitPrice = this.safeNumber (params, 'price2'); const stopPriceDefined = (stopPrice !== undefined); const limitPriceDefined = (limitPrice !== undefined); if (stopPriceDefined && limitPriceDefined) { @@ -86343,10 +84258,10 @@ module.exports = class kraken extends Exchange { if (orderDescription !== undefined) { const parts = orderDescription.split (' '); side = this.safeString (parts, 0); - amount = this.safeFloat (parts, 1); + amount = this.safeNumber (parts, 1); marketId = this.safeString (parts, 2); type = this.safeString (parts, 4); - price = this.safeFloat (parts, 5); + price = this.safeNumber (parts, 5); } side = this.safeString (description, 'type', side); type = this.safeString (description, 'ordertype', type); @@ -86360,27 +84275,23 @@ module.exports = class kraken extends Exchange { market = this.getDelistedMarketById (marketId); } const timestamp = this.safeTimestamp (order, 'opentm'); - amount = this.safeFloat (order, 'vol', amount); - const filled = this.safeFloat (order, 'vol_exec'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = amount - filled; - } + amount = this.safeNumber (order, 'vol', amount); + const filled = this.safeNumber (order, 'vol_exec'); let fee = undefined; - const cost = this.safeFloat (order, 'cost'); - price = this.safeFloat (description, 'price', price); + const cost = this.safeNumber (order, 'cost'); + price = this.safeNumber (description, 'price', price); if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (description, 'price2'); + price = this.safeNumber (description, 'price2'); } if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (order, 'price', price); + price = this.safeNumber (order, 'price', price); } - const average = this.safeFloat (order, 'price'); + const average = this.safeNumber (order, 'price'); if (market !== undefined) { symbol = market['symbol']; if ('fee' in order) { const flags = order['oflags']; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); fee = { 'cost': feeCost, 'rate': undefined, @@ -86404,8 +84315,8 @@ module.exports = class kraken extends Exchange { if (rawTrades !== undefined) { trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id }); } - const stopPrice = this.safeFloat (order, 'stopprice'); - return { + const stopPrice = this.safeNumber (order, 'stopprice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -86424,10 +84335,10 @@ module.exports = class kraken extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -86777,10 +84688,10 @@ module.exports = class kraken extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const address = this.safeString (transaction, 'info'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.safeString (transaction, 'type'); // injected from the outside - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost === undefined) { if (type === 'deposit') { feeCost = 0; @@ -86957,7 +84868,7 @@ module.exports = class kraken extends Exchange { throw new ExchangeError (this.id + " withdraw() requires a 'key' parameter (withdrawal key name, as set up on your account)"); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { // 'txid': 'comma delimited list of transaction ids to restrict output to', @@ -87091,13 +85002,14 @@ module.exports = class kraken extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],103:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],100:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, InvalidNonce, NotSupported, BadRequest, AuthenticationError, BadSymbol, RateLimitExceeded, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -87139,6 +85051,7 @@ module.exports = class kucoin extends Exchange { 'fetchTrades': true, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg', @@ -87146,6 +85059,7 @@ module.exports = class kucoin extends Exchange { 'api': { 'public': 'https://openapi-v2.kucoin.com', 'private': 'https://openapi-v2.kucoin.com', + 'futuresPrivate': 'https://api-futures.kucoin.com', }, 'test': { 'public': 'https://openapi-sandbox.kucoin.com', @@ -87254,6 +85168,15 @@ module.exports = class kucoin extends Exchange { 'stop-order/cancel', ], }, + 'futuresPrivate': { + 'get': [ + 'account-overview', + 'positions', + ], + 'post': [ + 'transfer-out', + ], + }, }, 'timeframes': { '1m': '1min', @@ -87278,6 +85201,7 @@ module.exports = class kucoin extends Exchange { 'order_not_exist_or_not_allow_to_cancel': InvalidOrder, // {"code":"400100","msg":"order_not_exist_or_not_allow_to_cancel"} 'Order size below the minimum requirement.': InvalidOrder, // {"code":"400100","msg":"Order size below the minimum requirement."} 'The withdrawal amount is below the minimum requirement.': ExchangeError, // {"code":"400100","msg":"The withdrawal amount is below the minimum requirement."} + 'Unsuccessful! Exceeded the max. funds out-transfer limit': InsufficientFunds, // {"code":"200000","msg":"Unsuccessful! Exceeded the max. funds out-transfer limit"} '400': BadRequest, '401': AuthenticationError, '403': NotSupported, @@ -87334,9 +85258,7 @@ module.exports = class kucoin extends Exchange { 'version': 'v1', 'symbolSeparator': '-', 'fetchMyTradesMethod': 'private_get_fills', - 'fetchBalance': { - 'type': 'trade', // or 'main' - }, + 'fetchBalance': 'trade', // endpoint versions 'versions': { 'public': { @@ -87356,6 +85278,25 @@ module.exports = class kucoin extends Exchange { 'accounts/sub-transfer': 'v2', }, }, + 'futuresPrivate': { + 'GET': { + 'account-overview': 'v1', + 'positions': 'v1', + }, + 'POST': { + 'transfer-out': 'v2', + }, + }, + }, + 'accountsByType': { + 'trade': 'trade', + 'trading': 'trade', + 'margin': 'margin', + 'main': 'main', + 'futures': 'contract', + 'contract': 'contract', + 'pool': 'pool', + 'pool-x': 'pool', }, }, }); @@ -87436,11 +85377,11 @@ module.exports = class kucoin extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const active = this.safeValue (market, 'enableTrading'); - const baseMaxSize = this.safeFloat (market, 'baseMaxSize'); - const baseMinSize = this.safeFloat (market, 'baseMinSize'); - const quoteMaxSize = this.safeFloat (market, 'quoteMaxSize'); - const quoteMinSize = this.safeFloat (market, 'quoteMinSize'); - // const quoteIncrement = this.safeFloat (market, 'quoteIncrement'); + const baseMaxSize = this.safeNumber (market, 'baseMaxSize'); + const baseMinSize = this.safeNumber (market, 'baseMinSize'); + const quoteMaxSize = this.safeNumber (market, 'quoteMaxSize'); + const quoteMinSize = this.safeNumber (market, 'quoteMinSize'); + // const quoteIncrement = this.safeNumber (market, 'quoteIncrement'); const precision = { 'amount': this.precisionFromString (this.safeString (market, 'baseIncrement')), 'price': this.precisionFromString (this.safeString (market, 'priceIncrement')), @@ -87451,7 +85392,7 @@ module.exports = class kucoin extends Exchange { 'max': baseMaxSize, }, 'price': { - 'min': this.safeFloat (market, 'priceIncrement'), + 'min': this.safeNumber (market, 'priceIncrement'), 'max': quoteMaxSize / baseMinSize, }, 'cost': { @@ -87502,7 +85443,7 @@ module.exports = class kucoin extends Exchange { const precision = this.safeInteger (entry, 'precision'); const isWithdrawEnabled = this.safeValue (entry, 'isWithdrawEnabled', false); const isDepositEnabled = this.safeValue (entry, 'isDepositEnabled', false); - const fee = this.safeFloat (entry, 'withdrawalMinFee'); + const fee = this.safeNumber (entry, 'withdrawalMinFee'); const active = (isWithdrawEnabled && isDepositEnabled); result[code] = { 'id': id, @@ -87569,7 +85510,7 @@ module.exports = class kucoin extends Exchange { const response = await this.privateGetWithdrawalsQuotas (this.extend (request, params)); const data = response['data']; const withdrawFees = {}; - withdrawFees[code] = this.safeFloat (data, 'withdrawMinFee'); + withdrawFees[code] = this.safeNumber (data, 'withdrawMinFee'); return { 'info': response, 'withdraw': withdrawFees, @@ -87616,35 +85557,35 @@ module.exports = class kucoin extends Exchange { // "mark": 0 // } // - let percentage = this.safeFloat (ticker, 'changeRate'); + let percentage = this.safeNumber (ticker, 'changeRate'); if (percentage !== undefined) { percentage = percentage * 100; } - const last = this.safeFloat2 (ticker, 'last', 'lastTradedPrice'); + const last = this.safeNumber2 (ticker, 'last', 'lastTradedPrice'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'vol'); - const quoteVolume = this.safeFloat (ticker, 'volValue'); + const baseVolume = this.safeNumber (ticker, 'vol'); + const quoteVolume = this.safeNumber (ticker, 'volValue'); const vwap = this.vwap (baseVolume, quoteVolume); const timestamp = this.safeInteger2 (ticker, 'time', 'datetime'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'changePrice'), + 'change': this.safeNumber (ticker, 'changePrice'), 'percentage': percentage, - 'average': this.safeFloat (ticker, 'averagePrice'), + 'average': this.safeNumber (ticker, 'averagePrice'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -87728,11 +85669,11 @@ module.exports = class kucoin extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -87930,16 +85871,18 @@ module.exports = class kucoin extends Exchange { // 'marginMode': 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned // 'autoBorrow': false, // The system will first borrow you funds at the optimal interest rate and then place an order for you }; - if (type !== 'market') { - request['price'] = this.priceToPrecision (symbol, price); - request['size'] = this.amountToPrecision (symbol, amount); - } else { - if (this.safeValue (params, 'quoteAmount')) { - // used to create market order by quote amount - https://github.com/ccxt/ccxt/issues/4876 - request['funds'] = this.amountToPrecision (symbol, amount); + const quoteAmount = this.safeNumber2 (params, 'cost', 'funds'); + if (type === 'market') { + if (quoteAmount !== undefined) { + params = this.omit (params, [ 'cost', 'funds' ]); + // kucoin uses base precision even for quote values + request['funds'] = this.amountToPrecision (symbol, quoteAmount); } else { request['size'] = this.amountToPrecision (symbol, amount); } + } else { + request['price'] = this.priceToPrecision (symbol, price); + request['size'] = this.amountToPrecision (symbol, amount); } const response = await this.privatePostOrders (this.extend (request, params)); // @@ -87973,8 +85916,10 @@ module.exports = class kucoin extends Exchange { 'fee': undefined, 'trades': undefined, }; - if (!this.safeValue (params, 'quoteAmount')) { + if (quoteAmount === undefined) { order['amount'] = amount; + } else { + order['cost'] = quoteAmount; } return order; } @@ -88150,15 +86095,18 @@ module.exports = class kucoin extends Exchange { const type = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'createdAt'); const datetime = this.iso8601 (timestamp); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); + if (price === 0.0) { + // market orders + price = undefined; + } const side = this.safeString (order, 'side'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (order, 'fee'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'dealSize'); - const cost = this.safeFloat (order, 'dealFunds'); - const remaining = amount - filled; + const feeCost = this.safeNumber (order, 'fee'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'dealSize'); + const cost = this.safeNumber (order, 'dealFunds'); // bool const isActive = this.safeValue (order, 'isActive', false); const cancelExist = this.safeValue (order, 'cancelExist', false); @@ -88168,20 +86116,11 @@ module.exports = class kucoin extends Exchange { 'currency': feeCurrency, 'cost': feeCost, }; - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const clientOrderId = this.safeString (order, 'clientOid'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': orderId, 'clientOrderId': clientOrderId, 'symbol': symbol, @@ -88194,7 +86133,7 @@ module.exports = class kucoin extends Exchange { 'stopPrice': stopPrice, 'cost': cost, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'timestamp': timestamp, 'datetime': datetime, 'fee': fee, @@ -88203,7 +86142,7 @@ module.exports = class kucoin extends Exchange { 'lastTradeTimestamp': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -88404,7 +86343,6 @@ module.exports = class kucoin extends Exchange { const id = this.safeString2 (trade, 'tradeId', 'id'); const orderId = this.safeString (trade, 'orderId'); const takerOrMaker = this.safeString (trade, 'liquidity'); - const amount = this.safeFloat2 (trade, 'size', 'amount'); let timestamp = this.safeInteger (trade, 'time'); if (timestamp !== undefined) { timestamp = parseInt (timestamp / 1000000); @@ -88415,10 +86353,13 @@ module.exports = class kucoin extends Exchange { timestamp = timestamp * 1000; } } - const price = this.safeFloat2 (trade, 'price', 'dealPrice'); + const priceString = this.safeString2 (trade, 'price', 'dealPrice'); + const amountString = this.safeString2 (trade, 'size', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const side = this.safeString (trade, 'side'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); let feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -88430,20 +86371,16 @@ module.exports = class kucoin extends Exchange { fee = { 'cost': feeCost, 'currency': feeCurrency, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } let type = this.safeString (trade, 'type'); if (type === 'match') { type = undefined; } - let cost = this.safeFloat2 (trade, 'funds', 'dealValue'); + let cost = this.safeNumber2 (trade, 'funds', 'dealValue'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'info': trade, @@ -88539,7 +86476,7 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); let address = this.safeString (transaction, 'address'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let txid = this.safeString (transaction, 'walletTxId'); if (txid !== undefined) { const txidParts = txid.split ('@'); @@ -88557,7 +86494,7 @@ module.exports = class kucoin extends Exchange { const rawStatus = this.safeString (transaction, 'status'); const status = this.parseTransactionStatus (rawStatus); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { let rate = undefined; if (amount !== undefined) { @@ -88738,45 +86675,180 @@ module.exports = class kucoin extends Exchange { async fetchBalance (params = {}) { await this.loadMarkets (); - let type = undefined; - const request = {}; - if ('type' in params) { - type = params['type']; - if (type !== undefined) { - request['type'] = type; - } - params = this.omit (params, 'type'); + const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'trade'); + const requestedType = this.safeString (params, 'type', defaultType); + const accountsByType = this.safeValue (this.options, 'accountsByType'); + const type = this.safeString (accountsByType, requestedType); + if (type === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' type must be one of ' + keys.join (', ')); + } + params = this.omit (params, 'type'); + if (type === 'contract') { + // futures api requires a futures apiKey + // only fetches one balance at a time + // by default it will only fetch the BTC balance of the futures account + // you can send 'currency' in params to fetch other currencies + // fetchBalance ({ 'type': 'futures', 'currency': 'USDT' }) + const response = await this.futuresPrivateGetAccountOverview (params); + // + // { + // code: '200000', + // data: { + // accountEquity: 0.00005, + // unrealisedPNL: 0, + // marginBalance: 0.00005, + // positionMargin: 0, + // orderMargin: 0, + // frozenFunds: 0, + // availableBalance: 0.00005, + // currency: 'XBT' + // } + // } + // + const data = this.safeValue (response, 'data'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (data, 'availableBalance'); + account['total'] = this.safeString (data, 'accountEquity'); + const result = { 'info': response }; + result[code] = account; + return this.parseBalance (result, false); } else { - const options = this.safeValue (this.options, 'fetchBalance', {}); - type = this.safeString (options, 'type', 'trade'); - } - const response = await this.privateGetAccounts (this.extend (request, params)); - // - // { - // "code":"200000", - // "data":[ - // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, - // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, - // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - const result = { 'info': response }; - for (let i = 0; i < data.length; i++) { - const balance = data[i]; - const balanceType = this.safeString (balance, 'type'); - if (balanceType === type) { - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'holds'); - result[code] = account; + const request = { + 'type': type, + }; + const response = await this.privateGetAccounts (this.extend (request, params)); + // + // { + // "code":"200000", + // "data":[ + // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, + // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, + // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + const result = { 'info': response }; + for (let i = 0; i < data.length; i++) { + const balance = data[i]; + const balanceType = this.safeString (balance, 'type'); + if (balanceType === type) { + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'holds'); + result[code] = account; + } } + return this.parseBalance (result, false); + } + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const requestedAmount = this.currencyToPrecision (code, amount); + const accountsById = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsById, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsById, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + if (fromId === 'contract') { + if (toId !== 'main') { + throw new ExchangeError (this.id + ' only supports transferring from futures account to main account'); + } + const request = { + 'currency': currency['id'], + 'amount': requestedAmount, + }; + if (!('bizNo' in params)) { + // it doesn't like more than 24 characters + request['bizNo'] = this.uuid22 (); + } + const response = await this.futuresPrivatePostTransferOut (this.extend (request, params)); + // + // { + // code: '200000', + // data: { + // applyId: '605a87217dff1500063d485d', + // bizNo: 'bcd6e5e1291f4905af84dc', + // payAccountType: 'CONTRACT', + // payTag: 'DEFAULT', + // remark: '', + // recAccountType: 'MAIN', + // recTag: 'DEFAULT', + // recRemark: '', + // recSystem: 'KUCOIN', + // status: 'PROCESSING', + // currency: 'XBT', + // amount: '0.00001', + // fee: '0', + // sn: '573688685663948', + // reason: '', + // createdAt: 1616545569000, + // updatedAt: 1616545569000 + // } + // } + // + const data = this.safeValue (response, 'data'); + const timestamp = this.safeInteger (data, 'createdAt'); + const id = this.safeString (data, 'applyId'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const amount = this.safeNumber (data, 'amount'); + const rawStatus = this.safeString (data, 'status'); + let status = undefined; + if (rawStatus === 'PROCESSING') { + status = 'pending'; + } + return { + 'info': response, + 'currency': code, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'amount': amount, + 'fromAccount': fromId, + 'toAccount': toId, + 'id': id, + 'status': status, + }; + } else { + const request = { + 'currency': currency['id'], + 'from': fromId, + 'to': toId, + 'amount': requestedAmount, + }; + if (!('clientOid' in params)) { + request['clientOid'] = this.uuid (); + } + const response = await this.privatePostAccountsInnerTransfer (this.extend (request, params)); + // { code: '200000', data: { orderId: '605a6211e657f00006ad0ad6' } } + const data = this.safeValue (response, 'data'); + const id = this.safeString (data, 'orderId'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'currency': code, + 'amount': requestedAmount, + 'fromAccount': fromId, + 'toAccount': toId, + 'status': undefined, + }; } - return this.parseBalance (result); } async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -88864,11 +86936,11 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'code': code, }; - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'balance'); const direction = this.safeString (item, 'direction'); let before = undefined; if (after !== undefined && amount !== undefined) { @@ -88918,6 +86990,94 @@ module.exports = class kucoin extends Exchange { return this.safeString (types, type, type); } + async fetchPositions (symbols = undefined, params = {}) { + const response = await this.futuresPrivateGetPositions (params); + // + // { + // code: '200000', + // data: [ + // { + // id: '605a9772a229ab0006408258', + // symbol: 'XBTUSDTM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746099, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54371.92, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'USDT', + // isInverse: false + // }, + // { + // id: '605a9772026ac900066550df', + // symbol: 'XBTUSDM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746110, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54354.76, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'XBT', + // isInverse: true + // } + // ] + // } + // + return this.safeValue (response, 'data', response); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { // // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint @@ -88934,16 +87094,16 @@ module.exports = class kucoin extends Exchange { let endpart = ''; headers = (headers !== undefined) ? headers : {}; if (Object.keys (query).length) { - if (method !== 'GET') { + if ((method === 'GET') || (method === 'DELETE')) { + endpoint += '?' + this.urlencode (query); + } else { body = this.json (query); endpart = body; headers['Content-Type'] = 'application/json'; - } else { - endpoint += '?' + this.urlencode (query); } } const url = this.urls['api'][api] + endpoint; - if (api === 'private') { + if ((api === 'private') || (api === 'futuresPrivate')) { this.checkRequiredCredentials (); const timestamp = this.nonce ().toString (); headers = this.extend ({ @@ -88986,23 +87146,24 @@ module.exports = class kucoin extends Exchange { // { code: '200000', data: { ... }} // const errorCode = this.safeString (response, 'code'); - const message = this.safeString (response, 'msg'); - this.throwExactlyMatchedException (this.exceptions['exact'], message, message); - this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, message); + const message = this.safeString (response, 'msg', ''); + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, this.id + ' ' + message); } }; -},{"./base/Exchange":6,"./base/errors":8}],104:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],101:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- -const acx = require ('./acx.js'); -const { ArgumentsRequired } = require ('./base/errors'); +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, InsufficientFunds, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class kuna extends acx { +module.exports = class kuna extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'kuna', @@ -89012,14 +87173,24 @@ module.exports = class kuna extends acx { 'version': 'v2', 'has': { 'CORS': false, - 'fetchTickers': true, + 'cancelOrder': true, + 'createOrder': true, + 'fetchBalance': true, + 'fetchMarkets': true, + 'fetchMyTrades': true, 'fetchOHLCV': 'emulated', 'fetchOpenOrders': true, - 'fetchMyTrades': true, + 'fetchOrder': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchTime': true, + 'fetchTrades': true, 'withdraw': false, }, 'timeframes': undefined, 'urls': { + 'extension': '.json', 'referral': 'https://kuna.io?r=kunaid-gvfihe8az7o4', 'logo': 'https://user-images.githubusercontent.com/51840849/87153927-f0578b80-c2c0-11ea-84b6-74612568e9e1.jpg', 'api': 'https://kuna.io', @@ -89027,8 +87198,47 @@ module.exports = class kuna extends acx { 'doc': 'https://kuna.io/documents/api', 'fees': 'https://kuna.io/documents/api', }, + 'api': { + 'public': { + 'get': [ + 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. + 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator + 'k', // Get OHLC(k line) of specific market + 'markets', // Get all available markets + 'order_book', // Get the order book of specified market + 'order_book/{market}', + 'tickers', // Get ticker of all markets + 'tickers/{market}', // Get ticker of specific market + 'timestamp', // Get server current time, in seconds since Unix epoch + 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. + 'trades/{market}', + ], + }, + 'private': { + 'get': [ + 'members/me', // Get your profile and accounts info + 'deposits', // Get your deposits history + 'deposit', // Get details of specific deposit + 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. + 'orders', // Get your orders, results is paginated + 'order', // Get information of specified order + 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. + 'withdraws', // Get your cryptocurrency withdraws + 'withdraw', // Get your cryptocurrency withdraw + ], + 'post': [ + 'orders', // Create a Sell/Buy order + 'orders/multi', // Create multiple sell/buy orders + 'orders/clear', // Cancel all my orders + 'order/delete', // Cancel an order + 'withdraw', // Create a withdraw + ], + }, + }, 'fees': { 'trading': { + 'tierBased': false, + 'percentage': true, 'taker': 0.25 / 100, 'maker': 0.25 / 100, }, @@ -89051,9 +87261,24 @@ module.exports = class kuna extends acx { }, }, }, + 'commonCurrencies': { + 'PLA': 'Plair', + }, + 'exceptions': { + '2002': InsufficientFunds, + '2003': OrderNotFound, + }, }); } + async fetchTime (params = {}) { + const response = await this.publicGetTimestamp (params); + // + // 1594911427 + // + return response * 1000; + } + async fetchMarkets (params = {}) { const quotes = [ 'btc', 'eth', 'eurs', 'rub', 'uah', 'usd', 'usdt', 'gol' ]; const pricePrecisions = { @@ -89109,24 +87334,100 @@ module.exports = class kuna extends acx { return markets; } - async fetchL3OrderBook (symbol, limit = undefined, params = {}) { - return await this.fetchOrderBook (symbol, limit, params); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); - } + async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; - const response = await this.privateGetOrders (this.extend (request, params)); - // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder - // with order cache + fetchOpenOrders - // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX - return this.parseOrders (response, market, since, limit); + if (limit !== undefined) { + request['limit'] = limit; // default = 300 + } + const orderbook = await this.publicGetDepth (this.extend (request, params)); + const timestamp = this.safeTimestamp (orderbook, 'timestamp'); + return this.parseOrderBook (orderbook, timestamp); + } + + parseTicker (ticker, market = undefined) { + const timestamp = this.safeTimestamp (ticker, 'at'); + ticker = ticker['ticker']; + let symbol = undefined; + if (market) { + symbol = market['symbol']; + } + const last = this.safeNumber (ticker, 'last'); + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'bidVolume': undefined, + 'ask': this.safeNumber (ticker, 'sell'), + 'askVolume': undefined, + 'vwap': undefined, + 'open': this.safeNumber (ticker, 'open'), + 'close': last, + 'last': last, + 'previousClose': undefined, + 'change': undefined, + 'percentage': undefined, + 'average': undefined, + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const response = await this.publicGetTickers (params); + const ids = Object.keys (response); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + let market = undefined; + let symbol = id; + if (id in this.markets_by_id) { + market = this.markets_by_id[id]; + symbol = market['symbol']; + } else { + let base = id.slice (0, 3); + let quote = id.slice (3, 6); + base = base.toUpperCase (); + quote = quote.toUpperCase (); + base = this.safeCurrencyCode (base); + quote = this.safeCurrencyCode (quote); + symbol = base + '/' + quote; + } + result[symbol] = this.parseTicker (response[id], market); + } + return this.filterByArray (result, 'symbol', symbols); + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTickersMarket (this.extend (request, params)); + return this.parseTicker (response, market); + } + + async fetchL3OrderBook (symbol, limit = undefined, params = {}) { + return await this.fetchOrderBook (symbol, limit, params); + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTrades (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); } parseTrade (trade, market = undefined) { @@ -89143,9 +87444,14 @@ module.exports = class kuna extends acx { }; side = this.safeString (sideMap, side, side); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_id'); const id = this.safeString (trade, 'id'); return { @@ -89165,29 +87471,6 @@ module.exports = class kuna extends acx { }; } - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); - } - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.privateGetTradesMy (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const trades = await this.fetchTrades (symbol, since, limit, params); @@ -89206,15 +87489,210 @@ module.exports = class kuna extends acx { } return result; } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + const response = await this.privateGetMembersMe (params); + const balances = this.safeValue (response, 'accounts'); + const result = { 'info': balances }; + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'market': this.marketId (symbol), + 'side': side, + 'volume': amount.toString (), + 'ord_type': type, + }; + if (type === 'limit') { + request['price'] = price.toString (); + } + const response = await this.privatePostOrders (this.extend (request, params)); + const marketId = this.safeValue (response, 'market'); + const market = this.safeValue (this.markets_by_id, marketId); + return this.parseOrder (response, market); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': id, + }; + const response = await this.privatePostOrderDelete (this.extend (request, params)); + const order = this.parseOrder (response); + const status = order['status']; + if (status === 'closed' || status === 'canceled') { + throw new OrderNotFound (this.id + ' ' + this.json (order)); + } + return order; + } + + parseOrderStatus (status) { + const statuses = { + 'done': 'closed', + 'wait': 'open', + 'cancel': 'canceled', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + const marketId = this.safeString (order, 'market'); + const symbol = this.safeSymbol (marketId, market); + const timestamp = this.parse8601 (this.safeString (order, 'created_at')); + const status = this.parseOrderStatus (this.safeString (order, 'state')); + const type = this.safeString (order, 'type'); + const side = this.safeString (order, 'side'); + const id = this.safeString (order, 'id'); + return this.safeOrder ({ + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': undefined, + 'status': status, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': this.safeNumber (order, 'price'), + 'stopPrice': undefined, + 'amount': this.safeNumber (order, 'volume'), + 'filled': this.safeNumber (order, 'executed_volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'trades': undefined, + 'fee': undefined, + 'info': order, + 'cost': undefined, + 'average': undefined, + }); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': parseInt (id), + }; + const response = await this.privateGetOrder (this.extend (request, params)); + return this.parseOrder (response); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetOrders (this.extend (request, params)); + // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder + // with order cache + fetchOpenOrders + // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX + return this.parseOrders (response, market, since, limit); + } + + async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetTradesMy (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); + } + + nonce () { + return this.milliseconds (); + } + + encodeParams (params) { + if ('orders' in params) { + const orders = params['orders']; + let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); + for (let i = 0; i < orders.length; i++) { + const order = orders[i]; + const keys = Object.keys (order); + for (let k = 0; k < keys.length; k++) { + const key = keys[k]; + const value = order[key]; + query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); + } + } + return query; + } + return this.urlencode (this.keysort (params)); + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let request = '/api/' + this.version + '/' + this.implodeParams (path, params); + if ('extension' in this.urls) { + request += this.urls['extension']; + } + const query = this.omit (params, this.extractParams (path)); + let url = this.urls['api'] + request; + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const nonce = this.nonce ().toString (); + const query = this.encodeParams (this.extend ({ + 'access_key': this.apiKey, + 'tonce': nonce, + }, params)); + const auth = method + '|' + request + '|' + query; + const signed = this.hmac (this.encode (auth), this.encode (this.secret)); + const suffix = query + '&signature=' + signed; + if (method === 'GET') { + url += '?' + suffix; + } else { + body = suffix; + headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; + } + } + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; + } + if (code === 400) { + const error = this.safeValue (response, 'error'); + const errorCode = this.safeString (error, 'code'); + const feedback = this.id + ' ' + this.json (response); + this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); + // fallback to default error handler + } + } }; -},{"./acx.js":4,"./base/errors":8}],105:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],102:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, BadSymbol, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89323,10 +87801,10 @@ module.exports = class lakebtc extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -89344,16 +87822,16 @@ module.exports = class lakebtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -89363,7 +87841,7 @@ module.exports = class lakebtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -89394,14 +87872,11 @@ module.exports = class lakebtc extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -89538,14 +88013,14 @@ module.exports = class lakebtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],106:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],103:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, DDoSProtection, BadRequest, AuthenticationError } = require ('./base/errors'); -const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89626,6 +88101,7 @@ module.exports = class latoken extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.1 / 100, @@ -89710,7 +88186,7 @@ module.exports = class latoken extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minQty'), + 'min': this.safeNumber (market, 'minQty'), 'max': undefined, }, 'price': { @@ -89760,7 +88236,7 @@ module.exports = class latoken extends Exchange { const numericId = this.safeInteger (currency, 'currencyId'); const code = this.safeCurrencyCode (id); const precision = this.safeInteger (currency, 'precission'); - const fee = this.safeFloat (currency, 'fee'); + const fee = this.safeNumber (currency, 'fee'); const active = undefined; result[code] = { 'id': id, @@ -89794,27 +88270,6 @@ module.exports = class latoken extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privateGetAccountBalances (params); @@ -89838,17 +88293,15 @@ module.exports = class latoken extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const frozen = this.safeFloat (balance, 'frozen'); - const pending = this.safeFloat (balance, 'pending'); - const used = this.sum (frozen, pending); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': used, - 'total': this.safeFloat (balance, 'amount'), - }; + const frozen = this.safeString (balance, 'frozen'); + const pending = this.safeString (balance, 'pending'); + const account = this.account (); + account['used'] = Precise.stringAdd (frozen, pending); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -89893,20 +88346,20 @@ module.exports = class latoken extends Exchange { // const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; if (open !== undefined && close !== undefined) { change = close - open; } - const percentage = this.safeFloat (ticker, 'priceChange'); + const percentage = this.safeNumber (ticker, 'priceChange'); const timestamp = this.nonce (); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'low': this.safeFloat (ticker, 'low'), - 'high': this.safeFloat (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -89920,7 +88373,7 @@ module.exports = class latoken extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -90004,22 +88457,19 @@ module.exports = class latoken extends Exchange { timestamp *= 1000; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'orderId'); - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -90154,29 +88604,17 @@ module.exports = class latoken extends Exchange { const symbol = this.safeSymbol (marketId, market); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executedAmount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executedAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderStatus')); - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const timeFilled = this.safeTimestamp (order, 'timeFilled'); let lastTradeTimestamp = undefined; if ((timeFilled !== undefined) && (timeFilled > 0)) { lastTradeTimestamp = timeFilled; } const clientOrderId = this.safeString (order, 'cliOrdId'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -90191,14 +88629,14 @@ module.exports = class latoken extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'average': undefined, - 'remaining': remaining, + 'remaining': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -90428,13 +88866,14 @@ module.exports = class latoken extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],107:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],104:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, DDoSProtection, AuthenticationError, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -90632,8 +89071,8 @@ module.exports = class lbank extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const info = ticker; ticker = info['ticker']; - const last = this.safeFloat (ticker, 'latest'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'latest'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; if (percentage !== undefined) { const relativeChange = this.sum (1, percentage / 100); @@ -90654,8 +89093,8 @@ module.exports = class lbank extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -90668,8 +89107,8 @@ module.exports = class lbank extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'turnover'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'turnover'), 'info': info, }; } @@ -90719,17 +89158,15 @@ module.exports = class lbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (trade, 'date_ms'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'tid'); const type = undefined; - const side = this.safeString (trade, 'type'); + let side = this.safeString (trade, 'type'); + side = side.replace ('_market', ''); return { 'id': id, 'info': this.safeValue (trade, 'info', trade), @@ -90777,11 +89214,11 @@ module.exports = class lbank extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -90846,12 +89283,12 @@ module.exports = class lbank extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (freeze, currencyId); - account['total'] = this.safeFloat (asset, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (freeze, currencyId); + account['total'] = this.safeString (asset, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -90879,35 +89316,20 @@ module.exports = class lbank extends Exchange { // "status":2 // } // - let symbol = undefined; - const responseMarket = this.safeValue (this.marketsById, order['symbol']); - if (responseMarket !== undefined) { - symbol = responseMarket['symbol']; - } else if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeInteger (order, 'create_time'); // Limit Order Request Returns: Order Price // Market Order Returns: cny amount of market order - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount', 0.0); - const filled = this.safeFloat (order, 'deal_amount', 0.0); - const av_price = this.safeFloat (order, 'avg_price'); - let cost = undefined; - if (av_price !== undefined) { - cost = filled * av_price; - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount', 0.0); + const filled = this.safeNumber (order, 'deal_amount', 0.0); + const average = this.safeNumber (order, 'avg_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'order_id'); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -90921,15 +89343,15 @@ module.exports = class lbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': this.safeValue (order, 'info', order), - 'average': undefined, - }; + 'average': average, + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -91129,14 +89551,15 @@ module.exports = class lbank extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],108:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],105:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported } = require ('./base/errors'); +const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -91240,7 +89663,7 @@ module.exports = class liquid extends Exchange { 'trading': { 'tierBased': true, 'percentage': true, - 'taker': 0.0015, + 'taker': 0.0030, 'maker': 0.0000, 'tiers': { 'perpetual': { @@ -91259,48 +89682,52 @@ module.exports = class liquid extends Exchange { [ 300000000, -0.00025 ], ], 'taker': [ - [ 0, 0.000600 ], - [ 25000, 0.000575 ], - [ 50000, 0.000550 ], - [ 100000, 0.000525 ], - [ 1000000, 0.000500 ], - [ 10000000, 0.000475 ], - [ 25000000, 0.000450 ], - [ 50000000, 0.000425 ], - [ 75000000, 0.000400 ], - [ 100000000, 0.000375 ], - [ 200000000, 0.000350 ], - [ 300000000, 0.000325 ], + [ 0, 0.00120 ], + [ 25000, 0.00115 ], + [ 50000, 0.00110 ], + [ 100000, 0.00105 ], + [ 1000000, 0.00100 ], + [ 10000000, 0.00095 ], + [ 25000000, 0.00090 ], + [ 50000000, 0.00085 ], + [ 75000000, 0.00080 ], + [ 100000000, 0.00075 ], + [ 200000000, 0.00070 ], + [ 300000000, 0.00065 ], ], }, 'spot': { 'taker': [ - [ 0, 0.0015 ], - [ 10000, 0.0015 ], - [ 20000, 0.0014 ], - [ 50000, 0.0013 ], - [ 100000, 0.0010 ], - [ 1000000, 0.0008 ], - [ 5000000, 0.0006 ], - [ 10000000, 0.0005 ], - [ 25000000, 0.0005 ], - [ 50000000, 0.00045 ], - [ 100000000, 0.0004 ], - [ 200000000, 0.0003 ], + [ 0, 0.003 ], + [ 10000, 0.0029 ], + [ 20000, 0.0028 ], + [ 50000, 0.0026 ], + [ 100000, 0.0020 ], + [ 1000000, 0.0016 ], + [ 5000000, 0.0012 ], + [ 10000000, 0.0010 ], + [ 25000000, 0.0009 ], + [ 50000000, 0.0008 ], + [ 100000000, 0.0007 ], + [ 200000000, 0.0006 ], + [ 500000000, 0.0004 ], + [ 1000000000, 0.0003 ], ], 'maker': [ [ 0, 0.0000 ], - [ 10000, 0.0015 ], - [ 20000, 0.1400 ], - [ 50000, 0.1300 ], - [ 100000, 0.0800 ], - [ 1000000, 0.0004 ], - [ 5000000, 0.00035 ], - [ 10000000, 0.00025 ], + [ 10000, 0.0020 ], + [ 20000, 0.0019 ], + [ 50000, 0.0018 ], + [ 100000, 0.0016 ], + [ 1000000, 0.0008 ], + [ 5000000, 0.0007 ], + [ 10000000, 0.0005 ], [ 25000000, 0.0000 ], [ 50000000, 0.0000 ], [ 100000000, 0.0000 ], [ 200000000, 0.0000 ], + [ 500000000, 0.0000 ], + [ 1000000000, 0.0000 ], ], }, }, @@ -91319,6 +89746,7 @@ module.exports = class liquid extends Exchange { 'less_than_order_size': InvalidOrder, 'price_too_high': InvalidOrder, 'price_too_small': InvalidOrder, // {"errors":{"order":["price_too_small"]}} + 'product_disabled': BadSymbol, // {"errors":{"order":["product_disabled"]}} }, 'commonCurrencies': { 'WIN': 'WCOIN', @@ -91368,7 +89796,7 @@ module.exports = class liquid extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': decimalPrecision, 'limits': { 'amount': { @@ -91384,7 +89812,7 @@ module.exports = class liquid extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal'), + 'min': this.safeNumber (currency, 'minimum_withdrawal'), 'max': undefined, }, }, @@ -91509,19 +89937,19 @@ module.exports = class liquid extends Exchange { let maker = this.fees['trading']['maker']; let taker = this.fees['trading']['taker']; if (type === 'swap') { - maker = this.safeFloat (market, 'maker_fee', this.fees['trading']['maker']); - taker = this.safeFloat (market, 'taker_fee', this.fees['trading']['taker']); + maker = this.safeNumber (market, 'maker_fee', this.fees['trading']['maker']); + taker = this.safeNumber (market, 'taker_fee', this.fees['trading']['taker']); } const disabled = this.safeValue (market, 'disabled', false); const active = !disabled; const baseCurrency = this.safeValue (currenciesByCode, base); const precision = { 'amount': 0.00000001, - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; let minAmount = undefined; if (baseCurrency !== undefined) { - minAmount = this.safeFloat (baseCurrency['info'], 'minimum_order_quantity'); + minAmount = this.safeNumber (baseCurrency['info'], 'minimum_order_quantity'); } const limits = { 'amount': { @@ -91603,8 +90031,8 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } for (let i = 0; i < fiat.length; i++) { @@ -91612,11 +90040,11 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -91635,7 +90063,7 @@ module.exports = class liquid extends Exchange { if (ticker['last_traded_price']) { const length = ticker['last_traded_price'].length; if (length > 0) { - last = this.safeFloat (ticker, 'last_traded_price'); + last = this.safeNumber (ticker, 'last_traded_price'); } } } @@ -91660,7 +90088,7 @@ module.exports = class liquid extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'last_price_24h'); + const open = this.safeNumber (ticker, 'last_price_24h'); if (open !== undefined && last !== undefined) { change = last - open; average = this.sum (last, open) / 2; @@ -91672,11 +90100,11 @@ module.exports = class liquid extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_market_ask'), - 'low': this.safeFloat (ticker, 'low_market_bid'), - 'bid': this.safeFloat (ticker, 'market_bid'), + 'high': this.safeNumber (ticker, 'high_market_ask'), + 'low': this.safeNumber (ticker, 'low_market_bid'), + 'bid': this.safeNumber (ticker, 'market_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'market_ask'), + 'ask': this.safeNumber (ticker, 'market_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -91686,7 +90114,7 @@ module.exports = class liquid extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'volume_24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -91732,14 +90160,11 @@ module.exports = class liquid extends Exchange { if (mySide !== undefined) { takerOrMaker = (takerSide === mySide) ? 'taker' : 'maker'; } - let cost = undefined; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -91942,9 +90367,9 @@ module.exports = class liquid extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeValue (this.markets_by_id, marketId); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'filled_quantity'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + let filled = this.safeNumber (order, 'filled_quantity'); + const price = this.safeNumber (order, 'price'); let symbol = undefined; let feeCurrency = undefined; if (market !== undefined) { @@ -91954,7 +90379,7 @@ module.exports = class liquid extends Exchange { const type = this.safeString (order, 'order_type'); let tradeCost = 0; let tradeFilled = 0; - let average = this.safeFloat (order, 'average_price'); + let average = this.safeNumber (order, 'average_price'); const trades = this.parseTrades (this.safeValue (order, 'executions', []), market, undefined, undefined, { 'order': orderId, 'type': type, @@ -92011,7 +90436,7 @@ module.exports = class liquid extends Exchange { 'trades': trades, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'order_fee'), + 'cost': this.safeNumber (order, 'order_fee'), }, 'info': order, }; @@ -92166,7 +90591,7 @@ module.exports = class liquid extends Exchange { const updated = this.safeTimestamp (transaction, 'updated_at'); const type = 'withdrawal'; const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); return { 'info': transaction, 'id': id, @@ -92267,13 +90692,14 @@ module.exports = class liquid extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],109:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],106:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -92349,6 +90775,10 @@ module.exports = class luno extends Exchange { 'quotes/{id}', 'withdrawals', 'withdrawals/{id}', + 'transfers', + // GET /api/exchange/2/listorders + // GET /api/exchange/2/orders/{id} + // GET /api/exchange/3/order ], 'post': [ 'accounts', @@ -92423,12 +90853,12 @@ module.exports = class luno extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), - 'max': this.safeFloat (market, 'max_volume'), + 'min': this.safeNumber (market, 'min_volume'), + 'max': this.safeNumber (market, 'max_volume'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -92479,20 +90909,22 @@ module.exports = class luno extends Exchange { const wallet = wallets[i]; const currencyId = this.safeString (wallet, 'asset'); const code = this.safeCurrencyCode (currencyId); - const reserved = this.safeFloat (wallet, 'reserved'); - const unconfirmed = this.safeFloat (wallet, 'unconfirmed'); - const balance = this.safeFloat (wallet, 'balance'); + const reserved = this.safeString (wallet, 'reserved'); + const unconfirmed = this.safeString (wallet, 'unconfirmed'); + const balance = this.safeString (wallet, 'balance'); + const reservedUnconfirmed = Precise.stringAdd (reserved, unconfirmed); + const balanceUnconfirmed = Precise.stringAdd (balance, unconfirmed); if (code in result) { - result[code]['used'] = this.sum (result[code]['used'], reserved, unconfirmed); - result[code]['total'] = this.sum (result[code]['total'], balance, unconfirmed); + result[code]['used'] = Precise.stringAdd (result[code]['used'], reservedUnconfirmed); + result[code]['total'] = Precise.stringAdd (result[code]['total'], balanceUnconfirmed); } else { const account = this.account (); - account['used'] = this.sum (reserved, unconfirmed); - account['total'] = this.sum (balance, unconfirmed); + account['used'] = reservedUnconfirmed; + account['total'] = balanceUnconfirmed; result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -92543,18 +90975,12 @@ module.exports = class luno extends Exchange { const side = (order['type'] === 'ASK') ? 'sell' : 'buy'; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'limit_volume'); - const quoteFee = this.safeFloat (order, 'fee_counter'); - const baseFee = this.safeFloat (order, 'fee_base'); - const filled = this.safeFloat (order, 'base'); - const cost = this.safeFloat (order, 'counter'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'limit_volume'); + const quoteFee = this.safeNumber (order, 'fee_counter'); + const baseFee = this.safeNumber (order, 'fee_base'); + const filled = this.safeNumber (order, 'base'); + const cost = this.safeNumber (order, 'counter'); const fee = { 'currency': undefined }; if (quoteFee) { fee['cost'] = quoteFee; @@ -92568,7 +90994,7 @@ module.exports = class luno extends Exchange { } } const id = this.safeString (order, 'order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -92585,12 +91011,12 @@ module.exports = class luno extends Exchange { 'amount': amount, 'filled': filled, 'cost': cost, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -92636,16 +91062,16 @@ module.exports = class luno extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -92655,7 +91081,7 @@ module.exports = class luno extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'rolling_24_hour_volume'), + 'baseVolume': this.safeNumber (ticker, 'rolling_24_hour_volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -92706,8 +91132,8 @@ module.exports = class luno extends Exchange { } else { side = trade['is_buy'] ? 'buy' : 'sell'; } - const feeBase = this.safeFloat (trade, 'fee_base'); - const feeCounter = this.safeFloat (trade, 'fee_counter'); + const feeBase = this.safeNumber (trade, 'fee_base'); + const feeCounter = this.safeNumber (trade, 'fee_counter'); let feeCurrency = undefined; let feeCost = undefined; if (feeBase !== undefined) { @@ -92732,10 +91158,10 @@ module.exports = class luno extends Exchange { 'type': undefined, 'side': side, 'takerOrMaker': takerOrMaker, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), // Does not include potential fee costs - 'cost': this.safeFloat (trade, 'counter'), + 'cost': this.safeNumber (trade, 'counter'), 'fee': { 'cost': feeCost, 'currency': feeCurrency, @@ -92782,8 +91208,8 @@ module.exports = class luno extends Exchange { const response = await this.privateGetFeeInfo (params); return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } @@ -92917,9 +91343,9 @@ module.exports = class luno extends Exchange { const timestamp = this.safeValue (entry, 'timestamp'); const currencyId = this.safeString (entry, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - const available_delta = this.safeFloat (entry, 'available_delta'); - const balance_delta = this.safeFloat (entry, 'balance_delta'); - const after = this.safeFloat (entry, 'balance'); + const available_delta = this.safeNumber (entry, 'available_delta'); + const balance_delta = this.safeNumber (entry, 'balance_delta'); + const after = this.safeNumber (entry, 'balance'); const comment = this.safeString (entry, 'description'); let before = after; let amount = 0.0; @@ -92988,12 +91414,13 @@ module.exports = class luno extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],110:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],107:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -93175,18 +91602,16 @@ module.exports = class lykke extends Exchange { const id = this.safeString2 (trade, 'id', 'Id'); const orderId = this.safeString (trade, 'OrderId'); const timestamp = this.parse8601 (this.safeString2 (trade, 'dateTime', 'DateTime')); - const price = this.safeFloat2 (trade, 'price', 'Price'); - let amount = this.safeFloat2 (trade, 'volume', 'Amount'); + const priceString = this.safeString2 (trade, 'price', 'Price'); + let amountString = this.safeString2 (trade, 'volume', 'Amount'); let side = this.safeStringLower (trade, 'action'); if (side === undefined) { - if (amount < 0) { - side = 'sell'; - } else { - side = 'buy'; - } + side = (amountString[0] === '-') ? 'sell' : 'buy'; } - amount = Math.abs (amount); - const cost = price * amount; + amountString = (amountString[0] === '-') ? amountString.slice (1) : amountString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = { 'cost': 0, // There are no fees for trading. https://www.lykke.com/wallet-fees-and-limits/ 'currency': market['quote'], @@ -93247,11 +91672,11 @@ module.exports = class lykke extends Exchange { const currencyId = this.safeString (balance, 'AssetId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Balance'); - account['used'] = this.safeFloat (balance, 'Reserved'); + account['total'] = this.safeString (balance, 'Balance'); + account['used'] = this.safeString (balance, 'Reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -93298,7 +91723,7 @@ module.exports = class lykke extends Exchange { // } // const id = this.safeString (result, 'Id'); - price = this.safeFloat (result, 'Price'); + price = this.safeNumber (result, 'Price'); return { 'id': id, 'info': result, @@ -93389,16 +91814,16 @@ module.exports = class lykke extends Exchange { if (market) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'lastPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -93409,7 +91834,7 @@ module.exports = class lykke extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume24H'), + 'quoteVolume': this.safeNumber (ticker, 'volume24H'), 'info': ticker, }; } @@ -93467,20 +91892,18 @@ module.exports = class lykke extends Exchange { } else if (('CreatedAt' in order) && (order['CreatedAt'])) { timestamp = this.parse8601 (order['CreatedAt']); } - const price = this.safeFloat (order, 'Price'); + const price = this.safeNumber (order, 'Price'); let side = undefined; - let amount = this.safeFloat (order, 'Volume'); + let amount = this.safeNumber (order, 'Volume'); if (amount < 0) { side = 'sell'; amount = Math.abs (amount); } else { side = 'buy'; } - const remaining = Math.abs (this.safeFloat (order, 'RemainingVolume')); - const filled = amount - remaining; - const cost = filled * price; + const remaining = Math.abs (this.safeNumber (order, 'RemainingVolume')); const id = this.safeString (order, 'Id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -93494,15 +91917,15 @@ module.exports = class lykke extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -93563,8 +91986,8 @@ module.exports = class lykke extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - let amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + let amount = this.safeNumber (bidask, amountKey); if (amount < 0) { amount = -amount; } @@ -93604,13 +92027,14 @@ module.exports = class lykke extends Exchange { } }; -},{"./base/Exchange":6}],111:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],108:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -93767,7 +92191,7 @@ module.exports = class mercado extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, baseId), + 'min': this.safeNumber (amountLimits, baseId), 'max': undefined, }, 'price': { @@ -93803,16 +92227,16 @@ module.exports = class mercado extends Exchange { const response = await this.publicGetCoinTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'ticker', {}); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -93822,7 +92246,7 @@ module.exports = class mercado extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -93837,15 +92261,12 @@ module.exports = class mercado extends Exchange { const id = this.safeString2 (trade, 'tid', 'operation_id'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee_rate'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee_rate'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -93902,12 +92323,12 @@ module.exports = class mercado extends Exchange { if (currencyId in balances) { const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -94014,32 +92435,31 @@ module.exports = class mercado extends Exchange { // } // const id = this.safeString (order, 'order_id'); + const order_type = this.safeString (order, 'order_type'); let side = undefined; if ('order_type' in order) { - side = (order['order_type'] === 1) ? 'buy' : 'sell'; + side = (order_type === '1') ? 'buy' : 'sell'; } const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'coin_pair'); market = this.safeMarket (marketId, market); const timestamp = this.safeTimestamp (order, 'created_timestamp'); const fee = { - 'cost': this.safeFloat (order, 'fee'), + 'cost': this.safeNumber (order, 'fee'), 'currency': market['quote'], }; - const price = this.safeFloat (order, 'limit_price'); - // price = this.safeFloat (order, 'executed_price_avg', price); - const average = this.safeFloat (order, 'executed_price_avg'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'executed_quantity'); - const remaining = amount - filled; - const cost = filled * average; + const price = this.safeNumber (order, 'limit_price'); + // price = this.safeNumber (order, 'executed_price_avg', price); + const average = this.safeNumber (order, 'executed_price_avg'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const lastTradeTimestamp = this.safeTimestamp (order, 'updated_timestamp'); const rawTrades = this.safeValue (order, 'operations', []); const trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'side': side, 'order': id, }); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -94053,15 +92473,15 @@ module.exports = class mercado extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -94119,11 +92539,11 @@ module.exports = class mercado extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -94244,13 +92664,14 @@ module.exports = class mercado extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],112:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],109:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -94319,11 +92740,11 @@ module.exports = class mixcoins extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.safeFloat (balance, 'lock'); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = this.safeString (balance, 'lock'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -94343,16 +92764,16 @@ module.exports = class mixcoins extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'result'); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -94362,7 +92783,7 @@ module.exports = class mixcoins extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -94375,14 +92796,11 @@ module.exports = class mixcoins extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -94475,7 +92893,7 @@ module.exports = class mixcoins extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],113:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],110:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -94483,6 +92901,7 @@ module.exports = class mixcoins extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -94722,7 +93141,7 @@ module.exports = class ndax extends Exchange { const name = this.safeString (currency, 'ProductFullName'); const type = this.safeString (currency, 'ProductType'); const code = this.safeCurrencyCode (this.safeString (currency, 'Product')); - const precision = this.safeFloat (currency, 'TickSize'); + const precision = this.safeNumber (currency, 'TickSize'); const isDisabled = this.safeValue (currency, 'IsDisabled'); const active = !isDisabled; result[code] = { @@ -94803,8 +93222,8 @@ module.exports = class ndax extends Exchange { const quote = this.safeCurrencyCode (this.safeString (market, 'Product2Symbol')); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'QuantityIncrement'), - 'price': this.safeFloat (market, 'PriceIncrement'), + 'amount': this.safeNumber (market, 'QuantityIncrement'), + 'price': this.safeNumber (market, 'PriceIncrement'), }; const sessionStatus = this.safeString (market, 'SessionStatus'); const isDisable = this.safeValue (market, 'IsDisable'); @@ -94822,11 +93241,11 @@ module.exports = class ndax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinimumQuantity'), + 'min': this.safeNumber (market, 'MinimumQuantity'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'MinimumPrice'), + 'min': this.safeNumber (market, 'MinimumPrice'), 'max': undefined, }, 'cost': { @@ -94947,27 +93366,27 @@ module.exports = class ndax extends Exchange { const timestamp = this.safeInteger (ticker, 'TimeStamp'); const marketId = this.safeString (ticker, 'InstrumentId'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'LastTradedPx'); - const percentage = this.safeFloat (ticker, 'Rolling24HrPxChangePercent'); - const change = this.safeFloat (ticker, 'Rolling24HrPxChange'); - const open = this.safeFloat (ticker, 'SessionOpen'); + const last = this.safeNumber (ticker, 'LastTradedPx'); + const percentage = this.safeNumber (ticker, 'Rolling24HrPxChangePercent'); + const change = this.safeNumber (ticker, 'Rolling24HrPxChange'); + const open = this.safeNumber (ticker, 'SessionOpen'); let average = undefined; if ((last !== undefined) && (change !== undefined)) { average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'Rolling24HrVolume'); - const quoteVolume = this.safeFloat (ticker, 'Rolling24HrNotional'); + const baseVolume = this.safeNumber (ticker, 'Rolling24HrVolume'); + const quoteVolume = this.safeNumber (ticker, 'Rolling24HrNotional'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'SessionHigh'), - 'low': this.safeFloat (ticker, 'SessionLow'), - 'bid': this.safeFloat (ticker, 'BestBid'), - 'bidVolume': undefined, // this.safeFloat (ticker, 'BidQty'), always shows 0 - 'ask': this.safeFloat (ticker, 'BestOffer'), - 'askVolume': undefined, // this.safeFloat (ticker, 'AskQty'), always shows 0 + 'high': this.safeNumber (ticker, 'SessionHigh'), + 'low': this.safeNumber (ticker, 'SessionLow'), + 'bid': this.safeNumber (ticker, 'BestBid'), + 'bidVolume': undefined, // this.safeNumber (ticker, 'BidQty'), always shows 0 + 'ask': this.safeNumber (ticker, 'BestOffer'), + 'askVolume': undefined, // this.safeNumber (ticker, 'AskQty'), always shows 0 'vwap': vwap, 'open': open, 'close': last, @@ -95040,11 +93459,11 @@ module.exports = class ndax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -95192,8 +93611,8 @@ module.exports = class ndax extends Exchange { // "OMSId":1 // } // - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let cost = undefined; let timestamp = undefined; let id = undefined; @@ -95204,11 +93623,8 @@ module.exports = class ndax extends Exchange { let fee = undefined; let type = undefined; if (Array.isArray (trade)) { - price = this.safeFloat (trade, 3); - amount = this.safeFloat (trade, 2); - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + priceString = this.safeString (trade, 3); + amountString = this.safeString (trade, 2); timestamp = this.safeInteger (trade, 6); id = this.safeString (trade, 0); marketId = this.safeInteger (trade, 1); @@ -95220,13 +93636,13 @@ module.exports = class ndax extends Exchange { id = this.safeString (trade, 'TradeId'); orderId = this.safeString2 (trade, 'OrderId', 'OrigOrderId'); marketId = this.safeString2 (trade, 'InstrumentId', 'Instrument'); - price = this.safeFloat (trade, 'Price'); - amount = this.safeFloat (trade, 'Quantity'); - cost = this.safeFloat2 (trade, 'Value', 'GrossValueExecuted'); + priceString = this.safeString (trade, 'Price'); + amountString = this.safeString (trade, 'Quantity'); + cost = this.safeNumber2 (trade, 'Value', 'GrossValueExecuted'); takerOrMaker = this.safeStringLower (trade, 'MakerTaker'); side = this.safeStringLower (trade, 'Side'); type = this.safeStringLower (trade, 'OrderType'); - const feeCost = this.safeFloat (trade, 'Fee'); + const feeCost = this.safeNumber (trade, 'Fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'FeeProductId'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -95236,6 +93652,11 @@ module.exports = class ndax extends Exchange { }; } } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const symbol = this.safeSymbol (marketId, market); return { 'info': trade, @@ -95350,11 +93771,11 @@ module.exports = class ndax extends Exchange { const currencyId = this.safeString (balance, 'ProductId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Amount'); - account['used'] = this.safeFloat (balance, 'Hold'); + account['total'] = this.safeString (balance, 'Amount'); + account['used'] = this.safeString (balance, 'Hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseLedgerEntryType (type) { @@ -95400,8 +93821,8 @@ module.exports = class ndax extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'ReferenceType')); const currencyId = this.safeString (item, 'ProductId'); const code = this.safeCurrencyCode (currencyId, currency); - const credit = this.safeFloat (item, 'CR'); - const debit = this.safeFloat (item, 'DR'); + const credit = this.safeNumber (item, 'CR'); + const debit = this.safeNumber (item, 'DR'); let amount = undefined; let direction = undefined; if (credit > 0) { @@ -95413,7 +93834,7 @@ module.exports = class ndax extends Exchange { } const timestamp = this.safeInteger (item, 'TimeStamp'); let before = undefined; - const after = this.safeFloat (item, 'Balance'); + const after = this.safeNumber (item, 'Balance'); if (direction === 'out') { before = this.sum (after, amount); } else if (direction === 'in') { @@ -95561,36 +93982,26 @@ module.exports = class ndax extends Exchange { // const id = this.safeString2 (order, 'ReplacementOrderId', 'OrderId'); const timestamp = this.safeInteger (order, 'ReceiveTime'); - let lastTradeTimestamp = undefined; + const lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); const marketId = this.safeString (order, 'Instrument'); const symbol = this.safeSymbol (marketId, market); const side = this.safeStringLower (order, 'Side'); const type = this.safeStringLower (order, 'OrderType'); const clientOrderId = this.safeString2 (order, 'ReplacementClOrdId', 'ClientOrderId'); - let price = this.safeFloat (order, 'Price', 0.0); + let price = this.safeNumber (order, 'Price', 0.0); price = (price > 0.0) ? price : undefined; - const amount = this.safeFloat (order, 'OrigQuantity'); - const filled = this.safeFloat (order, 'QuantityExecuted'); - const cost = this.safeFloat (order, 'GrossValueExecuted'); - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (filled > 0) { - lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); - average = this.safeFloat (order, 'AvgPrice', 0.0); - average = (average > 0) ? average : undefined; - } - } - let stopPrice = this.safeFloat (order, 'StopPrice', 0.0); + const amount = this.safeNumber (order, 'OrigQuantity'); + const filled = this.safeNumber (order, 'QuantityExecuted'); + const cost = this.safeNumber (order, 'GrossValueExecuted'); + let average = this.safeNumber (order, 'AvgPrice', 0.0); + average = (average > 0) ? average : undefined; + let stopPrice = this.safeNumber (order, 'StopPrice', 0.0); stopPrice = (stopPrice > 0.0) ? stopPrice : undefined; const timeInForce = undefined; const status = this.parseOrderStatus (this.safeString (order, 'OrderState')); const fee = undefined; const trades = undefined; - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -95609,10 +94020,10 @@ module.exports = class ndax extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -96410,8 +94821,8 @@ module.exports = class ndax extends Exchange { } const addressTo = address; const status = this.parseTransactionStatusByType (this.safeString (transaction, 'TicketStatus'), type); - const amount = this.safeFloat (transaction, 'Amount'); - const feeCost = this.safeFloat (transaction, 'FeeAmount'); + const amount = this.safeNumber (transaction, 'Amount'); + const feeCost = this.safeNumber (transaction, 'FeeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -96492,7 +94903,7 @@ module.exports = class ndax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],114:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],111:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -96500,6 +94911,7 @@ module.exports = class ndax extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, BadRequest, CancelPending, OrderNotFound, InsufficientFunds, RateLimitExceeded, InvalidOrder, AccountSuspended, BadSymbol, OnMaintenance } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -96692,7 +95104,7 @@ module.exports = class novadax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -96700,7 +95112,7 @@ module.exports = class novadax extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderValue'), + 'min': this.safeNumber (market, 'minOrderValue'), 'max': undefined, }, }; @@ -96742,8 +95154,8 @@ module.exports = class novadax extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const open = this.safeFloat (ticker, 'open24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'open24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let percentage = undefined; let change = undefined; let average = undefined; @@ -96752,18 +95164,18 @@ module.exports = class novadax extends Exchange { percentage = change / open * 100; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'baseVolume24h'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume24h'); + const baseVolume = this.safeNumber (ticker, 'baseVolume24h'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -96919,11 +95331,13 @@ module.exports = class novadax extends Exchange { const orderId = this.safeString (trade, 'orderId'); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeStringLower (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - cost = amount * price; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'volume'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); @@ -96935,7 +95349,7 @@ module.exports = class novadax extends Exchange { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { - 'cost': this.safeFloat (parts, 0), + 'cost': this.safeNumber (parts, 0), 'currency': feeCurrencyCode, }; } @@ -97043,11 +95457,11 @@ module.exports = class novadax extends Exchange { const volumeField = this.safeString (options, 'volume', 'amount'); // or vol return [ this.safeTimestamp (ohlcv, 'score'), - this.safeFloat (ohlcv, 'openPrice'), - this.safeFloat (ohlcv, 'highPrice'), - this.safeFloat (ohlcv, 'lowPrice'), - this.safeFloat (ohlcv, 'closePrice'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'openPrice'), + this.safeNumber (ohlcv, 'highPrice'), + this.safeNumber (ohlcv, 'lowPrice'), + this.safeNumber (ohlcv, 'closePrice'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -97075,12 +95489,12 @@ module.exports = class novadax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'available'); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); + account['total'] = this.safeString (balance, 'available'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -97103,7 +95517,7 @@ module.exports = class novadax extends Exchange { if (uppercaseSide === 'SELL') { request['amount'] = this.amountToPrecision (symbol, amount); } else if (uppercaseSide === 'BUY') { - let value = this.safeFloat (params, 'value'); + let value = this.safeNumber (params, 'value'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -97333,21 +95747,17 @@ module.exports = class novadax extends Exchange { // } // const id = this.safeString (order, 'id'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'filledValue'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'filledValue'); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeInteger (order, 'timestamp'); - const average = this.safeFloat (order, 'averagePrice'); - const filled = this.safeFloat (order, 'filledAmount'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } + const average = this.safeNumber (order, 'averagePrice'); + const filled = this.safeNumber (order, 'filledAmount'); let fee = undefined; - const feeCost = this.safeFloat (order, 'filledFee'); + const feeCost = this.safeNumber (order, 'filledFee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -97356,7 +95766,7 @@ module.exports = class novadax extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -97374,11 +95784,11 @@ module.exports = class novadax extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async withdraw (code, amount, address, tag = undefined, params = {}) { @@ -97541,7 +95951,7 @@ module.exports = class novadax extends Exchange { } else if (type === 'COIN_OUT') { type = 'withdraw'; } - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'addressTag'); const txid = this.safeString (transaction, 'txHash'); @@ -97683,7 +96093,7 @@ module.exports = class novadax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],115:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],112:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -97833,10 +96243,10 @@ module.exports = class oceanex extends Exchange { 'active': true, 'info': market, 'precision': { - 'amount': this.safeValue (market, 'amount_precision'), - 'price': this.safeValue (market, 'price_precision'), - 'base': this.safeValue (market, 'ask_precision'), - 'quote': this.safeValue (market, 'bid_precision'), + 'amount': this.safeInteger (market, 'amount_precision'), + 'price': this.safeInteger (market, 'price_precision'), + 'base': this.safeInteger (market, 'ask_precision'), + 'quote': this.safeInteger (market, 'bid_precision'), }, 'limits': { 'amount': { @@ -97848,7 +96258,7 @@ module.exports = class oceanex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeValue (market, 'minimum_trading_amount'), + 'min': this.safeNumber (market, 'minimum_trading_amount'), 'max': undefined, }, }, @@ -97942,21 +96352,21 @@ module.exports = class oceanex extends Exchange { 'symbol': market['symbol'], 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (ticker, 'last'), - 'last': this.safeFloat (ticker, 'last'), + 'close': this.safeNumber (ticker, 'last'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -98081,8 +96491,8 @@ module.exports = class oceanex extends Exchange { 'type': 'limit', 'takerOrMaker': undefined, 'side': side, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), 'cost': undefined, 'fee': undefined, }; @@ -98109,8 +96519,8 @@ module.exports = class oceanex extends Exchange { result[symbol] = { 'info': group, 'symbol': symbol, - 'maker': this.safeFloat (maker, 'value'), - 'taker': this.safeFloat (taker, 'value'), + 'maker': this.safeNumber (maker, 'value'), + 'taker': this.safeNumber (taker, 'value'), }; } return result; @@ -98132,11 +96542,11 @@ module.exports = class oceanex extends Exchange { const currencyId = this.safeValue (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -98244,12 +96654,12 @@ module.exports = class oceanex extends Exchange { // const status = this.parseOrderStatus (this.safeValue (order, 'state')); const marketId = this.safeString2 (order, 'market', 'market_id'); - const symbol = this.safeSymbol (marketId); + const symbol = this.safeSymbol (marketId, market); let timestamp = this.safeTimestamp (order, 'created_on'); if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'created_at')); } - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, @@ -98261,17 +96671,17 @@ module.exports = class oceanex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeValue (order, 'side'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_price'), - 'amount': this.safeFloat (order, 'volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'filled': this.safeFloat (order, 'executed_volume'), + 'average': this.safeNumber (order, 'avg_price'), + 'amount': this.safeNumber (order, 'volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'filled': this.safeNumber (order, 'executed_volume'), 'status': status, 'cost': undefined, 'trades': undefined, 'fee': undefined, - }; + }); } parseOrderStatus (status) { @@ -98364,12 +96774,12 @@ module.exports = class oceanex extends Exchange { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['codes'], errorCode, feedback); this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - throw new ExchangeError (response); + throw new ExchangeError (feedback); } } }; -},{"./base/Exchange":6,"./base/errors":8}],116:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],113:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -98406,7 +96816,7 @@ module.exports = class okcoin extends okex { } }; -},{"./okex.js":117}],117:[function(require,module,exports){ +},{"./okex.js":114}],114:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -98414,6 +96824,7 @@ module.exports = class okcoin extends okex { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -99207,7 +97618,7 @@ module.exports = class okex extends Exchange { let option = false; let baseId = this.safeString (market, 'base_currency'); let quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { if ('option_type' in market) { marketType = 'option'; @@ -99233,12 +97644,12 @@ module.exports = class okex extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = spot ? (base + '/' + quote) : id; - const lotSize = this.safeFloat2 (market, 'lot_size', 'trade_increment'); + const lotSize = this.safeNumber2 (market, 'lot_size', 'trade_increment'); const precision = { - 'amount': this.safeFloat (market, 'size_increment', lotSize), - 'price': this.safeFloat (market, 'tick_size'), + 'amount': this.safeNumber (market, 'size_increment', lotSize), + 'price': this.safeNumber (market, 'tick_size'), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const active = true; const fees = this.safeValue2 (this.fees, marketType, 'trading', {}); return this.extend (fees, { @@ -99413,7 +97824,7 @@ module.exports = class okex extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal'), + 'min': this.safeNumber (currency, 'min_withdrawal'), 'max': undefined, }, }, @@ -99488,18 +97899,18 @@ module.exports = class okex extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open_24h'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open_24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_24h'), - 'low': this.safeFloat (ticker, 'low_24h'), - 'bid': this.safeFloat (ticker, 'best_bid'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (ticker, 'best_ask'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber (ticker, 'high_24h'), + 'low': this.safeNumber (ticker, 'low_24h'), + 'bid': this.safeNumber (ticker, 'best_bid'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (ticker, 'best_ask'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': undefined, 'open': open, 'close': last, @@ -99508,8 +97919,8 @@ module.exports = class okex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'base_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'quote_volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'base_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'quote_volume_24h'), 'info': ticker, }; } @@ -99646,9 +98057,12 @@ module.exports = class okex extends Exchange { quote = market['quote']; } const timestamp = this.parse8601 (this.safeString2 (trade, 'timestamp', 'created_at')); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'size', 'qty'); - amount = this.safeFloat (trade, 'order_qty', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'size', 'qty'); + amountString = this.safeString (trade, 'order_qty', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -99656,13 +98070,7 @@ module.exports = class okex extends Exchange { takerOrMaker = 'taker'; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -99771,22 +98179,22 @@ module.exports = class okex extends Exchange { } return [ timestamp, // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets ]; } else { return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, 'volume'), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, 'volume'), // Base Volume ]; } } @@ -99932,9 +98340,9 @@ module.exports = class okex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeNumber (balance, 'balance'); + account['used'] = this.safeNumber (balance, 'hold'); + account['free'] = this.safeNumber (balance, 'available'); result[code] = account; } return this.parseBalance (result); @@ -100004,9 +98412,9 @@ module.exports = class okex extends Exchange { const currencyId = parts[1]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (marketBalance, 'balance'); - account['used'] = this.safeFloat (marketBalance, 'hold'); - account['free'] = this.safeFloat (marketBalance, 'available'); + account['total'] = this.safeNumber (marketBalance, 'balance'); + account['used'] = this.safeNumber (marketBalance, 'hold'); + account['free'] = this.safeNumber (marketBalance, 'available'); accounts[code] = account; } else { throw new NotSupported (this.id + ' margin balance response format has changed!'); @@ -100059,29 +98467,29 @@ module.exports = class okex extends Exchange { const code = this.safeCurrencyCode (id); const balance = this.safeValue (info, id, {}); const account = this.account (); - const totalAvailBalance = this.safeFloat (balance, 'total_avail_balance'); + const totalAvailBalance = this.safeNumber (balance, 'total_avail_balance'); if (this.safeString (balance, 'margin_mode') === 'fixed') { const contracts = this.safeValue (balance, 'contracts', []); let free = totalAvailBalance; for (let i = 0; i < contracts.length; i++) { const contract = contracts[i]; - const fixedBalance = this.safeFloat (contract, 'fixed_balance'); - const realizedPnl = this.safeFloat (contract, 'realized_pnl'); - const marginFrozen = this.safeFloat (contract, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (contract, 'margin_for_unfilled'); + const fixedBalance = this.safeNumber (contract, 'fixed_balance'); + const realizedPnl = this.safeNumber (contract, 'realized_pnl'); + const marginFrozen = this.safeNumber (contract, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (contract, 'margin_for_unfilled'); const margin = this.sum (fixedBalance, realizedPnl) - marginFrozen - marginForUnfilled; free = this.sum (free, margin); } account['free'] = free; } else { - const realizedPnl = this.safeFloat (balance, 'realized_pnl'); - const unrealizedPnl = this.safeFloat (balance, 'unrealized_pnl'); - const marginFrozen = this.safeFloat (balance, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (balance, 'margin_for_unfilled'); + const realizedPnl = this.safeNumber (balance, 'realized_pnl'); + const unrealizedPnl = this.safeNumber (balance, 'unrealized_pnl'); + const marginFrozen = this.safeNumber (balance, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (balance, 'margin_for_unfilled'); account['free'] = this.sum (totalAvailBalance, realizedPnl, unrealizedPnl) - marginFrozen - marginForUnfilled; } // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); + account['total'] = this.safeNumber (balance, 'equity'); result[code] = account; } return this.parseBalance (result); @@ -100119,8 +98527,8 @@ module.exports = class okex extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeNumber (balance, 'equity'); + account['free'] = this.safeNumber (balance, 'total_avail_balance'); result[symbol] = account; } return this.parseBalance (result); @@ -100324,7 +98732,7 @@ module.exports = class okex extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -100534,8 +98942,8 @@ module.exports = class okex extends Exchange { symbol = market['symbol']; } } - let amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat2 (order, 'filled_size', 'filled_qty'); + let amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber2 (order, 'filled_size', 'filled_qty'); let remaining = undefined; if (amount !== undefined) { if (filled !== undefined) { @@ -100546,9 +98954,9 @@ module.exports = class okex extends Exchange { if (type === 'market') { remaining = 0; } - let cost = this.safeFloat2 (order, 'filled_notional', 'funds'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); + let cost = this.safeNumber2 (order, 'filled_notional', 'funds'); + const price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'price_avg'); if (cost === undefined) { if (filled !== undefined && average !== undefined) { cost = average * filled; @@ -100559,7 +98967,7 @@ module.exports = class okex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'state')); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -100572,7 +98980,7 @@ module.exports = class okex extends Exchange { if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) { clientOrderId = undefined; // fix empty clientOrderId string } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); return { 'info': order, 'id': id, @@ -100816,16 +99224,6 @@ module.exports = class okex extends Exchange { return await this.fetchOrdersByState ('7', symbol, since, limit, params); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -100853,7 +99251,8 @@ module.exports = class okex extends Exchange { async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); - const currency = this.currency (code); + const parts = code.split ('-'); + const currency = this.currency (parts[0]); const request = { 'currency': currency['id'], }; @@ -100866,8 +99265,8 @@ module.exports = class okex extends Exchange { // } // ] // - const addresses = this.parseDepositAddresses (response); - const address = this.safeValue (addresses, code); + const addressesByCode = this.parseDepositAddresses (response); + const address = this.safeValue (addressesByCode, code); if (address === undefined) { throw new InvalidAddress (this.id + ' fetchDepositAddress cannot return nonexistent addresses, you should create withdrawal addresses with the exchange website first'); } @@ -101042,7 +99441,7 @@ module.exports = class okex extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const txid = this.safeString (transaction, 'txid'); const timestamp = this.parse8601 (this.safeString (transaction, 'timestamp')); @@ -101105,19 +99504,19 @@ module.exports = class okex extends Exchange { let feeCurrencyId = undefined; if (receivedCurrencyId === quoteId) { side = this.safeString (otherTrade, 'side'); - amount = this.safeFloat (otherTrade, 'size'); - cost = this.safeFloat (userTrade, 'size'); + amount = this.safeNumber (otherTrade, 'size'); + cost = this.safeNumber (userTrade, 'size'); feeCurrencyId = this.safeString (otherTrade, 'currency'); } else { side = this.safeString (userTrade, 'side'); - amount = this.safeFloat (userTrade, 'size'); - cost = this.safeFloat (otherTrade, 'size'); + amount = this.safeNumber (userTrade, 'size'); + cost = this.safeNumber (otherTrade, 'size'); feeCurrencyId = this.safeString (userTrade, 'currency'); } const id = this.safeString (userTrade, 'trade_id'); - const price = this.safeFloat (userTrade, 'price'); - const feeCostFirst = this.safeFloat (otherTrade, 'fee'); - const feeCostSecond = this.safeFloat (userTrade, 'fee'); + const price = this.safeNumber (userTrade, 'price'); + const feeCostFirst = this.safeNumber (otherTrade, 'fee'); + const feeCostSecond = this.safeNumber (userTrade, 'fee'); const feeCurrencyCodeFirst = this.safeCurrencyCode (this.safeString (otherTrade, 'currency')); const feeCurrencyCodeSecond = this.safeCurrencyCode (this.safeString (userTrade, 'currency')); let fee = undefined; @@ -101549,7 +99948,7 @@ module.exports = class okex extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); let method = undefined; const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType'); @@ -101931,14 +100330,14 @@ module.exports = class okex extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'timestamp')); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; const marketId = this.safeString (item, 'instrument_id'); let symbol = undefined; @@ -102048,13 +100447,14 @@ module.exports = class okex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],118:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],115:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -102147,12 +100547,12 @@ module.exports = class paymium extends Exchange { if (free in response) { const account = this.account (); const used = 'locked_' + currencyId; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -102171,30 +100571,30 @@ module.exports = class paymium extends Exchange { }; const ticker = await this.publicGetDataCurrencyTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'at'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'price'); + const last = this.safeNumber (ticker, 'price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'variation'), + 'percentage': this.safeNumber (ticker, 'variation'), 'average': undefined, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, @@ -102210,15 +100610,12 @@ module.exports = class paymium extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); + const priceString = this.safeString (trade, 'price'); const amountField = 'traded_' + market['base'].toLowerCase (); - const amount = this.safeFloat (trade, amountField); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const amountString = this.safeString (trade, amountField); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -102313,7 +100710,7 @@ module.exports = class paymium extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],119:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],116:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -102621,13 +101018,13 @@ module.exports = class phemex extends Exchange { }); } - parseSafeFloat (value = undefined) { + parseSafeNumber (value = undefined) { if (value === undefined) { return value; } value = value.replace (',', ''); const parts = value.split (' '); - return this.safeFloat (parts, 0); + return this.safeNumber (parts, 0); } parseSwapMarket (market) { @@ -102651,7 +101048,9 @@ module.exports = class phemex extends Exchange { // "minPriceEp":5000, // "maxPriceEp":10000000000, // "maxOrderQty":1000000, - // "type":"Perpetual" + // "type":"Perpetual", + // "status":"Listed", + // "tipOrderQty":1000000, // "steps":"50", // "riskLimits":[ // {"limit":100,"initialMargin":"1.0%","initialMarginEr":1000000,"maintenanceMargin":"0.5%","maintenanceMarginEr":500000}, @@ -102676,7 +101075,7 @@ module.exports = class phemex extends Exchange { // } // const id = this.safeString (market, 'symbol'); - const baseId = this.safeString (market, 'baseCurrency', 'contractUnderlyingAssets'); + const baseId = this.safeString2 (market, 'baseCurrency', 'contractUnderlyingAssets'); const quoteId = this.safeString (market, 'quoteCurrency'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); @@ -102693,16 +101092,16 @@ module.exports = class phemex extends Exchange { } const linear = !inverse; const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const priceScale = this.safeInteger (market, 'priceScale'); const ratioScale = this.safeInteger (market, 'ratioScale'); const valueScale = this.safeInteger (market, 'valueScale'); - const minPriceEp = this.safeFloat (market, 'minPriceEp'); - const maxPriceEp = this.safeFloat (market, 'maxPriceEp'); - const makerFeeRateEr = this.safeFloat (market, 'makerFeeRateEr'); - const takerFeeRateEr = this.safeFloat (market, 'takerFeeRateEr'); + const minPriceEp = this.safeNumber (market, 'minPriceEp'); + const maxPriceEp = this.safeNumber (market, 'maxPriceEp'); + const makerFeeRateEr = this.safeNumber (market, 'makerFeeRateEr'); + const takerFeeRateEr = this.safeNumber (market, 'takerFeeRateEr'); if (makerFeeRateEr !== undefined) { maker = this.fromEn (makerFeeRateEr, ratioScale, 0.00000001); } @@ -102720,10 +101119,11 @@ module.exports = class phemex extends Exchange { }, 'cost': { 'min': undefined, - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderQty')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderQty')), }, }; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -102772,7 +101172,9 @@ module.exports = class phemex extends Exchange { // "defaultMakerFee":"0.001", // "defaultMakerFeeEr":100000, // "baseQtyPrecision":6, - // "quoteQtyPrecision":2 + // "quoteQtyPrecision":2, + // "status":"Listed", + // "tipOrderQty":20 // } // const type = this.safeStringLower (market, 'type'); @@ -102783,30 +101185,31 @@ module.exports = class phemex extends Exchange { const inverse = undefined; const spot = true; const swap = false; - const taker = this.safeFloat (market, 'defaultTakerFee'); - const maker = this.safeFloat (market, 'defaultMakerFee'); + const taker = this.safeNumber (market, 'defaultTakerFee'); + const maker = this.safeNumber (market, 'defaultMakerFee'); const precision = { - 'amount': this.parseSafeFloat (this.safeString (market, 'baseTickSize')), - 'price': this.parseSafeFloat (this.safeString (market, 'quoteTickSize')), + 'amount': this.parseSafeNumber (this.safeString (market, 'baseTickSize')), + 'price': this.parseSafeNumber (this.safeString (market, 'quoteTickSize')), }; const limits = { 'amount': { 'min': precision['amount'], - 'max': this.parseSafeFloat (this.safeString (market, 'maxBaseOrderSize')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxBaseOrderSize')), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.parseSafeFloat (this.safeString (market, 'minOrderValue')), - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderValue')), + 'min': this.parseSafeNumber (this.safeString (market, 'minOrderValue')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderValue')), }, }; const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -102996,8 +101399,8 @@ module.exports = class phemex extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const valueScale = this.safeInteger (currency, 'valueScale'); - const minValueEv = this.safeFloat (currency, 'minValueEv'); - const maxValueEv = this.safeFloat (currency, 'maxValueEv'); + const minValueEv = this.safeNumber (currency, 'minValueEv'); + const maxValueEv = this.safeNumber (currency, 'maxValueEv'); let minAmount = undefined; let maxAmount = undefined; let precision = undefined; @@ -103047,12 +101450,12 @@ module.exports = class phemex extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - let amount = this.safeFloat (bidask, amountKey); + let amount = this.safeNumber (bidask, amountKey); if (market['spot']) { amount = this.fromEv (amount, market); } return [ - this.fromEp (this.safeFloat (bidask, priceKey), market), + this.fromEp (this.safeNumber (bidask, priceKey), market), amount, ]; } @@ -103186,16 +101589,16 @@ module.exports = class phemex extends Exchange { // let baseVolume = undefined; if ((market !== undefined) && market['spot']) { - baseVolume = this.fromEv (this.safeFloat (ohlcv, 7), market); + baseVolume = this.fromEv (this.safeNumber (ohlcv, 7), market); } else { baseVolume = this.safeInteger (ohlcv, 7); } return [ this.safeTimestamp (ohlcv, 0), - this.fromEp (this.safeFloat (ohlcv, 3), market), - this.fromEp (this.safeFloat (ohlcv, 4), market), - this.fromEp (this.safeFloat (ohlcv, 5), market), - this.fromEp (this.safeFloat (ohlcv, 6), market), + this.fromEp (this.safeNumber (ohlcv, 3), market), + this.fromEp (this.safeNumber (ohlcv, 4), market), + this.fromEp (this.safeNumber (ohlcv, 5), market), + this.fromEp (this.safeNumber (ohlcv, 6), market), baseVolume, ]; } @@ -103288,11 +101691,11 @@ module.exports = class phemex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.000001); - const last = this.fromEp (this.safeFloat (ticker, 'lastEp'), market); - const quoteVolume = this.fromEp (this.safeFloat (ticker, 'turnoverEv'), market); - let baseVolume = this.safeFloat (ticker, 'volume'); + const last = this.fromEp (this.safeNumber (ticker, 'lastEp'), market); + const quoteVolume = this.fromEp (this.safeNumber (ticker, 'turnoverEv'), market); + let baseVolume = this.safeNumber (ticker, 'volume'); if (baseVolume === undefined) { - baseVolume = this.fromEv (this.safeFloat (ticker, 'volumeEv')); + baseVolume = this.fromEv (this.safeNumber (ticker, 'volumeEv')); } let vwap = undefined; if ((market !== undefined) && (market['spot'])) { @@ -103301,7 +101704,7 @@ module.exports = class phemex extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.fromEp (this.safeFloat (ticker, 'openEp'), market); + const open = this.fromEp (this.safeNumber (ticker, 'openEp'), market); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -103313,11 +101716,11 @@ module.exports = class phemex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.fromEp (this.safeFloat (ticker, 'highEp'), market), - 'low': this.fromEp (this.safeFloat (ticker, 'lowEp'), market), - 'bid': this.fromEp (this.safeFloat (ticker, 'bidEp'), market), + 'high': this.fromEp (this.safeNumber (ticker, 'highEp'), market), + 'low': this.fromEp (this.safeNumber (ticker, 'lowEp'), market), + 'bid': this.fromEp (this.safeNumber (ticker, 'bidEp'), market), 'bidVolume': undefined, - 'ask': this.fromEp (this.safeFloat (ticker, 'askEp'), market), + 'ask': this.fromEp (this.safeNumber (ticker, 'askEp'), market), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -103508,8 +101911,8 @@ module.exports = class phemex extends Exchange { id = this.safeString (trade, tradeLength - 4); } side = this.safeStringLower (trade, tradeLength - 3); - price = this.fromEp (this.safeFloat (trade, tradeLength - 2), market); - amount = this.fromEv (this.safeFloat (trade, tradeLength - 1), market); + price = this.fromEp (this.safeNumber (trade, tradeLength - 2), market); + amount = this.fromEv (this.safeNumber (trade, tradeLength - 1), market); if (market['spot']) { if ((price !== undefined) && (amount !== undefined)) { cost = price * amount; @@ -103525,14 +101928,14 @@ module.exports = class phemex extends Exchange { if (execStatus === 'MakerFill') { takerOrMaker = 'maker'; } - price = this.fromEp (this.safeFloat (trade, 'execPriceEp'), market); - amount = this.fromEv (this.safeFloat (trade, 'execBaseQtyEv'), market); - amount = this.safeFloat (trade, 'execQty', amount); - cost = this.fromEv (this.safeFloat2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); - const feeCost = this.fromEv (this.safeFloat (trade, 'execFeeEv'), market); + price = this.fromEp (this.safeNumber (trade, 'execPriceEp'), market); + amount = this.fromEv (this.safeNumber (trade, 'execBaseQtyEv'), market); + amount = this.safeNumber (trade, 'execQty', amount); + cost = this.fromEv (this.safeNumber2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); + const feeCost = this.fromEv (this.safeNumber (trade, 'execFeeEv'), market); if (feeCost !== undefined) { let feeRate = undefined; - let feeRateEr = this.safeFloat (trade, 'feeRateEr'); + let feeRateEr = this.safeNumber (trade, 'feeRateEr'); if (feeRateEr < 0) { feeRateEr = Math.abs (feeRateEr); feeRate = this.fromEr (feeRateEr, market); @@ -103608,9 +102011,9 @@ module.exports = class phemex extends Exchange { const currency = this.safeValue (this.currencies, code, {}); const scale = this.safeInteger (currency, 'valueScale', 8); const account = this.account (); - const balanceEv = this.safeFloat (balance, 'balanceEv'); - const lockedTradingBalanceEv = this.safeFloat (balance, 'lockedTradingBalanceEv'); - const lockedWithdrawEv = this.safeFloat (balance, 'lockedWithdrawEv'); + const balanceEv = this.safeNumber (balance, 'balanceEv'); + const lockedTradingBalanceEv = this.safeNumber (balance, 'lockedTradingBalanceEv'); + const lockedWithdrawEv = this.safeNumber (balance, 'lockedWithdrawEv'); const total = this.fromEn (balanceEv, scale, scale, DECIMAL_PLACES); const lockedTradingBalance = this.fromEn (lockedTradingBalanceEv, scale, scale, DECIMAL_PLACES); const lockedWithdraw = this.fromEn (lockedWithdrawEv, scale, scale, DECIMAL_PLACES); @@ -103704,8 +102107,8 @@ module.exports = class phemex extends Exchange { const code = this.safeCurrencyCode (currencyId); const currency = this.currency (code); const account = this.account (); - const accountBalanceEv = this.safeFloat (balance, 'accountBalanceEv'); - const totalUsedBalanceEv = this.safeFloat (balance, 'totalUsedBalanceEv'); + const accountBalanceEv = this.safeNumber (balance, 'accountBalanceEv'); + const totalUsedBalanceEv = this.safeNumber (balance, 'totalUsedBalanceEv'); const valueScale = this.safeInteger (currency, 'valueScale', 8); account['total'] = this.fromEn (accountBalanceEv, valueScale, valueScale, DECIMAL_PLACES); account['used'] = this.fromEn (totalUsedBalanceEv, valueScale, valueScale, DECIMAL_PLACES); @@ -103937,21 +102340,21 @@ module.exports = class phemex extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let price = this.fromEp (this.safeFloat (order, 'priceEp'), market); + let price = this.fromEp (this.safeNumber (order, 'priceEp'), market); if (price === 0) { price = undefined; } - const amount = this.fromEv (this.safeFloat (order, 'baseQtyEv'), market); - const remaining = this.fromEv (this.safeFloat (order, 'leavesBaseQtyEv'), market); - let filled = this.fromEv (this.safeFloat (order, 'cumBaseQtyEv'), market); - const cost = this.fromEv (this.safeFloat (order, 'quoteQtyEv'), market); - const average = this.fromEp (this.safeFloat (order, 'avgPriceEp'), market); + const amount = this.fromEv (this.safeNumber (order, 'baseQtyEv'), market); + const remaining = this.fromEv (this.safeNumber (order, 'leavesBaseQtyEv'), market); + let filled = this.fromEv (this.safeNumber (order, 'cumBaseQtyEv'), market); + const cost = this.fromEv (this.safeNumber (order, 'quoteQtyEv'), market); + const average = this.fromEp (this.safeNumber (order, 'avgPriceEp'), market); const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'ordType')); const timestamp = this.safeIntegerProduct2 (order, 'actionTimeNs', 'createTimeNs', 0.000001); let fee = undefined; - const feeCost = this.fromEv (this.safeFloat (order, 'cumFeeEv'), market); + const feeCost = this.fromEv (this.safeNumber (order, 'cumFeeEv'), market); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -103964,7 +102367,7 @@ module.exports = class phemex extends Exchange { } } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.fromEp (this.safeFloat (order, 'stopPxEp', market)); + const stopPrice = this.fromEp (this.safeNumber (order, 'stopPxEp', market)); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -104037,18 +102440,18 @@ module.exports = class phemex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'orderType')); - const price = this.fromEp (this.safeFloat (order, 'priceEp'), market); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); + const price = this.fromEp (this.safeNumber (order, 'priceEp'), market); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); const timestamp = this.safeIntegerProduct (order, 'actionTimeNs', 0.000001); - const cost = this.safeFloat (order, 'cumValue'); + const cost = this.safeNumber (order, 'cumValue'); let lastTradeTimestamp = this.safeIntegerProduct (order, 'transactTimeNs', 0.000001); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -104123,7 +102526,7 @@ module.exports = class phemex extends Exchange { } request['qtyType'] = qtyType; if (qtyType === 'ByQuote') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); params = this.omit (params, 'cost'); if (this.options['createOrderByQuoteRequiresPrice']) { if (price !== undefined) { @@ -104143,7 +102546,7 @@ module.exports = class phemex extends Exchange { if (type === 'Limit') { request['priceEp'] = this.toEp (price, market); } - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice !== undefined) { request['stopPxEp'] = this.toEp (stopPrice, market); } @@ -104651,7 +103054,7 @@ module.exports = class phemex extends Exchange { const code = currency['code']; const timestamp = this.safeInteger2 (transaction, 'createdAt', 'submitedAt'); let type = this.safeStringLower (transaction, 'type'); - const feeCost = this.fromEn (this.safeFloat (transaction, 'feeEv'), currency['valueScale'], currency['precision']); + const feeCost = this.fromEn (this.safeNumber (transaction, 'feeEv'), currency['valueScale'], currency['precision']); let fee = undefined; if (feeCost !== undefined) { type = 'withdrawal'; @@ -104661,7 +103064,7 @@ module.exports = class phemex extends Exchange { }; } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.fromEn (this.safeFloat (transaction, 'amountEv'), currency['valueScale'], currency['precision']); + const amount = this.fromEn (this.safeNumber (transaction, 'amountEv'), currency['valueScale'], currency['precision']); return { 'info': transaction, 'id': id, @@ -104683,7 +103086,7 @@ module.exports = class phemex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.safeString (params, 'code'); const request = {}; @@ -104836,13 +103239,14 @@ module.exports = class phemex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],120:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],117:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, RequestTimeout, AuthenticationError, PermissionDenied, DDoSProtection, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, CancelPending, InvalidNonce, OnMaintenance, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -104952,6 +103356,7 @@ module.exports = class poloniex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', // starting from Jan 8 2020 'maker': 0.0009, 'taker': 0.0009, @@ -105046,24 +103451,6 @@ module.exports = class poloniex extends Exchange { }); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - parseOHLCV (ohlcv, market = undefined) { // // { @@ -105079,11 +103466,11 @@ module.exports = class poloniex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'date'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'quoteVolume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'quoteVolume'), ]; } @@ -105176,11 +103563,11 @@ module.exports = class poloniex extends Exchange { const balance = this.safeValue (response, currencyId, {}); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onOrders'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFees (params = {}) { @@ -105198,8 +103585,8 @@ module.exports = class poloniex extends Exchange { // return { 'info': fees, - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), 'withdraw': {}, 'deposit': {}, }; @@ -105257,8 +103644,8 @@ module.exports = class poloniex extends Exchange { let open = undefined; let change = undefined; let average = undefined; - const last = this.safeFloat (ticker, 'last'); - const relativeChange = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const relativeChange = this.safeNumber (ticker, 'percentChange'); if (relativeChange !== -1) { open = last / this.sum (1, relativeChange); change = last - open; @@ -105268,11 +103655,11 @@ module.exports = class poloniex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24hr'), - 'low': this.safeFloat (ticker, 'low24hr'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high24hr'), + 'low': this.safeNumber (ticker, 'low24hr'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -105282,8 +103669,8 @@ module.exports = class poloniex extends Exchange { 'change': change, 'percentage': relativeChange * 100, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -105324,7 +103711,7 @@ module.exports = class poloniex extends Exchange { const code = this.safeCurrencyCode (id); const active = (currency['delisted'] === 0) && !currency['disabled']; const numericId = this.safeInteger (currency, 'id'); - const fee = this.safeFloat (currency, 'txFee'); + const fee = this.safeNumber (currency, 'txFee'); result[code] = { 'id': id, 'numericId': numericId, @@ -105415,13 +103802,18 @@ module.exports = class poloniex extends Exchange { } const side = this.safeString (trade, 'type'); let fee = undefined; - const price = this.safeFloat (trade, 'rate'); - const cost = this.safeFloat (trade, 'total'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const feeDisplay = this.safeString (trade, 'feeDisplay'); if (feeDisplay !== undefined) { const parts = feeDisplay.split (' '); - const feeCost = this.safeFloat (parts, 0); + const feeCost = this.safeNumber (parts, 0); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -105440,7 +103832,7 @@ module.exports = class poloniex extends Exchange { } } let takerOrMaker = undefined; - const takerAdjustment = this.safeFloat (trade, 'takerAdjustment'); + const takerAdjustment = this.safeNumber (trade, 'takerAdjustment'); if (takerAdjustment !== undefined) { takerOrMaker = 'taker'; } @@ -105686,9 +104078,9 @@ module.exports = class poloniex extends Exchange { if (resultingTrades !== undefined) { trades = this.parseTrades (resultingTrades, market); } - const price = this.safeFloat2 (order, 'price', 'rate'); - let remaining = this.safeFloat (order, 'amount'); - let amount = this.safeFloat (order, 'startingAmount'); + const price = this.safeNumber2 (order, 'price', 'rate'); + let remaining = this.safeNumber (order, 'amount'); + let amount = this.safeNumber (order, 'startingAmount'); let filled = undefined; let cost = 0; if (amount !== undefined) { @@ -105738,7 +104130,7 @@ module.exports = class poloniex extends Exchange { } const id = this.safeString (order, 'orderNumber'); let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -106235,11 +104627,11 @@ module.exports = class poloniex extends Exchange { const defaultType = ('withdrawalNumber' in transaction) ? 'withdrawal' : 'deposit'; const type = this.safeString (transaction, 'type', defaultType); const id = this.safeString2 (transaction, 'withdrawalNumber', 'depositNumber'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'paymentID'); // according to https://poloniex.com/fees/ - const feeCost = this.safeFloat (transaction, 'fee', 0); + const feeCost = this.safeNumber (transaction, 'fee', 0); if (type === 'withdrawal') { // poloniex withdrawal amount includes the fee amount = amount - feeCost; @@ -106323,7 +104715,7 @@ module.exports = class poloniex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],121:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],118:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -106331,6 +104723,7 @@ module.exports = class poloniex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, BadResponse, BadRequest, InvalidOrder, InsufficientFunds, AuthenticationError, ArgumentsRequired, InvalidAddress, RateLimitExceeded, DDoSProtection, BadSymbol } = require ('./base/errors'); const { TRUNCATE, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -106466,9 +104859,11 @@ module.exports = class probit extends Exchange { }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', 'CBC': 'CryptoBharatCoin', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'HBC': 'Hybrid Bank Cash', 'UNI': 'UNICORN Token', }, @@ -106517,11 +104912,11 @@ module.exports = class probit extends Exchange { const costPrecision = this.safeInteger (market, 'cost_precision'); const precision = { 'amount': 1 / Math.pow (10, amountPrecision), - 'price': this.safeFloat (market, 'price_increment'), + 'price': this.safeNumber (market, 'price_increment'), 'cost': 1 / Math.pow (10, costPrecision), }; - const takerFeeRate = this.safeFloat (market, 'taker_fee_rate'); - const makerFeeRate = this.safeFloat (market, 'maker_fee_rate'); + const takerFeeRate = this.safeNumber (market, 'taker_fee_rate'); + const makerFeeRate = this.safeNumber (market, 'maker_fee_rate'); result.push ({ 'id': id, 'info': market, @@ -106536,16 +104931,16 @@ module.exports = class probit extends Exchange { 'maker': makerFeeRate / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_cost'), - 'max': this.safeFloat (market, 'max_cost'), + 'min': this.safeNumber (market, 'min_cost'), + 'max': this.safeNumber (market, 'max_cost'), }, }, }); @@ -106632,7 +105027,7 @@ module.exports = class probit extends Exchange { // [ { 'amount': '0.015', 'priority': 1, 'currency_id': 'ETH' }, {} ] for (let j = 0; j < withdrawalFees.length; j++) { const withdrawalFee = withdrawalFees[j]; - const amount = this.safeFloat (withdrawalFee, 'amount'); + const amount = this.safeNumber (withdrawalFee, 'amount'); const priority = this.safeInteger (withdrawalFee, 'priority'); if ((amount !== undefined) && (priority !== undefined)) { fees.push (withdrawalFee); @@ -106640,7 +105035,7 @@ module.exports = class probit extends Exchange { } const withdrawalFeesByPriority = this.sortBy (fees, 'priority'); const withdrawalFee = this.safeValue (withdrawalFeesByPriority, 0, {}); - const fee = this.safeFloat (withdrawalFee, 'amount'); + const fee = this.safeNumber (withdrawalFee, 'amount'); result[code] = { 'id': id, 'code': code, @@ -106663,11 +105058,11 @@ module.exports = class probit extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (platform, 'min_deposit_amount'), + 'min': this.safeNumber (platform, 'min_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (platform, 'min_withdrawal_amount'), + 'min': this.safeNumber (platform, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -106697,11 +105092,11 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (balance, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'total'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -106753,14 +105148,6 @@ module.exports = class probit extends Exchange { return this.parseTickers (data, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -106808,8 +105195,8 @@ module.exports = class probit extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); - const close = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); + const close = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); let percentage = undefined; let open = undefined; if (change !== undefined) { @@ -106818,15 +105205,15 @@ module.exports = class probit extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -106968,16 +105355,13 @@ module.exports = class probit extends Exchange { marketId = this.safeString (trade, 'market_id', marketId); const symbol = this.safeSymbol (marketId, market, '-'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'order_id'); - const feeCost = this.safeFloat (trade, 'fee_amount'); + const feeCost = this.safeNumber (trade, 'fee_amount'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency_id'); @@ -107121,11 +105505,11 @@ module.exports = class probit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'start_time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_volume'), ]; } @@ -107224,37 +105608,24 @@ module.exports = class probit extends Exchange { const marketId = this.safeString (order, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'time')); - let price = this.safeFloat (order, 'limit_price'); - const filled = this.safeFloat (order, 'filled_quantity'); - let remaining = this.safeFloat (order, 'open_quantity'); - const canceledAmount = this.safeFloat (order, 'cancelled_quantity'); + let price = this.safeNumber (order, 'limit_price'); + const filled = this.safeNumber (order, 'filled_quantity'); + let remaining = this.safeNumber (order, 'open_quantity'); + const canceledAmount = this.safeNumber (order, 'cancelled_quantity'); if (canceledAmount !== undefined) { remaining = this.sum (remaining, canceledAmount); } - const amount = this.safeFloat (order, 'quantity', this.sum (filled, remaining)); - let cost = this.safeFloat2 (order, 'filled_cost', 'cost'); + const amount = this.safeNumber (order, 'quantity', this.sum (filled, remaining)); + const cost = this.safeNumber2 (order, 'filled_cost', 'cost'); if (type === 'market') { price = undefined; } - let average = undefined; - if (filled !== undefined) { - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if (cost !== undefined) { - if (filled > 0) { - average = cost / filled; - } - } - } let clientOrderId = this.safeString (order, 'client_order_id'); if (clientOrderId === '') { clientOrderId = undefined; } const timeInForce = this.safeStringUpper (order, 'time_in_force'); - return { + return this.safeOrder ({ 'id': id, 'info': order, 'clientOrderId': clientOrderId, @@ -107271,11 +105642,11 @@ module.exports = class probit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'average': average, + 'average': undefined, 'cost': cost, 'fee': undefined, 'trades': undefined, - }; + }); } costToPrecision (symbol, cost) { @@ -107305,7 +105676,7 @@ module.exports = class probit extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -107430,16 +105801,6 @@ module.exports = class probit extends Exchange { return this.parseDepositAddresses (data); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { // In order to use this method // you need to allow API withdrawal from the API Settings Page, and @@ -107470,7 +105831,7 @@ module.exports = class probit extends Exchange { parseTransaction (transaction, currency = undefined) { const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'destination_tag'); const txid = this.safeString (transaction, 'hash'); @@ -107479,7 +105840,7 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (transaction, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined && feeCost !== 0) { fee = { @@ -107609,13 +105970,14 @@ module.exports = class probit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],122:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],119:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, InsufficientFunds, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -107791,11 +106153,11 @@ module.exports = class qtrade extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_buy_value'), + 'min': this.safeNumber (market, 'minimum_buy_value'), 'max': undefined, }, 'price': { @@ -107876,12 +106238,12 @@ module.exports = class qtrade extends Exchange { 'info': currency, 'type': type, 'name': name, - 'fee': this.safeFloat (config, 'withdraw_fee'), + 'fee': this.safeNumber (config, 'withdraw_fee'), 'precision': this.safeInteger (currency, 'precision'), 'active': active, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimum_order'), + 'min': this.safeNumber (currency, 'minimum_order'), 'max': undefined, }, 'price': { @@ -107916,11 +106278,11 @@ module.exports = class qtrade extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'market_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'market_volume'), ]; } @@ -107982,8 +106344,8 @@ module.exports = class qtrade extends Exchange { const result = []; for (let j = 0; j < prices.length; j++) { const priceAsString = prices[j]; - const price = this.safeFloat (prices, j); - const amount = this.safeFloat (bidasks, priceAsString); + const price = this.safeNumber (prices, j); + const amount = this.safeNumber (bidasks, priceAsString); result.push ([ price, amount ]); } orderbook[side] = result; @@ -108015,12 +106377,12 @@ module.exports = class qtrade extends Exchange { const marketId = this.safeString (ticker, 'id_hr'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeIntegerProduct (ticker, 'last_change', 0.001); - const previous = this.safeFloat (ticker, 'day_open'); - const last = this.safeFloat (ticker, 'last'); - const day_change = this.safeFloat (ticker, 'day_change'); + const previous = this.safeNumber (ticker, 'day_open'); + const last = this.safeNumber (ticker, 'last'); + const day_change = this.safeNumber (ticker, 'day_change'); let percentage = undefined; let change = undefined; - let average = this.safeFloat (ticker, 'day_avg_price'); + let average = this.safeNumber (ticker, 'day_avg_price'); if (day_change !== undefined) { percentage = day_change * 100; if (previous !== undefined) { @@ -108030,18 +106392,18 @@ module.exports = class qtrade extends Exchange { if ((average === undefined) && (last !== undefined) && (previous !== undefined)) { average = this.sum (last, previous) / 2; } - const baseVolume = this.safeFloat (ticker, 'day_volume_market'); - const quoteVolume = this.safeFloat (ticker, 'day_volume_base'); + const baseVolume = this.safeNumber (ticker, 'day_volume_market'); + const quoteVolume = this.safeNumber (ticker, 'day_volume_base'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'day_high'), - 'low': this.safeFloat (ticker, 'day_low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'day_high'), + 'low': this.safeNumber (ticker, 'day_low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': previous, @@ -108249,16 +106611,16 @@ module.exports = class qtrade extends Exchange { const side = this.safeString (trade, 'side'); const marketId = this.safeString (trade, 'market_string'); const symbol = this.safeSymbol (marketId, market, '_'); - let cost = this.safeFloat2 (trade, 'base_volume', 'base_amount'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'market_amount', 'amount'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - if (price !== undefined) { - cost = price * amount; - } + let cost = this.safeNumber2 (trade, 'base_volume', 'base_amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'market_amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'base_fee'); + const feeCost = this.safeNumber (trade, 'base_fee'); if (feeCost !== undefined) { const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; fee = { @@ -108315,7 +106677,7 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); account['used'] = 0; result[code] = account; } @@ -108325,10 +106687,10 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -108457,10 +106819,9 @@ module.exports = class qtrade extends Exchange { side = this.safeString (parts, 0); orderType = this.safeString (parts, 1); } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'market_amount'); - let remaining = this.safeFloat (order, 'market_amount_remaining'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'market_amount'); + const remaining = this.safeNumber (order, 'market_amount_remaining'); const open = this.safeValue (order, 'open', false); const closeReason = this.safeString (order, 'close_reason'); let status = undefined; @@ -108472,58 +106833,21 @@ module.exports = class qtrade extends Exchange { status = 'closed'; } const marketId = this.safeString (order, 'market_string'); - const symbol = this.safeSymbol (marketId, market, '_'); + market = this.safeMarket (marketId, market, '_'); + const symbol = market['symbol']; const rawTrades = this.safeValue (order, 'trades', []); const parsedTrades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id, 'side': side, 'type': orderType, }); - const numTrades = parsedTrades.length; - let lastTradeTimestamp = undefined; - let feeCost = undefined; - let cost = undefined; - if (numTrades > 0) { - feeCost = 0; - cost = 0; - filled = 0; - remaining = amount; - for (let i = 0; i < parsedTrades.length; i++) { - const trade = parsedTrades[i]; - feeCost = this.sum (trade['fee']['cost'], feeCost); - lastTradeTimestamp = this.safeInteger (trade, 'timestamp'); - cost = this.sum (trade['cost'], cost); - filled = this.sum (trade['amount'], filled); - remaining = Math.max (0, remaining - trade['amount']); - } - } - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; - fee = { - 'currency': feeCurrencyCode, - 'cost': feeCost, - }; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let average = undefined; - if (filled !== undefined) { - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': orderType, 'timeInForce': undefined, @@ -108531,15 +106855,16 @@ module.exports = class qtrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, - 'fee': fee, - 'cost': cost, + 'fee': undefined, + 'fees': undefined, + 'cost': undefined, 'trades': parsedTrades, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -109008,7 +107333,7 @@ module.exports = class qtrade extends Exchange { const tagTo = tag; const cancelRequested = this.safeValue (transaction, 'cancel_requested'); const type = (cancelRequested === undefined) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); let status = this.parseTransactionStatus (this.safeString (transaction, 'status')); @@ -109152,7 +107477,7 @@ module.exports = class qtrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],123:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],120:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); @@ -109340,8 +107665,8 @@ module.exports = class rightbtc extends Exchange { return result; } - divideSafeFloat (x, key, divisor) { - const value = this.safeFloat (x, key); + divideSafeNumber (x, key, divisor) { + const value = this.safeNumber (x, key); if (value !== undefined) { return value / divisor; } @@ -109351,12 +107676,12 @@ module.exports = class rightbtc extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); - const last = this.divideSafeFloat (ticker, 'last', 1e8); - const high = this.divideSafeFloat (ticker, 'high', 1e8); - const low = this.divideSafeFloat (ticker, 'low', 1e8); - const bid = this.divideSafeFloat (ticker, 'buy', 1e8); - const ask = this.divideSafeFloat (ticker, 'sell', 1e8); - const baseVolume = this.divideSafeFloat (ticker, 'vol24h', 1e8); + const last = this.divideSafeNumber (ticker, 'last', 1e8); + const high = this.divideSafeNumber (ticker, 'high', 1e8); + const low = this.divideSafeNumber (ticker, 'low', 1e8); + const bid = this.divideSafeNumber (ticker, 'buy', 1e8); + const ask = this.divideSafeNumber (ticker, 'sell', 1e8); + const baseVolume = this.divideSafeNumber (ticker, 'vol24h', 1e8); return { 'symbol': symbol, 'timestamp': timestamp, @@ -109460,9 +107785,9 @@ module.exports = class rightbtc extends Exchange { let id = this.safeString (trade, 'tid'); id = this.safeString (trade, 'trade_id', id); const orderId = this.safeString (trade, 'order_id'); - const price = this.divideSafeFloat (trade, 'price', 1e8); - let amount = this.safeFloat (trade, 'amount'); - amount = this.safeFloat (trade, 'quantity', amount); + const price = this.divideSafeNumber (trade, 'price', 1e8); + let amount = this.safeNumber (trade, 'amount'); + amount = this.safeNumber (trade, 'quantity', amount); if (amount !== undefined) { amount = amount / 1e8; } @@ -109559,8 +107884,8 @@ module.exports = class rightbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); // https://github.com/ccxt/ccxt/issues/3873 - account['free'] = this.divideSafeFloat (balance, 'balance', 1e8); - account['used'] = this.divideSafeFloat (balance, 'frozen', 1e8); + account['free'] = this.divideSafeNumber (balance, 'balance', 1e8); + account['used'] = this.divideSafeNumber (balance, 'frozen', 1e8); result[code] = account; } return this.parseBalance (result); @@ -109649,30 +107974,18 @@ module.exports = class rightbtc extends Exchange { } else if ('transactTime' in order) { timestamp = order['transactTime']; } - let price = this.safeFloat2 (order, 'limit', 'price'); + let price = this.safeNumber2 (order, 'limit', 'price'); if (price !== undefined) { price = price / 1e8; } - const amount = this.divideSafeFloat (order, 'quantity', 1e8); - let filled = this.divideSafeFloat (order, 'filled_quantity', 1e8); - let remaining = this.divideSafeFloat (order, 'rest', 1e8); - const cost = this.divideSafeFloat (order, 'cost', 1e8); + const amount = this.divideSafeNumber (order, 'quantity', 1e8); + const filled = this.divideSafeNumber (order, 'filled_quantity', 1e8); + const remaining = this.divideSafeNumber (order, 'rest', 1e8); + const cost = this.divideSafeNumber (order, 'cost', 1e8); // lines 483-494 should be generalized into a base class method - if (amount !== undefined) { - if (remaining === undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - if (filled === undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } - } const type = 'limit'; const side = this.safeStringLower (order, 'side'); - const feeCost = this.divideSafeFloat (order, 'min_fee', 1e8); + const feeCost = this.divideSafeNumber (order, 'min_fee', 1e8); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -109680,13 +107993,13 @@ module.exports = class rightbtc extends Exchange { feeCurrency = market['quote']; } fee = { - 'rate': this.safeFloat (order, 'fee'), + 'rate': this.safeNumber (order, 'fee'), 'cost': feeCost, 'currency': feeCurrency, }; } const trades = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -109708,7 +108021,7 @@ module.exports = class rightbtc extends Exchange { 'fee': fee, 'trades': trades, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -109912,7 +108225,7 @@ module.exports = class rightbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],124:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],121:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -109920,6 +108233,7 @@ module.exports = class rightbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, BadSymbol, BadRequest, InvalidOrder, ArgumentsRequired, OrderNotFound, InsufficientFunds, DDoSProtection } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110064,12 +108378,12 @@ module.exports = class ripio extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'min_amount'), - 'price': this.safeFloat (market, 'price_tick'), + 'amount': this.safeNumber (market, 'min_amount'), + 'price': this.safeNumber (market, 'price_tick'), }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -110077,15 +108391,15 @@ module.exports = class ripio extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_value'), + 'min': this.safeNumber (market, 'min_value'), 'max': undefined, }, }; const active = this.safeValue (market, 'enabled', true); const fees = this.safeValue (market, 'fees', []); const firstFee = this.safeValue (fees, 0, {}); - const maker = this.safeFloat (firstFee, 'maker_fee', 0.0); - const taker = this.safeFloat (firstFee, 'taker_fee', 0.0); + const maker = this.safeNumber (firstFee, 'maker_fee', 0.0); + const taker = this.safeNumber (firstFee, 'taker_fee', 0.0); result.push ({ 'id': id, 'symbol': symbol, @@ -110192,18 +108506,18 @@ module.exports = class ripio extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); const marketId = this.safeString (ticker, 'pair'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const average = this.safeFloat (ticker, 'avg'); + const last = this.safeNumber (ticker, 'last_price'); + const average = this.safeNumber (ticker, 'avg'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bid_volume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'ask_volume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bid_volume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'ask_volume'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -110345,15 +108659,14 @@ module.exports = class ripio extends Exchange { if (side !== undefined) { side = side.toLowerCase (); } - const price = this.safeFloat2 (trade, 'price', 'match_price'); - const amount = this.safeFloat2 (trade, 'amount', 'exchanged'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString2 (trade, 'price', 'match_price'); + const amountString = this.safeString2 (trade, 'amount', 'exchanged'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'pair'); market = this.safeMarket (marketId, market); - const feeCost = this.safeFloat (trade, takerOrMaker + '_fee'); + const feeCost = this.safeNumber (trade, takerOrMaker + '_fee'); const orderId = this.safeString (trade, takerOrMaker); let fee = undefined; if (feeCost !== undefined) { @@ -110427,11 +108740,11 @@ module.exports = class ripio extends Exchange { const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -110690,16 +109003,16 @@ module.exports = class ripio extends Exchange { // } // const id = this.safeString (order, 'order_id'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat (order, 'notional'); + const amount = this.safeNumber (order, 'amount'); + let cost = this.safeNumber (order, 'notional'); const type = this.safeStringLower (order, 'order_type'); const priceField = (type === 'market') ? 'fill_price' : 'limit_price'; - const price = this.safeFloat (order, priceField); + const price = this.safeNumber (order, priceField); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeTimestamp (order, 'created_at'); let average = this.safeValue (order, 'fill_price'); - let filled = this.safeFloat (order, 'filled'); + let filled = this.safeNumber (order, 'filled'); let remaining = undefined; const fills = this.safeValue (order, 'fills'); let trades = undefined; @@ -110734,7 +109047,7 @@ module.exports = class ripio extends Exchange { } const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); return { 'id': id, 'clientOrderId': undefined, @@ -110860,13 +109173,14 @@ module.exports = class ripio extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],125:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],122:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110977,14 +109291,14 @@ module.exports = class southxchange extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const deposited = this.safeFloat (balance, 'Deposited'); - const unconfirmed = this.safeFloat (balance, 'Unconfirmed'); + const deposited = this.safeString (balance, 'Deposited'); + const unconfirmed = this.safeString (balance, 'Unconfirmed'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'Available'); - account['total'] = this.sum (deposited, unconfirmed); + account['free'] = this.safeString (balance, 'Available'); + account['total'] = Precise.stringAdd (deposited, unconfirmed); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -111002,16 +109316,16 @@ module.exports = class southxchange extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'Last'); + const last = this.safeNumber (ticker, 'Last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'Bid'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -111019,9 +109333,9 @@ module.exports = class southxchange extends Exchange { 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'Variation24Hr'), + 'percentage': this.safeNumber (ticker, 'Variation24Hr'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume24Hr'), + 'baseVolume': this.safeNumber (ticker, 'Volume24Hr'), 'quoteVolume': undefined, 'info': ticker, }; @@ -111055,14 +109369,11 @@ module.exports = class southxchange extends Exchange { parseTrade (trade, market) { const timestamp = this.safeTimestamp (trade, 'At'); - const price = this.safeFloat (trade, 'Price'); - const amount = this.safeFloat (trade, 'Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'Price'); + const amountString = this.safeString (trade, 'Amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'Type'); let symbol = undefined; if (market !== undefined) { @@ -111103,21 +109414,13 @@ module.exports = class southxchange extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const timestamp = undefined; - const price = this.safeFloat (order, 'LimitPrice'); - const amount = this.safeFloat (order, 'OriginalAmount'); - const remaining = this.safeFloat (order, 'Amount'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - cost = price * amount; - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'LimitPrice'); + const amount = this.safeNumber (order, 'OriginalAmount'); + const remaining = this.safeNumber (order, 'Amount'); const type = 'limit'; const side = this.safeStringLower (order, 'Type'); const id = this.safeString (order, 'Code'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -111132,15 +109435,14 @@ module.exports = class southxchange extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'filled': filled, + 'cost': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -111273,8 +109575,8 @@ module.exports = class southxchange extends Exchange { const type = this.safeString (item, 'Type'); const ledgerEntryType = this.parseLedgerEntryType (type); const code = this.safeCurrencyCode (this.safeString (item, 'CurrencyCode'), currency); - let amount = this.safeFloat (item, 'Amount'); - const after = this.safeFloat (item, 'TotalBalance'); + let amount = this.safeNumber (item, 'Amount'); + const after = this.safeNumber (item, 'TotalBalance'); let before = undefined; if (amount !== undefined) { if (after !== undefined) { @@ -111445,7 +109747,7 @@ module.exports = class southxchange extends Exchange { // } // const id = this.safeString (transaction, 'MovementId'); - const amount = this.safeFloat (transaction, 'Amount'); + const amount = this.safeNumber (transaction, 'Amount'); const address = this.safeString (transaction, 'Address'); const addressTo = address; const addressFrom = undefined; @@ -111560,7 +109862,7 @@ module.exports = class southxchange extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],126:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],123:[function(require,module,exports){ (function (module, exports) { 'use strict'; @@ -115088,7 +113390,7 @@ module.exports = class southxchange extends Exchange { }; })(typeof module === 'undefined' || module, this); -},{"buffer":188}],127:[function(require,module,exports){ +},{"buffer":184}],124:[function(require,module,exports){ ;(function (root, factory) { if (typeof exports === "object") { // CommonJS @@ -121077,7 +119379,7 @@ module.exports = class southxchange extends Exchange { return CryptoJS; })); -},{}],128:[function(require,module,exports){ +},{}],125:[function(require,module,exports){ 'use strict'; var elliptic = exports; @@ -121101,7 +119403,7 @@ elliptic.curves = require('./elliptic/curves'); elliptic.ec = require('./elliptic/ec'); elliptic.eddsa = require('./elliptic/eddsa'); -},{"./elliptic/curve":131,"./elliptic/curves":134,"./elliptic/ec":135,"./elliptic/eddsa":138,"./elliptic/utils":142}],129:[function(require,module,exports){ +},{"./elliptic/curve":128,"./elliptic/curves":131,"./elliptic/ec":132,"./elliptic/eddsa":135,"./elliptic/utils":139}],126:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -121478,7 +119780,7 @@ BasePoint.prototype.dblp = function dblp(k) { return r; }; -},{"../../../../BN/bn":126,"../../elliptic":128}],130:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],127:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -121913,7 +120215,7 @@ Point.prototype.eqXToP = function eqXToP(x) { Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],131:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],128:[function(require,module,exports){ 'use strict'; var curve = exports; @@ -121923,7 +120225,7 @@ curve.short = require('./short'); curve.mont = require('./mont'); curve.edwards = require('./edwards'); -},{"./base":129,"./edwards":130,"./mont":132,"./short":133}],132:[function(require,module,exports){ +},{"./base":126,"./edwards":127,"./mont":129,"./short":130}],129:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -122105,7 +120407,7 @@ Point.prototype.getX = function getX() { return this.x.fromRed(); }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],133:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],130:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -123045,7 +121347,7 @@ JPoint.prototype.isInfinity = function isInfinity() { return this.z.cmpn(0) === 0; }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],134:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],131:[function(require,module,exports){ 'use strict'; var curves = exports; @@ -123251,7 +121553,7 @@ defineCurve('secp256k1', { ] }); -},{"../elliptic":128,"./precomputed/secp256k1":141}],135:[function(require,module,exports){ +},{"../elliptic":125,"./precomputed/secp256k1":138}],132:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123493,7 +121795,7 @@ EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { throw new Error('Unable to find valid recovery factor'); }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../../hmac-drbg/hmac-drbg":143,"./key":136,"./signature":137}],136:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../../hmac-drbg/hmac-drbg":140,"./key":133,"./signature":134}],133:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123614,7 +121916,7 @@ KeyPair.prototype.inspect = function inspect() { ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; }; -},{"../../../../BN/bn":126,"../../elliptic":128}],137:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],134:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123640,7 +121942,7 @@ function Signature(options, enc) { } module.exports = Signature; -},{"../../../../BN/bn":126,"../../elliptic":128}],138:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],135:[function(require,module,exports){ 'use strict'; var curves = require('../curves'); @@ -123787,7 +122089,7 @@ EDDSA.prototype.isPoint = function isPoint(val) { return val instanceof this.pointClass; }; -},{"../../../../../base/functions/encode":11,"../../../../BN/bn.js":126,"../../../../crypto-js/crypto-js":127,"../curves":134,"../utils":142,"./key":139,"./signature":140}],139:[function(require,module,exports){ +},{"../../../../../base/functions/encode":12,"../../../../BN/bn.js":123,"../../../../crypto-js/crypto-js":124,"../curves":131,"../utils":139,"./key":136,"./signature":137}],136:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -123889,7 +122191,7 @@ KeyPair.prototype.getPublic = function getPublic(enc) { module.exports = KeyPair; -},{"../utils":142}],140:[function(require,module,exports){ +},{"../utils":139}],137:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123956,7 +122258,7 @@ Signature.prototype.toHex = function toHex() { module.exports = Signature; -},{"../../../../BN/bn":126,"../utils":142}],141:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../utils":139}],138:[function(require,module,exports){ module.exports = { doubles: { step: 4, @@ -124738,7 +123040,7 @@ module.exports = { } }; -},{}],142:[function(require,module,exports){ +},{}],139:[function(require,module,exports){ 'use strict'; var utils = exports; @@ -124954,7 +123256,7 @@ utils.encode = function encode(arr, enc) { return arr; }; -},{"../../../BN/bn":126}],143:[function(require,module,exports){ +},{"../../../BN/bn":123}],140:[function(require,module,exports){ 'use strict'; var CryptoJS = require('../../../crypto-js/crypto-js'); @@ -125070,7 +123372,7 @@ HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { return utils.wordArrayToBuffer(res); }; -},{"../../../../base/functions/encode":11,"../../../crypto-js/crypto-js":127,"../elliptic/utils":142}],144:[function(require,module,exports){ +},{"../../../../base/functions/encode":12,"../../../crypto-js/crypto-js":124,"../elliptic/utils":139}],141:[function(require,module,exports){ 'use strict'; var fetch = require('../node-fetch/index'); @@ -125111,7 +123413,7 @@ module.exports = function (context) { }; }; -},{"../node-fetch/index":145}],145:[function(require,module,exports){ +},{"../node-fetch/index":142}],142:[function(require,module,exports){ (function (global,Buffer){ 'use strict'; @@ -126679,7 +124981,7 @@ exports.Response = Response; exports.FetchError = FetchError; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"buffer":188,"http":230,"https":193,"stream":229,"url":236,"zlib":187}],146:[function(require,module,exports){ +},{"buffer":184,"http":226,"https":189,"stream":225,"url":232,"zlib":183}],143:[function(require,module,exports){ (function (Buffer){ /*! * RSA library for Node.js @@ -126906,7 +125208,7 @@ module.exports = (function () { })(); }).call(this,require("buffer").Buffer) -},{"./formats/formats.js":153,"./libs/rsa.js":157,"./schemes/schemes.js":159,"./utils":160,"buffer":188}],147:[function(require,module,exports){ +},{"./formats/formats.js":150,"./libs/rsa.js":154,"./schemes/schemes.js":156,"./utils":157,"buffer":184}],144:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. @@ -126921,7 +125223,7 @@ module.exports = { }; -},{}],148:[function(require,module,exports){ +},{}],145:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. var errors = require('./errors'); @@ -126944,7 +125246,7 @@ for (var e in errors) { module.exports[e] = errors[e]; } -},{"./errors":147,"./reader":149,"./types":150}],149:[function(require,module,exports){ +},{"./errors":144,"./reader":146,"./types":147}],146:[function(require,module,exports){ (function (Buffer){ // Copyright 2011 Mark Cavage All rights reserved. @@ -127210,7 +125512,7 @@ Reader.prototype._readTag = function (tag) { module.exports = Reader; }).call(this,require("buffer").Buffer) -},{"./errors":147,"./types":150,"assert":183,"buffer":188}],150:[function(require,module,exports){ +},{"./errors":144,"./types":147,"assert":179,"buffer":184}],147:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. @@ -127248,7 +125550,7 @@ module.exports = { Context: 128 }; -},{}],151:[function(require,module,exports){ +},{}],148:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. // If you have no idea what ASN.1 or BER is, see this: @@ -127267,7 +125569,7 @@ module.exports = { BerReader: Ber.Reader, }; -},{"./ber/index":148}],152:[function(require,module,exports){ +},{"./ber/index":145}],149:[function(require,module,exports){ var _ = require('../utils')._; var utils = require('../utils'); @@ -127340,7 +125642,7 @@ module.exports = { } }; -},{"../utils":160}],153:[function(require,module,exports){ +},{"../utils":157}],150:[function(require,module,exports){ var _ = require('../utils')._; module.exports = { @@ -127373,7 +125675,7 @@ module.exports = { }, }; -},{"../utils":160,"./components":152,"./pkcs1":154,"./pkcs8":155}],154:[function(require,module,exports){ +},{"../utils":157,"./components":149,"./pkcs1":151,"./pkcs8":152}],151:[function(require,module,exports){ (function (Buffer){ var ber = require('../asn1/index').Ber; var _ = require('../utils')._; @@ -127525,7 +125827,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"../asn1/index":151,"../utils":160,"buffer":188}],155:[function(require,module,exports){ +},{"../asn1/index":148,"../utils":157,"buffer":184}],152:[function(require,module,exports){ (function (Buffer){ var ber = require('../asn1/index').Ber; var _ = require('../utils')._; @@ -127716,7 +126018,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"../asn1/index":151,"../utils":160,"buffer":188}],156:[function(require,module,exports){ +},{"../asn1/index":148,"../utils":157,"buffer":184}],153:[function(require,module,exports){ (function (Buffer){ /* * Basic JavaScript BN library - subset useful for RSA encryption. @@ -128972,7 +127274,7 @@ BigInteger.prototype.square = bnSquare; module.exports = BigInteger; }).call(this,require("buffer").Buffer) -},{"../utils":160,"buffer":188}],157:[function(require,module,exports){ +},{"../utils":157,"buffer":184}],154:[function(require,module,exports){ /* * RSA Encryption / Decryption with PKCS1 v2 Padding. * @@ -129121,7 +127423,7 @@ module.exports.Key = (function () { })(); -},{"../schemes/schemes.js":159,"../utils":160,"../utils.js":160,"./jsbn.js":156}],158:[function(require,module,exports){ +},{"../schemes/schemes.js":156,"../utils":157,"../utils.js":157,"./jsbn.js":153}],155:[function(require,module,exports){ (function (Buffer){ /** * PKCS1 padding and signature scheme @@ -129301,7 +127603,7 @@ function wordArrayToBuffer(wordArray) { } }).call(this,require("buffer").Buffer) -},{"../../crypto-js/crypto-js":127,"../libs/jsbn":156,"buffer":188,"constants":190}],159:[function(require,module,exports){ +},{"../../crypto-js/crypto-js":124,"../libs/jsbn":153,"buffer":184,"constants":186}],156:[function(require,module,exports){ module.exports = { pkcs1: require('./pkcs1'), @@ -129324,7 +127626,7 @@ module.exports = { } }; -},{"./pkcs1":158}],160:[function(require,module,exports){ +},{"./pkcs1":155}],157:[function(require,module,exports){ /* * Utils functions * @@ -129424,7 +127726,7 @@ module.exports.trimSurroundingText = function (data, opening, closing) { return data.substring(trimStartIndex, trimEndIndex); } -},{}],161:[function(require,module,exports){ +},{}],158:[function(require,module,exports){ 'use strict'; var replace = String.prototype.replace; @@ -129444,7 +127746,7 @@ module.exports = { RFC3986: 'RFC3986' }; -},{}],162:[function(require,module,exports){ +},{}],159:[function(require,module,exports){ 'use strict'; var stringify = require('./stringify'); @@ -129457,7 +127759,7 @@ module.exports = { stringify: stringify }; -},{"./formats":161,"./parse":163,"./stringify":164}],163:[function(require,module,exports){ +},{"./formats":158,"./parse":160,"./stringify":161}],160:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); @@ -129701,7 +128003,7 @@ module.exports = function (str, opts) { return utils.compact(obj); }; -},{"./utils":165}],164:[function(require,module,exports){ +},{"./utils":162}],161:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); @@ -129972,7 +128274,7 @@ module.exports = function (object, opts) { return joined.length > 0 ? prefix + joined : ''; }; -},{"./formats":161,"./utils":165}],165:[function(require,module,exports){ +},{"./formats":158,"./utils":162}],162:[function(require,module,exports){ 'use strict'; var has = Object.prototype.hasOwnProperty; @@ -130204,13 +128506,14 @@ module.exports = { merge: merge }; -},{}],166:[function(require,module,exports){ +},{}],163:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, OrderNotFound, PermissionDenied, BadRequest, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -130393,6 +128696,7 @@ module.exports = class stex extends Exchange { 'BITSW': 'BITS', 'BHD': 'Bithold', 'BTH': 'Bithereum', + 'MPH': 'Chasyr Token', 'SBTC': 'SBTCT', // SiamBitcoin }, 'options': { @@ -130456,7 +128760,7 @@ module.exports = class stex extends Exchange { // differentiated fees for each particular method const code = this.safeCurrencyCode (this.safeString (currency, 'code')); const precision = this.safeInteger (currency, 'precision'); - const fee = this.safeFloat (currency, 'withdrawal_fee_const'); // todo: redesign + const fee = this.safeNumber (currency, 'withdrawal_fee_const'); // todo: redesign const active = this.safeValue (currency, 'active', true); result[code] = { 'id': id, @@ -130473,11 +128777,11 @@ module.exports = class stex extends Exchange { 'price': { 'min': Math.pow (10, -precision), 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (currency, 'minimum_deposit_amount'), + 'min': this.safeNumber (currency, 'minimum_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal_amount'), + 'min': this.safeNumber (currency, 'minimum_withdrawal_amount'), 'max': undefined, }, }, @@ -130538,11 +128842,11 @@ module.exports = class stex extends Exchange { 'price': this.safeInteger (market, 'market_precision'), }; const active = this.safeValue (market, 'active'); - const minBuyPrice = this.safeFloat (market, 'min_buy_price'); - const minSellPrice = this.safeFloat (market, 'min_sell_price'); + const minBuyPrice = this.safeNumber (market, 'min_buy_price'); + const minSellPrice = this.safeNumber (market, 'min_sell_price'); const minPrice = Math.max (minBuyPrice, minSellPrice); - const buyFee = this.safeFloat (market, 'buy_fee_percent') / 100; - const sellFee = this.safeFloat (market, 'sell_fee_percent') / 100; + const buyFee = this.safeNumber (market, 'buy_fee_percent') / 100; + const sellFee = this.safeNumber (market, 'sell_fee_percent') / 100; const fee = Math.max (buyFee, sellFee); result.push ({ 'id': id, @@ -130561,7 +128865,7 @@ module.exports = class stex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_order_amount'), + 'min': this.safeNumber (market, 'min_order_amount'), 'max': undefined, }, 'price': { 'min': minPrice, 'max': undefined }, @@ -130725,8 +129029,8 @@ module.exports = class stex extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString2 (ticker, 'id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -130739,11 +129043,11 @@ module.exports = class stex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -130753,20 +129057,12 @@ module.exports = class stex extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volumeQuote'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volumeQuote'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker (params); @@ -130832,11 +129128,11 @@ module.exports = class stex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -130911,12 +129207,11 @@ module.exports = class stex extends Exchange { // const id = this.safeString (trade, 'id'); const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; @@ -131029,11 +129324,11 @@ module.exports = class stex extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'currency_id')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen_balance'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -131092,9 +129387,9 @@ module.exports = class stex extends Exchange { const marketId = this.safeString2 (order, 'currency_pair_id', 'currency_pair_name'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (order, 'timestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'initial_amount'); - const filled = this.safeFloat (order, 'processed_amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'initial_amount'); + const filled = this.safeNumber (order, 'processed_amount'); let remaining = undefined; let cost = undefined; if (filled !== undefined) { @@ -131124,7 +129419,7 @@ module.exports = class stex extends Exchange { 'order': id, }); } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); const result = { 'info': order, 'id': id, @@ -131155,7 +129450,7 @@ module.exports = class stex extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'amount'); + const feeCost = this.safeNumber (fees[i], 'amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -131739,13 +130034,13 @@ module.exports = class stex extends Exchange { code = currency['code']; } const type = ('deposit_status_id' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeStringLower (transaction, 'status')); const timestamp = this.safeTimestamp2 (transaction, 'timestamp', 'created_ts'); const updated = this.safeTimestamp (transaction, 'updated_ts'); const txid = this.safeString (transaction, 'txid'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'fee_currency_id', 'deposit_fee_currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -131981,8 +130276,8 @@ module.exports = class stex extends Exchange { for (let i = 0; i < data.length; i++) { const id = this.safeString (data[i], 'id'); const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (data[i], 'withdrawal_fee_const'); - depositFees[code] = this.safeFloat (data[i], 'deposit_fee_const'); + withdrawFees[code] = this.safeNumber (data[i], 'withdrawal_fee_const'); + depositFees[code] = this.safeNumber (data[i], 'deposit_fee_const'); } return { 'withdraw': withdrawFees, @@ -132011,7 +130306,7 @@ module.exports = class stex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],167:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],164:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -132045,13 +130340,14 @@ module.exports = class surbitcoin extends foxbit { } }; -},{"./foxbit.js":87}],168:[function(require,module,exports){ +},{"./foxbit.js":85}],165:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -132219,8 +130515,8 @@ module.exports = class therock extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const buy_fee = this.safeFloat (market, 'buy_fee'); - const sell_fee = this.safeFloat (market, 'sell_fee'); + const buy_fee = this.safeNumber (market, 'buy_fee'); + const sell_fee = this.safeNumber (market, 'sell_fee'); let taker = Math.max (buy_fee, sell_fee); taker = taker / 100; const maker = taker; @@ -132241,11 +130537,11 @@ module.exports = class therock extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_quantity_offer'), + 'min': this.safeNumber (market, 'minimum_quantity_offer'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'minimum_price_offer'), + 'min': this.safeNumber (market, 'minimum_price_offer'), 'max': undefined, }, 'cost': { @@ -132269,11 +130565,11 @@ module.exports = class therock extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'trading_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'trading_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -132292,27 +130588,27 @@ module.exports = class therock extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'close'), // previous day close, if any + 'previousClose': this.safeNumber (ticker, 'close'), // previous day close, if any 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_traded'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume_traded'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -132387,14 +130683,11 @@ module.exports = class therock extends Exchange { const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; let feeCost = undefined; const transactions = this.safeValue (trade, 'transactions', []); @@ -132404,7 +130697,7 @@ module.exports = class therock extends Exchange { if (feeCost === undefined) { feeCost = 0; } - feeCost = this.sum (feeCost, this.safeFloat (feeTransactions[i], 'price')); + feeCost = this.sum (feeCost, this.safeNumber (feeTransactions[i], 'price')); } if (feeCost !== undefined) { fee = { @@ -132559,7 +130852,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (item, 'price'); + const amount = this.safeNumber (item, 'price'); const timestamp = this.parse8601 (this.safeString (item, 'date')); const status = 'ok'; return { @@ -132791,7 +131084,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'price'); + const amount = this.safeNumber (transaction, 'price'); const timestamp = this.parse8601 (this.safeString (transaction, 'date')); const status = 'ok'; // todo parse tags @@ -132966,15 +131259,15 @@ module.exports = class therock extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'date')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'amount_unfilled'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amount_unfilled'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let trades = this.safeValue (order, 'trades'); let cost = undefined; let average = undefined; @@ -133001,7 +131294,7 @@ module.exports = class therock extends Exchange { cost = 0; } } - const stopPrice = this.safeFloat (order, 'conditional_price'); + const stopPrice = this.safeNumber (order, 'conditional_price'); return { 'id': id, 'clientOrderId': undefined, @@ -133279,13 +131572,14 @@ module.exports = class therock extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],169:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],166:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, OrderNotFound, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -133464,11 +131758,11 @@ module.exports = class tidebit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -133493,15 +131787,15 @@ module.exports = class tidebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'ask': this.safeFloat (ticker, 'sell'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'ask': this.safeNumber (ticker, 'sell'), 'bidVolume': undefined, 'askVolume': undefined, 'vwap': undefined, @@ -133512,7 +131806,7 @@ module.exports = class tidebit extends Exchange { 'percentage': undefined, 'previousClose': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -133546,9 +131840,14 @@ module.exports = class tidebit extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -133593,11 +131892,11 @@ module.exports = class tidebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -133683,18 +131982,12 @@ module.exports = class tidebit extends Exchange { const id = this.safeString (order, 'id'); const type = this.safeString (order, 'ord_type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const filled = this.safeFloat (order, 'executed_volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - let cost = undefined; - if (price !== undefined) { - if (filled !== undefined) { - cost = price * filled; - } - } - const average = this.safeFloat (order, 'avg_price'); - return { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const filled = this.safeNumber (order, 'executed_volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -133711,12 +132004,12 @@ module.exports = class tidebit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': average, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -133824,11 +132117,12 @@ module.exports = class tidebit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],170:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],167:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class tidex extends Exchange { describe () { @@ -133910,6 +132204,7 @@ module.exports = class tidex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.1 / 100, @@ -133954,19 +132249,48 @@ module.exports = class tidex extends Exchange { async fetchCurrencies (params = {}) { const response = await this.webGetCurrency (params); + // + // [ + // { + // "id":2, + // "symbol":"BTC", + // "type":2, + // "name":"Bitcoin", + // "amountPoint":8, + // "depositEnable":true, + // "depositMinAmount":0.0005, + // "withdrawEnable":true, + // "withdrawFee":0.0004, + // "withdrawMinAmount":0.0005, + // "settings":{ + // "Blockchain":"https://blockchair.com/bitcoin/", + // "TxUrl":"https://blockchair.com/bitcoin/transaction/{0}", + // "AddrUrl":"https://blockchair.com/bitcoin/address/{0}", + // "ConfirmationCount":3, + // "NeedMemo":false + // }, + // "visible":true, + // "isDelisted":false + // } + // ] + // const result = {}; for (let i = 0; i < response.length; i++) { const currency = response[i]; const id = this.safeString (currency, 'symbol'); - const precision = currency['amountPoint']; + const precision = this.safeInteger (currency, 'amountPoint'); const code = this.safeCurrencyCode (id); - let active = currency['visible'] === true; - const canWithdraw = currency['withdrawEnable'] === true; - const canDeposit = currency['depositEnable'] === true; + const visible = this.safeValue (currency, 'visible'); + let active = visible === true; + const withdrawEnable = this.safeValue (currency, 'withdrawEnable'); + const depositEnable = this.safeValue (currency, 'depositEnable'); + const canWithdraw = withdrawEnable === true; + const canDeposit = depositEnable === true; if (!canWithdraw || !canDeposit) { active = false; } const name = this.safeString (currency, 'name'); + const fee = this.safeNumber (currency, 'withdrawFee'); result[code] = { 'id': id, 'code': code, @@ -133976,7 +132300,7 @@ module.exports = class tidex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': currency['withdrawFee'], + 'fee': fee, }, 'deposit': { 'active': canDeposit, @@ -133997,11 +132321,11 @@ module.exports = class tidex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawMinAmount'), + 'min': this.safeNumber (currency, 'withdrawMinAmount'), 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'depositMinAmount'), + 'min': this.safeNumber (currency, 'depositMinAmount'), 'max': undefined, }, }, @@ -134011,26 +132335,25 @@ module.exports = class tidex extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615861869, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":3.0, + // "min_amount":0.001, + // "max_amount":1000000.0, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.1, + // }, + // }, + // } + // const markets = response['pairs']; const keys = Object.keys (markets); const result = []; @@ -134047,19 +132370,20 @@ module.exports = class tidex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }, }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -134068,7 +132392,7 @@ module.exports = class tidex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -134089,11 +132413,11 @@ module.exports = class tidex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (funds, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'value'); - account['used'] = this.safeFloat (balance, 'inOrders'); + account['free'] = this.safeString (balance, 'value'); + account['used'] = this.safeString (balance, 'inOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -134165,16 +132489,16 @@ module.exports = class tidex extends Exchange { timestamp = undefined; } } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -134183,9 +132507,9 @@ module.exports = class tidex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -134233,16 +132557,19 @@ module.exports = class tidex extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const orderId = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = 'limit'; // all trades are still limit trades let takerOrMaker = undefined; let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -134261,12 +132588,6 @@ module.exports = class tidex extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': orderId, @@ -134322,17 +132643,18 @@ module.exports = class tidex extends Exchange { let status = 'open'; let filled = 0.0; let remaining = amount; - if ('return' in response) { - id = this.safeString (response['return'], 'order_id'); + const returnResult = this.safeValue (response, 'return'); + if (returnResult !== undefined) { + id = this.safeString (returnResult, 'order_id'); if (id === '0') { - id = this.safeString (response['return'], 'init_order_id'); + id = this.safeString (returnResult, 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (returnResult, 'received', filled); + remaining = this.safeNumber (returnResult, 'remains', amount); } const timestamp = this.milliseconds (); - return { + return this.safeOrder ({ 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -134342,7 +132664,7 @@ module.exports = class tidex extends Exchange { 'type': type, 'side': side, 'price': price, - 'cost': price * filled, + 'cost': undefined, 'amount': amount, 'remaining': remaining, 'filled': filled, @@ -134352,7 +132674,7 @@ module.exports = class tidex extends Exchange { 'clientOrderId': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -134381,23 +132703,15 @@ module.exports = class tidex extends Exchange { const symbol = this.safeSymbol (marketId, market); let remaining = undefined; let amount = undefined; - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; + const price = this.safeNumber (order, 'rate'); if ('start_amount' in order) { - amount = this.safeFloat (order, 'start_amount'); - remaining = this.safeFloat (order, 'amount'); + amount = this.safeNumber (order, 'start_amount'); + remaining = this.safeNumber (order, 'amount'); } else { - remaining = this.safeFloat (order, 'amount'); - } - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } + remaining = this.safeNumber (order, 'amount'); } const fee = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -134411,15 +132725,15 @@ module.exports = class tidex extends Exchange { 'side': this.safeString (order, 'type'), 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -134609,11 +132923,12 @@ module.exports = class tidex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],171:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],168:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, PermissionDenied, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, RateLimitExceeded, NotSupported, BadRequest, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class timex extends Exchange { describe () { @@ -135062,11 +133377,11 @@ module.exports = class timex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'totalBalance'); - account['used'] = this.safeFloat (balance, 'lockedBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + account['used'] = this.safeString (balance, 'lockedBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -135427,7 +133742,7 @@ module.exports = class timex extends Exchange { const result = this.safeValue (response, 0, {}); return { 'info': response, - 'maker': this.safeFloat (result, 'fee'), + 'maker': this.safeNumber (result, 'fee'), 'taker': undefined, }; } @@ -135464,18 +133779,18 @@ module.exports = class timex extends Exchange { 'amount': this.precisionFromString (this.safeString (market, 'quantityIncrement')), 'price': this.precisionFromString (this.safeString (market, 'tickSize')), }; - const amountIncrement = this.safeFloat (market, 'quantityIncrement'); - const minBase = this.safeFloat (market, 'baseMinSize'); + const amountIncrement = this.safeNumber (market, 'quantityIncrement'); + const minBase = this.safeNumber (market, 'baseMinSize'); const minAmount = Math.max (amountIncrement, minBase); - const priceIncrement = this.safeFloat (market, 'tickSize'); - const minCost = this.safeFloat (market, 'quoteMinSize'); + const priceIncrement = this.safeNumber (market, 'tickSize'); + const minCost = this.safeNumber (market, 'quoteMinSize'); const limits = { 'amount': { 'min': minAmount, 'max': undefined }, 'price': { 'min': priceIncrement, 'max': undefined }, 'cost': { 'min': Math.max (minCost, minAmount * priceIncrement), 'max': undefined }, }; - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); return { 'id': id, 'symbol': symbol, @@ -135536,7 +133851,7 @@ module.exports = class timex extends Exchange { const name = this.safeString (currency, 'name'); const precision = this.safeInteger (currency, 'decimals'); const active = this.safeValue (currency, 'active'); - // const fee = this.safeFloat (currency, 'withdrawalFee'); + // const fee = this.safeNumber (currency, 'withdrawalFee'); const feeString = this.safeString (currency, 'withdrawalFee'); const tradeDecimals = this.safeInteger (currency, 'tradeDecimals'); let fee = undefined; @@ -135573,14 +133888,6 @@ module.exports = class timex extends Exchange { }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // // { @@ -135600,8 +133907,8 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '/'); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -135617,11 +133924,11 @@ module.exports = class timex extends Exchange { 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -135631,8 +133938,8 @@ module.exports = class timex extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'volumeQuote'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volumeQuote'), }; } @@ -135651,23 +133958,27 @@ module.exports = class timex extends Exchange { // fetchMyTrades, fetchOrder (private) // // { - // "fee": "0.3", - // "id": 100, - // "makerOrTaker": "MAKER", - // "makerOrderId": "string", - // "price": "0.017", - // "quantity": "0.3", + // "id": "7613414", + // "makerOrderId": "0x8420af060722f560098f786a2894d4358079b6ea5d14b395969ed77bc87a623a", + // "takerOrderId": "0x1235ef158a361815b54c9988b6241c85aedcbc1fe81caf8df8587d5ab0373d1a", + // "symbol": "LTCUSDT", // "side": "BUY", - // "symbol": "TIMEETH", - // "takerOrderId": "string", - // "timestamp": "2019-12-08T04:54:11.171Z" - // } + // "quantity": "0.2", + // "fee": "0.22685", + // "feeToken": "USDT", + // "price": "226.85", + // "makerOrTaker": "TAKER", + // "timestamp": "2021-04-09T15:39:45.608" + // } // const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeStringLower2 (trade, 'direction', 'side'); const takerOrMaker = this.safeStringLower (trade, 'makerOrTaker'); @@ -135676,18 +133987,14 @@ module.exports = class timex extends Exchange { orderId = this.safeString (trade, takerOrMaker + 'OrderId'); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); + const feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'feeToken')); if (feeCost !== undefined) { - const feeCurrency = (market === undefined) ? undefined : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrency, }; } - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = this.costToPrecision (symbol, amount * price); - } return { 'info': trade, 'id': id, @@ -135719,11 +134026,11 @@ module.exports = class timex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -135754,14 +134061,12 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'filledQuantity'); - const canceledQuantity = this.safeFloat (order, 'cancelledQuantity'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'filledQuantity'); + const canceledQuantity = this.safeNumber (order, 'cancelledQuantity'); let status = undefined; if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0.0); if (filled >= amount) { status = 'closed'; } else if ((canceledQuantity !== undefined) && (canceledQuantity > 0)) { @@ -135770,30 +134075,19 @@ module.exports = class timex extends Exchange { status = 'open'; } } - const cost = parseFloat (this.costToPrecision (symbol, price * filled)); - const fee = undefined; - let lastTradeTimestamp = undefined; - let trades = undefined; - const rawTrades = this.safeValue (order, 'trades'); - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'order': id, - }); - } - if (trades !== undefined) { - const numTrades = trades.length; - if (numTrades > 0) { - lastTradeTimestamp = trades[numTrades - 1]['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'order': id, + 'type': type, + }); const clientOrderId = this.safeString (order, 'clientOrderId'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': undefined, @@ -135802,14 +134096,14 @@ module.exports = class timex extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { @@ -135850,13 +134144,14 @@ module.exports = class timex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],172:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],169:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, PermissionDenied, AddressPending } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -136082,9 +134377,9 @@ module.exports = class upbit extends Exchange { } else if ((locked !== undefined) && locked) { active = false; } - const maxOnetimeWithdrawal = this.safeFloat (withdrawLimits, 'onetime'); - const maxDailyWithdrawal = this.safeFloat (withdrawLimits, 'daily', maxOnetimeWithdrawal); - const remainingDailyWithdrawal = this.safeFloat (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); + const maxOnetimeWithdrawal = this.safeNumber (withdrawLimits, 'onetime'); + const maxDailyWithdrawal = this.safeNumber (withdrawLimits, 'daily', maxOnetimeWithdrawal); + const remainingDailyWithdrawal = this.safeNumber (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); let maxWithdrawLimit = undefined; if (remainingDailyWithdrawal > 0) { maxWithdrawLimit = remainingDailyWithdrawal; @@ -136100,11 +134395,11 @@ module.exports = class upbit extends Exchange { 'code': code, 'name': code, 'active': active, - 'fee': this.safeFloat (currencyInfo, 'withdraw_fee'), + 'fee': this.safeNumber (currencyInfo, 'withdraw_fee'), 'precision': precision, 'limits': { 'withdraw': { - 'min': this.safeFloat (withdrawLimits, 'minimum'), + 'min': this.safeNumber (withdrawLimits, 'minimum'), 'max': maxWithdrawLimit, }, }, @@ -136167,8 +134462,8 @@ module.exports = class upbit extends Exchange { }; const state = this.safeString (marketInfo, 'state'); const active = (state === 'active'); - const bidFee = this.safeFloat (response, 'bid_fee'); - const askFee = this.safeFloat (response, 'ask_fee'); + const bidFee = this.safeNumber (response, 'bid_fee'); + const askFee = this.safeNumber (response, 'ask_fee'); const fee = Math.max (bidFee, askFee); return { 'info': response, @@ -136184,7 +134479,7 @@ module.exports = class upbit extends Exchange { 'taker': fee, 'limits': { 'amount': { - 'min': this.safeFloat (ask, 'min_total'), + 'min': this.safeNumber (ask, 'min_total'), 'max': undefined, }, 'price': { @@ -136192,8 +134487,8 @@ module.exports = class upbit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (bid, 'min_total'), - 'max': this.safeFloat (marketInfo, 'max_total'), + 'min': this.safeNumber (bid, 'min_total'), + 'max': this.safeNumber (marketInfo, 'max_total'), }, }, }; @@ -136232,8 +134527,8 @@ module.exports = class upbit extends Exchange { 'price': 8, }; const active = true; - const makerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); - const takerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); + const makerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); + const takerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); result.push ({ 'id': id, 'symbol': symbol, @@ -136286,11 +134581,11 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { @@ -136393,30 +134688,30 @@ module.exports = class upbit extends Exchange { const timestamp = this.safeInteger (ticker, 'trade_timestamp'); const marketId = this.safeString2 (ticker, 'market', 'code'); const symbol = this.safeSymbol (marketId, market, '-'); - const previous = this.safeFloat (ticker, 'prev_closing_price'); - const last = this.safeFloat (ticker, 'trade_price'); - const change = this.safeFloat (ticker, 'signed_change_price'); - const percentage = this.safeFloat (ticker, 'signed_change_rate'); + const previous = this.safeNumber (ticker, 'prev_closing_price'); + const last = this.safeNumber (ticker, 'trade_price'); + const change = this.safeNumber (ticker, 'signed_change_price'); + const percentage = this.safeNumber (ticker, 'signed_change_rate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price'), - 'low': this.safeFloat (ticker, 'low_price'), + 'high': this.safeNumber (ticker, 'high_price'), + 'low': this.safeNumber (ticker, 'low_price'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'opening_price'), + 'open': this.safeNumber (ticker, 'opening_price'), 'close': last, 'last': last, 'previousClose': previous, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'acc_trade_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'acc_trade_price_24h'), + 'baseVolume': this.safeNumber (ticker, 'acc_trade_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'acc_trade_price_24h'), 'info': ticker, }; } @@ -136523,15 +134818,13 @@ module.exports = class upbit extends Exchange { } else if (askOrBid === 'bid') { side = 'buy'; } - let cost = this.safeFloat (trade, 'funds'); - const price = this.safeFloat2 (trade, 'trade_price', 'price'); - const amount = this.safeFloat2 (trade, 'trade_volume', 'volume'); + let cost = this.safeNumber (trade, 'funds'); + const priceString = this.safeString2 (trade, 'trade_price', 'price'); + const amountString = this.safeString2 (trade, 'trade_volume', 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString2 (trade, 'market', 'code'); market = this.safeMarket (marketId, market); @@ -136626,11 +134919,11 @@ module.exports = class upbit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'candle_date_time_utc')), - this.safeFloat (ohlcv, 'opening_price'), - this.safeFloat (ohlcv, 'high_price'), - this.safeFloat (ohlcv, 'low_price'), - this.safeFloat (ohlcv, 'trade_price'), - this.safeFloat (ohlcv, 'candle_acc_trade_volume'), // base volume + this.safeNumber (ohlcv, 'opening_price'), + this.safeNumber (ohlcv, 'high_price'), + this.safeNumber (ohlcv, 'low_price'), + this.safeNumber (ohlcv, 'trade_price'), + this.safeNumber (ohlcv, 'candle_acc_trade_volume'), // base volume ]; } @@ -136899,7 +135192,7 @@ module.exports = class upbit extends Exchange { // } // const id = this.safeString (transaction, 'uuid'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = undefined; // not present in the data structure received from the exchange const tag = undefined; // not present in the data structure received from the exchange const txid = this.safeString (transaction, 'txid'); @@ -136912,7 +135205,7 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -136997,10 +135290,10 @@ module.exports = class upbit extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const status = this.parseOrderStatus (this.safeString (order, 'state')); let lastTradeTimestamp = undefined; - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - const filled = this.safeFloat (order, 'executed_volume'); + let price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const filled = this.safeNumber (order, 'executed_volume'); let cost = undefined; if (type === 'price') { type = 'market'; @@ -137009,7 +135302,7 @@ module.exports = class upbit extends Exchange { } let average = undefined; let fee = undefined; - let feeCost = this.safeFloat (order, 'paid_fee'); + let feeCost = this.safeNumber (order, 'paid_fee'); const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); let trades = this.safeValue (order, 'trades', []); @@ -137032,7 +135325,7 @@ module.exports = class upbit extends Exchange { cost = this.sum (cost, trade['cost']); if (getFeesFromTrades) { const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); + const tradeFeeCost = this.safeNumber (tradeFee, 'cost'); if (tradeFeeCost !== undefined) { feeCost = this.sum (feeCost, tradeFeeCost); } @@ -137174,16 +135467,6 @@ module.exports = class upbit extends Exchange { return this.parseOrder (response); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetDepositsCoinAddresses (params); @@ -137381,212 +135664,7 @@ module.exports = class upbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],173:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); - -// --------------------------------------------------------------------------- - -module.exports = class vaultoro extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'vaultoro', - 'name': 'Vaultoro', - 'countries': [ 'CH' ], - 'rateLimit': 1000, - 'version': '1', - 'has': { - 'CORS': true, - 'fetchMarkets': true, - 'fetchOrderBook': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'fetchTrades': true, - 'fetchTicker': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg', - 'api': 'https://api.vaultoro.com', - 'www': 'https://www.vaultoro.com', - 'doc': 'https://api.vaultoro.com', - }, - 'commonCurrencies': { - 'GLD': 'Gold', - }, - 'api': { - 'public': { - 'get': [ - 'bidandask', - 'buyorders', - 'latest', - 'latesttrades', - 'markets', - 'orderbook', - 'sellorders', - 'transactions/day', - 'transactions/hour', - 'transactions/month', - ], - }, - 'private': { - 'get': [ - 'balance', - 'mytrades', - 'orders', - ], - 'post': [ - 'buy/{symbol}/{type}', - 'cancel/{id}', - 'sell/{symbol}/{type}', - 'withdraw', - ], - }, - }, - }); - } - - async fetchMarkets (params = {}) { - const result = []; - const response = await this.publicGetMarkets (params); - const market = this.safeValue (response, 'data'); - const baseId = this.safeString (market, 'MarketCurrency'); - const quoteId = this.safeString (market, 'BaseCurrency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const id = this.safeString (market, 'MarketName'); - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'active': undefined, - 'precision': this.precision, - 'limits': this.limits, - }); - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetBalance (params); - const balances = this.safeValue (response, 'data'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency_code'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'cash'); - account['used'] = this.safeFloat (balance, 'reserved'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetOrderbook (params); - const orderbook = { - 'bids': response['data'][0]['b'], - 'asks': response['data'][1]['s'], - }; - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'Gold_Price', 'Gold_Amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'Time')); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const price = this.safeFloat (trade, 'Gold_Price'); - const amount = this.safeFloat (trade, 'Gold_Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } - return { - 'id': undefined, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': undefined, - 'side': undefined, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const response = await this.publicGetTransactionsDay (params); - return this.parseTrades (response, market, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const method = 'privatePost' + this.capitalize (side) + 'SymbolType'; - const request = { - 'symbol': market['quoteId'].toLowerCase (), - 'type': type, - 'gld': amount, - 'price': price || 1, - }; - const response = await this[method] (this.extend (request, params)); - return { - 'info': response, - 'id': response['data']['Order_ID'], - }; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - return await this.privatePostCancelId (this.extend (request, params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/'; - if (api === 'public') { - url += path; - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce (); - url += this.version + '/' + this.implodeParams (path, params); - const query = this.extend ({ - 'nonce': nonce, - 'apikey': this.apiKey, - }, this.omit (params, this.extractParams (path))); - url += '?' + this.urlencode (query); - headers = { - 'Content-Type': 'application/json', - 'X-Signature': this.hmac (this.encode (url), this.encode (this.secret)), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } -}; - -},{"./base/Exchange":6}],174:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],170:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -137620,7 +135698,7 @@ module.exports = class vbtc extends foxbit { } }; -},{"./foxbit.js":87}],175:[function(require,module,exports){ +},{"./foxbit.js":85}],171:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -137628,6 +135706,7 @@ module.exports = class vbtc extends foxbit { const Exchange = require ('./base/Exchange'); const { ExchangeError, OrderNotFound, InvalidOrder, BadRequest, AuthenticationError, RateLimitExceeded, RequestTimeout, BadSymbol, AddressPending, PermissionDenied, InsufficientFunds } = require ('./base/errors'); const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -137819,15 +135898,15 @@ module.exports = class vcc extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, 'min'), + 'min': this.safeNumber (amountLimits, 'min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (priceLimits, 'min'), + 'min': this.safeNumber (priceLimits, 'min'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (costLimits, 'min'), + 'min': this.safeNumber (costLimits, 'min'), 'max': undefined, }, }, @@ -137874,12 +135953,12 @@ module.exports = class vcc extends Exchange { 'code': code, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': this.safeInteger (currency, 'decimal'), 'limits': { 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw'), - 'max': this.safeFloat (currency, 'max_withdraw'), + 'min': this.safeNumber (currency, 'min_withdraw'), + 'max': this.safeNumber (currency, 'max_withdraw'), }, }, }; @@ -137902,8 +135981,8 @@ module.exports = class vcc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } @@ -137929,11 +136008,11 @@ module.exports = class vcc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (data, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -137951,11 +136030,11 @@ module.exports = class vcc extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -138044,10 +136123,10 @@ module.exports = class vcc extends Exchange { // } // const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); - const open = this.safeFloat (ticker, 'open_price'); - const last = this.safeFloat (ticker, 'last_price'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); + const open = this.safeNumber (ticker, 'open_price'); + const last = this.safeNumber (ticker, 'last_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -138064,11 +136143,11 @@ module.exports = class vcc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -138182,17 +136261,17 @@ module.exports = class vcc extends Exchange { } market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'base_volume', 'quantity'); - let cost = this.safeFloat2 (trade, 'quote_volume', 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'base_volume', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber2 (trade, 'quote_volume', 'amount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const side = this.safeString2 (trade, 'type', 'trade_type'); const id = this.safeString2 (trade, 'trade_id', 'id'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -138377,7 +136456,7 @@ module.exports = class vcc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -138385,7 +136464,7 @@ module.exports = class vcc extends Exchange { const txid = this.safeString (transaction, 'transaction_id'); const tag = this.safeString (transaction, 'destination_tag'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -138630,46 +136709,27 @@ module.exports = class vcc extends Exchange { const marketId = baseId + '_' + quoteId; market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'executed_quantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - let cost = this.safeFloat (order, 'ceiling'); + const cost = this.safeNumber (order, 'ceiling'); const id = this.safeString (order, 'id'); - let average = undefined; - let price = this.safeFloat (order, 'price'); - // in case of market order - if (!price) { - price = this.safeFloat (order, 'executed_price'); - average = price; - } - let remaining = this.safeFloat (order, 'remaining'); - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if (filled !== undefined) { - if ((amount !== undefined) && (remaining === undefined)) { - remaining = Math.max (0, amount - filled); - } - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((average === undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'executed_price'); + const remaining = this.safeNumber (order, 'remaining'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'trade_type'); const fee = { 'currency': market['quote'], - 'cost': this.safeFloat (order, 'fee'), - 'rate': this.safeFloat (order, 'fee_rate'), + 'cost': this.safeNumber (order, 'fee'), + 'rate': this.safeNumber (order, 'fee_rate'), }; let lastTradeTimestamp = undefined; if (updated !== created) { lastTradeTimestamp = updated; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': id, 'timestamp': created, @@ -138691,7 +136751,7 @@ module.exports = class vcc extends Exchange { 'fee': fee, 'trades': undefined, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -138961,7 +137021,7 @@ module.exports = class vcc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],176:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],172:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -139529,13 +137589,13 @@ module.exports = class wavesexchange extends Exchange { symbol = market['symbol']; } const data = this.safeValue (ticker, 'data', {}); - const last = this.safeFloat (data, 'lastPrice'); - const low = this.safeFloat (data, 'low'); - const high = this.safeFloat (data, 'high'); - const vwap = this.safeFloat (data, 'weightedAveragePrice'); - const baseVolume = this.safeFloat (data, 'volume'); - const quoteVolume = this.safeFloat (data, 'quoteVolume'); - const open = this.safeValue (data, 'firstPrice'); + const last = this.safeNumber (data, 'lastPrice'); + const low = this.safeNumber (data, 'low'); + const high = this.safeNumber (data, 'high'); + const vwap = this.safeNumber (data, 'weightedAveragePrice'); + const baseVolume = this.safeNumber (data, 'volume'); + const quoteVolume = this.safeNumber (data, 'quoteVolume'); + const open = this.safeNumber (data, 'firstPrice'); let change = undefined; let average = undefined; let percentage = undefined; @@ -139689,11 +137749,11 @@ module.exports = class wavesexchange extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.parse8601 (this.safeString (data, 'time')), - this.safeFloat (data, 'open'), - this.safeFloat (data, 'high'), - this.safeFloat (data, 'low'), - this.safeFloat (data, 'close'), - this.safeFloat (data, 'volume', 0), + this.safeNumber (data, 'open'), + this.safeNumber (data, 'high'), + this.safeNumber (data, 'low'), + this.safeNumber (data, 'close'), + this.safeNumber (data, 'volume', 0), ]; } @@ -139908,7 +137968,7 @@ module.exports = class wavesexchange extends Exchange { } if (matcherFee === undefined) { const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8); - const rate = this.safeFloat (rates, matcherFeeAssetId); + const rate = this.safeNumber (rates, matcherFeeAssetId); const code = this.safeCurrencyCode (matcherFeeAssetId); const currency = this.currency (code); const newPrecison = Math.pow (10, wavesPrecision - currency['precision']); @@ -140318,7 +138378,7 @@ module.exports = class wavesexchange extends Exchange { const issueTransaction = this.safeValue (entry, 'issueTransaction'); const decimals = this.safeInteger (issueTransaction, 'decimals'); const currencyId = this.safeString (entry, 'assetId'); - const balance = this.safeFloat (entry, 'balance'); + const balance = this.safeNumber (entry, 'balance'); let code = undefined; if (currencyId in this.currencies_by_id) { code = this.safeCurrencyCode (currencyId); @@ -140348,7 +138408,7 @@ module.exports = class wavesexchange extends Exchange { if (!(code in result)) { result[code] = this.account (); } - const amount = this.safeFloat (reservedBalance, currencyId); + const amount = this.safeNumber (reservedBalance, currencyId); result[code]['used'] = this.currencyFromPrecision (code, amount); } const wavesRequest = { @@ -140361,7 +138421,7 @@ module.exports = class wavesexchange extends Exchange { // "balance": 909085978 // } result['WAVES'] = this.safeValue (result, 'WAVES', {}); - result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeFloat (wavesTotal, 'balance')); + result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeNumber (wavesTotal, 'balance')); const codes = Object.keys (result); for (let i = 0; i < codes.length; i++) { const code = codes[i]; @@ -140453,8 +138513,8 @@ module.exports = class wavesexchange extends Exchange { const datetime = this.safeString (data, 'timestamp'); const timestamp = this.parse8601 (datetime); const id = this.safeString (data, 'id'); - const price = this.safeFloat (data, 'price'); - const amount = this.safeFloat (data, 'amount'); + const price = this.safeNumber (data, 'price'); + const amount = this.safeNumber (data, 'amount'); const order1 = this.safeValue (data, 'order1'); const order2 = this.safeValue (data, 'order2'); let order = undefined; @@ -140478,7 +138538,7 @@ module.exports = class wavesexchange extends Exchange { cost = price * amount; } const fee = { - 'cost': this.safeFloat (data, 'fee'), + 'cost': this.safeNumber (data, 'fee'), 'currency': this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES')), }; return { @@ -140560,7 +138620,7 @@ module.exports = class wavesexchange extends Exchange { const withdrawAddress = await this.privateGetWithdrawAddressesCurrencyAddress (withdrawAddressRequest); const currency = this.safeValue (withdrawAddress, 'currency'); const allowedAmount = this.safeValue (currency, 'allowed_amount'); - const minimum = this.safeFloat (allowedAmount, 'min'); + const minimum = this.safeNumber (allowedAmount, 'min'); if (amount <= minimum) { throw new BadRequest (this.id + ' ' + code + ' withdraw failed, amount ' + amount.toString () + ' must be greater than the minimum allowed amount of ' + minimum.toString ()); } @@ -140630,13 +138690,14 @@ module.exports = class wavesexchange extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],177:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],173:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeNotAvailable, ExchangeError, DDoSProtection, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -140797,7 +138858,7 @@ module.exports = class whitebit extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -140805,7 +138866,7 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minTotal'), + 'min': this.safeNumber (market, 'minTotal'), 'max': undefined, }, }, @@ -140870,8 +138931,8 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -140883,8 +138944,8 @@ module.exports = class whitebit extends Exchange { const response = await this.publicV2GetFee (params); const fees = this.safeValue (response, 'result'); return { - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), }; } @@ -140954,8 +139015,8 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let change = undefined; if (percentage !== undefined) { change = this.numberToString (percentage * 0.01); @@ -140964,22 +139025,22 @@ module.exports = class whitebit extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'deal'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'deal'), 'info': ticker, }; } @@ -141147,8 +139208,11 @@ module.exports = class whitebit extends Exchange { } else { timestamp = parseInt (timestamp * 1000); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'volume'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'volume'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const id = this.safeString2 (trade, 'id', 'tradeId'); let side = this.safeString (trade, 'type'); if (side === undefined) { @@ -141159,10 +139223,6 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined && price !== undefined) { - cost = amount * price; - } return { 'info': trade, 'timestamp': timestamp, @@ -141232,11 +139292,11 @@ module.exports = class whitebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -141285,7 +139345,7 @@ module.exports = class whitebit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],178:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],174:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -141440,14 +139500,13 @@ module.exports = class xbtce extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'FreeAmount'), - 'used': this.safeFloat (balance, 'LockedAmount'), - 'total': this.safeFloat (balance, 'Amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'FreeAmount'); + account['used'] = this.safeString (balance, 'LockedAmount'); + account['total'] = this.safeString (balance, 'Amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -141559,11 +139618,11 @@ module.exports = class xbtce extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeInteger (ohlcv, 'Timestamp'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -141657,11 +139716,12 @@ module.exports = class xbtce extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],179:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],175:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, InsufficientFunds, InvalidAddress, BadSymbol, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class xena extends Exchange { describe () { @@ -141937,8 +139997,8 @@ module.exports = class xena extends Exchange { 'price': pricePrecision, 'amount': 0, }; - const maxCost = this.safeFloat (market, 'maxOrderQty'); - const minCost = this.safeFloat (market, 'minOrderQuantity'); + const maxCost = this.safeNumber (market, 'maxOrderQty'); + const minCost = this.safeNumber (market, 'minOrderQuantity'); const limits = { 'amount': { 'min': undefined, @@ -142023,7 +140083,7 @@ module.exports = class xena extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (withdraw, 'commission'), + 'fee': this.safeNumber (withdraw, 'commission'), 'precision': precision, 'limits': { 'amount': { @@ -142039,7 +140099,7 @@ module.exports = class xena extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'minAmount'), + 'min': this.safeNumber (withdraw, 'minAmount'), 'max': undefined, }, }, @@ -142067,8 +140127,8 @@ module.exports = class xena extends Exchange { const timestamp = this.milliseconds (); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPx'); - const open = this.safeFloat (ticker, 'firstPx'); + const last = this.safeNumber (ticker, 'lastPx'); + const open = this.safeNumber (ticker, 'firstPx'); let percentage = undefined; let change = undefined; let average = undefined; @@ -142079,18 +140139,18 @@ module.exports = class xena extends Exchange { percentage = change / open * 100; } } - const buyVolume = this.safeFloat (ticker, 'buyVolume'); - const sellVolume = this.safeFloat (ticker, 'sellVolume'); + const buyVolume = this.safeNumber (ticker, 'buyVolume'); + const sellVolume = this.safeNumber (ticker, 'sellVolume'); const baseVolume = this.sum (buyVolume, sellVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPx'), - 'low': this.safeFloat (ticker, 'lowPx'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'highPx'), + 'low': this.safeNumber (ticker, 'lowPx'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -142267,11 +140327,11 @@ module.exports = class xena extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onHold'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onHold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTrade (trade, market = undefined) { @@ -142325,20 +140385,17 @@ module.exports = class xena extends Exchange { const orderId = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat2 (trade, 'lastPx', 'mdEntryPx'); - const amount = this.safeFloat2 (trade, 'lastQty', 'mdEntrySize'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'lastPx', 'mdEntryPx'); + const amountString = this.safeString2 (trade, 'lastQty', 'mdEntrySize'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (trade, 'commRate'); + const feeRate = this.safeNumber (trade, 'commRate'); fee = { 'cost': feeCost, 'rate': feeRate, @@ -142453,15 +140510,15 @@ module.exports = class xena extends Exchange { // const transactTime = this.safeInteger (ohlcv, 'transactTime'); const timestamp = parseInt (transactTime / 1000000); - const buyVolume = this.safeFloat (ohlcv, 'buyVolume'); - const sellVolume = this.safeFloat (ohlcv, 'sellVolume'); + const buyVolume = this.safeNumber (ohlcv, 'buyVolume'); + const sellVolume = this.safeNumber (ohlcv, 'sellVolume'); const volume = this.sum (buyVolume, sellVolume); return [ timestamp, - this.safeFloat (ohlcv, 'firstPx'), - this.safeFloat (ohlcv, 'highPx'), - this.safeFloat (ohlcv, 'lowPx'), - this.safeFloat (ohlcv, 'lastPx'), + this.safeNumber (ohlcv, 'firstPx'), + this.safeNumber (ohlcv, 'highPx'), + this.safeNumber (ohlcv, 'lowPx'), + this.safeNumber (ohlcv, 'lastPx'), volume, ]; } @@ -142586,11 +140643,10 @@ module.exports = class xena extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); - let cost = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); let side = this.safeStringLower (order, 'side'); if (side === '1') { side = 'buy'; @@ -142607,12 +140663,7 @@ module.exports = class xena extends Exchange { } else if (type === '4') { type = 'stop-limit'; } - if (cost === undefined) { - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -142627,14 +140678,14 @@ module.exports = class xena extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -142687,7 +140738,7 @@ module.exports = class xena extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if ((type === 'stop') || (type === 'stop-limit')) { - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPx param for order type ' + type); } @@ -142766,12 +140817,12 @@ module.exports = class xena extends Exchange { if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); } - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx !== undefined) { request['stopPx'] = this.priceToPrecision (symbol, stopPx); params = this.omit (params, 'stopPx'); } - const capPrice = this.safeFloat (params, 'capPrice'); + const capPrice = this.safeNumber (params, 'capPrice'); if (capPrice !== undefined) { request['capPrice'] = this.priceToPrecision (symbol, capPrice); params = this.omit (params, 'capPrice'); @@ -143126,7 +141177,7 @@ module.exports = class xena extends Exchange { const address = this.safeString (transaction, 'address'); const addressFrom = undefined; const addressTo = address; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const fee = undefined; return { @@ -143223,7 +141274,7 @@ module.exports = class xena extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'kind')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); @@ -143235,11 +141286,11 @@ module.exports = class xena extends Exchange { timestamp = parseInt (timestamp / 1000000); } const fee = { - 'cost': this.safeFloat (item, 'commission'), + 'cost': this.safeNumber (item, 'commission'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -143379,13 +141430,14 @@ module.exports = class xena extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],180:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],176:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError, RateLimitExceeded } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -143520,6 +141572,7 @@ module.exports = class yobit extends Exchange { 'NAV': 'NavajoCoin', 'NBT': 'NiceBytes', 'OMG': 'OMGame', + 'ONX': 'Onix', 'PAC': '$PAC', 'PLAY': 'PlayCoin', 'PIVX': 'Darknet', @@ -143618,15 +141671,33 @@ module.exports = class yobit extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['total'] = this.safeFloat (total, currencyId); + account['free'] = this.safeString (free, currencyId); + account['total'] = this.safeString (total, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615856752, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":10000, + // "min_amount":0.0001, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.2, + // "fee_buyer":0.2, + // "fee_seller":0.2 + // }, + // }, + // } + // const markets = this.safeValue (response, 'pairs'); const keys = Object.keys (markets); const result = []; @@ -143644,15 +141715,15 @@ module.exports = class yobit extends Exchange { 'price': this.safeInteger (market, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }; const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }; const costLimits = { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }; const limits = { 'amount': amountLimits, @@ -143661,6 +141732,7 @@ module.exports = class yobit extends Exchange { }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -143669,7 +141741,7 @@ module.exports = class yobit extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -143745,16 +141817,16 @@ module.exports = class yobit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -143763,9 +141835,9 @@ module.exports = class yobit extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -143814,15 +141886,18 @@ module.exports = class yobit extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const order = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const type = 'limit'; // all trades are still limit trades let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -143837,12 +141912,6 @@ module.exports = class yobit extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, 'taker'); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': order, @@ -143904,8 +141973,8 @@ module.exports = class yobit extends Exchange { id = this.safeString (response['return'], 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (response['return'], 'received', 0.0); + remaining = this.safeNumber (response['return'], 'remains', amount); } const timestamp = this.milliseconds (); return { @@ -143955,21 +142024,13 @@ module.exports = class yobit extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp_created'); const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const remaining = this.safeFloat (order, 'amount'); - const amount = this.safeFloat (order, 'start_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - cost = price * filled; - } - } + const remaining = this.safeNumber (order, 'amount'); + const amount = this.safeNumber (order, 'start_amount'); + const price = this.safeNumber (order, 'rate'); const fee = undefined; const type = 'limit'; const side = this.safeString (order, 'type'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -143983,16 +142044,15 @@ module.exports = class yobit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -144203,13 +142263,14 @@ module.exports = class yobit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],181:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],177:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -144333,6 +142394,27 @@ module.exports = class zaif extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetCurrencyPairsAll (params); + // + // [ + // { + // "aux_unit_point": 0, + // "item_japanese": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3", + // "aux_unit_step": 5.0, + // "description": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3\u30fb\u65e5\u672c\u5186\u306e\u53d6\u5f15\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059", + // "item_unit_min": 0.001, + // "event_number": 0, + // "currency_pair": "btc_jpy", + // "is_token": false, + // "aux_unit_min": 5.0, + // "aux_japanese": "\u65e5\u672c\u5186", + // "id": 1, + // "item_unit_step": 0.0001, + // "name": "BTC/JPY", + // "seq": 0, + // "title": "BTC/JPY" + // } + // ] + // const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -144343,8 +142425,8 @@ module.exports = class zaif extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': -Math.log10 (market['item_unit_step']), - 'price': market['aux_unit_point'], + 'amount': -Math.log10 (this.safeNumber (market, 'item_unit_step')), + 'price': this.safeInteger (market, 'aux_unit_point'), }; const fees = this.safeValue (this.options['fees'], symbol, this.fees['trading']); const taker = fees['taker']; @@ -144362,11 +142444,11 @@ module.exports = class zaif extends Exchange { 'maker': maker, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'item_unit_min'), + 'min': this.safeNumber (market, 'item_unit_min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'aux_unit_min'), + 'min': this.safeNumber (market, 'aux_unit_min'), 'max': undefined, }, 'cost': { @@ -144398,7 +142480,7 @@ module.exports = class zaif extends Exchange { }; if ('deposit' in balances) { if (currencyId in balances['deposit']) { - account['total'] = this.safeFloat (balances['deposit'], currencyId); + account['total'] = this.safeNumber (balances['deposit'], currencyId); account['used'] = account['total'] - account['free']; } } @@ -144423,22 +142505,22 @@ module.exports = class zaif extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.milliseconds (); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -144459,14 +142541,11 @@ module.exports = class zaif extends Exchange { side = (side === 'bid') ? 'buy' : 'sell'; const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString2 (trade, 'id', 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); return { @@ -144544,16 +142623,10 @@ module.exports = class zaif extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp'); const marketId = this.safeString (order, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -144567,7 +142640,7 @@ module.exports = class zaif extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': undefined, 'remaining': undefined, @@ -144575,7 +142648,7 @@ module.exports = class zaif extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -144694,13 +142767,14 @@ module.exports = class zaif extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],182:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],178:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadRequest, ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, OrderNotFound, ExchangeNotAvailable, DDoSProtection, InvalidOrder, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -144786,8 +142860,8 @@ module.exports = class zb extends Exchange { 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg', 'api': { - 'public': 'http://api.zb.cn/data', // no https for public API - 'private': 'https://trade.zb.cn/api', + 'public': 'https://api.zb.today/data', + 'private': 'https://trade.zb.today/api', }, 'www': 'https://www.zb.com', 'doc': 'https://www.zb.com/i/developer', @@ -144902,6 +142976,16 @@ module.exports = class zb extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetMarkets (params); + // + // { + // "zb_qc":{ + // "amountScale":2, + // "minAmount":0.01, + // "minSize":5, + // "priceScale":4, + // }, + // } + // const keys = Object.keys (markets); const result = []; for (let i = 0; i < keys.length; i++) { @@ -144965,11 +143049,11 @@ module.exports = class zb extends Exchange { const account = this.account (); const currencyId = this.safeString (balance, 'key'); const code = this.safeCurrencyCode (currencyId); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'freez'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'freez'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -145018,18 +143102,6 @@ module.exports = class zb extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetGetPayinAddress (params); @@ -145136,16 +143208,16 @@ module.exports = class zb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -145155,12 +143227,23 @@ module.exports = class zb extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; } + parseOHLCV (ohlcv, market = undefined) { + return [ + this.safeInteger (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + ]; + } + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -145185,14 +143268,12 @@ module.exports = class zb extends Exchange { let side = this.safeString (trade, 'trade_type'); side = (side === 'bid') ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const costString = Precise.stringMul (priceString, amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (costString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -145371,23 +143452,13 @@ module.exports = class zb extends Exchange { const timestamp = this.safeInteger (order, 'trade_date'); const marketId = this.safeString (order, 'currency'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'trade_amount'); - const amount = this.safeFloat (order, 'total_amount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'trade_money'); - let average = undefined; + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'trade_amount'); + const amount = this.safeNumber (order, 'total_amount'); + const cost = this.safeNumber (order, 'trade_money'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((cost !== undefined) && (filled !== undefined) && (filled > 0)) { - average = cost / filled; - } const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fees'); + const feeCost = this.safeNumber (order, 'fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -145402,7 +143473,7 @@ module.exports = class zb extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -145416,15 +143487,15 @@ module.exports = class zb extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -145487,7 +143558,7 @@ module.exports = class zb extends Exchange { // const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'hash'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let timestamp = this.parse8601 (this.safeString (transaction, 'submit_time')); timestamp = this.safeInteger (transaction, 'submitTime', timestamp); let address = this.safeString2 (transaction, 'toAddress', 'address'); @@ -145507,7 +143578,7 @@ module.exports = class zb extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -145540,7 +143611,7 @@ module.exports = class zb extends Exchange { if (password === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires exchange.password or a safePwd parameter'); } - const fees = this.safeFloat (params, 'fees'); + const fees = this.safeNumber (params, 'fees'); if (fees === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires a fees parameter'); } @@ -145731,7 +143802,7 @@ module.exports = class zb extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],183:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],179:[function(require,module,exports){ (function (global){ 'use strict'; @@ -146225,7 +144296,7 @@ var objectKeys = Object.keys || function (obj) { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"util/":241}],184:[function(require,module,exports){ +},{"util/":237}],180:[function(require,module,exports){ 'use strict' exports.byteLength = byteLength @@ -146341,9 +144412,9 @@ function fromByteArray (uint8) { return parts.join('') } -},{}],185:[function(require,module,exports){ +},{}],181:[function(require,module,exports){ -},{}],186:[function(require,module,exports){ +},{}],182:[function(require,module,exports){ (function (process,Buffer){ 'use strict'; /* eslint camelcase: "off" */ @@ -146755,7 +144826,7 @@ Zlib.prototype._reset = function () { exports.Zlib = Zlib; }).call(this,require('_process'),require("buffer").Buffer) -},{"_process":210,"assert":183,"buffer":188,"pako/lib/zlib/constants":200,"pako/lib/zlib/deflate.js":202,"pako/lib/zlib/inflate.js":204,"pako/lib/zlib/zstream":208}],187:[function(require,module,exports){ +},{"_process":206,"assert":179,"buffer":184,"pako/lib/zlib/constants":196,"pako/lib/zlib/deflate.js":198,"pako/lib/zlib/inflate.js":200,"pako/lib/zlib/zstream":204}],183:[function(require,module,exports){ (function (process){ 'use strict'; @@ -147367,7 +145438,7 @@ util.inherits(DeflateRaw, Zlib); util.inherits(InflateRaw, Zlib); util.inherits(Unzip, Zlib); }).call(this,require('_process')) -},{"./binding":186,"_process":210,"assert":183,"buffer":188,"stream":229,"util":241}],188:[function(require,module,exports){ +},{"./binding":182,"_process":206,"assert":179,"buffer":184,"stream":225,"util":237}],184:[function(require,module,exports){ /*! * The buffer module from node.js, for the browser. * @@ -149083,7 +147154,7 @@ function numberIsNaN (obj) { return obj !== obj // eslint-disable-line no-self-compare } -},{"base64-js":184,"ieee754":194}],189:[function(require,module,exports){ +},{"base64-js":180,"ieee754":190}],185:[function(require,module,exports){ module.exports = { "100": "Continue", "101": "Switching Protocols", @@ -149149,7 +147220,7 @@ module.exports = { "511": "Network Authentication Required" } -},{}],190:[function(require,module,exports){ +},{}],186:[function(require,module,exports){ module.exports={ "O_RDONLY": 0, "O_WRONLY": 1, @@ -149360,7 +147431,7 @@ module.exports={ "UV_UDP_REUSEADDR": 4 } -},{}],191:[function(require,module,exports){ +},{}],187:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -149471,7 +147542,7 @@ function objectToString(o) { } }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) -},{"../../is-buffer/index.js":196}],192:[function(require,module,exports){ +},{"../../is-buffer/index.js":192}],188:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -149775,7 +147846,7 @@ function isUndefined(arg) { return arg === void 0; } -},{}],193:[function(require,module,exports){ +},{}],189:[function(require,module,exports){ var http = require('http') var url = require('url') @@ -149808,7 +147879,7 @@ function validateParams (params) { return params } -},{"http":230,"url":236}],194:[function(require,module,exports){ +},{"http":226,"url":232}],190:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = nBytes * 8 - mLen - 1 @@ -149894,7 +147965,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],195:[function(require,module,exports){ +},{}],191:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -149919,7 +147990,7 @@ if (typeof Object.create === 'function') { } } -},{}],196:[function(require,module,exports){ +},{}],192:[function(require,module,exports){ /*! * Determine if an object is a Buffer * @@ -149942,14 +148013,14 @@ function isSlowBuffer (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) } -},{}],197:[function(require,module,exports){ +},{}],193:[function(require,module,exports){ var toString = {}.toString; module.exports = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; -},{}],198:[function(require,module,exports){ +},{}],194:[function(require,module,exports){ 'use strict'; @@ -150056,7 +148127,7 @@ exports.setTyped = function (on) { exports.setTyped(TYPED_OK); -},{}],199:[function(require,module,exports){ +},{}],195:[function(require,module,exports){ 'use strict'; // Note: adler32 takes 12% for level 0 and 2% for level 6. @@ -150109,7 +148180,7 @@ function adler32(adler, buf, len, pos) { module.exports = adler32; -},{}],200:[function(require,module,exports){ +},{}],196:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -150179,7 +148250,7 @@ module.exports = { //Z_NULL: null // Use -1 or null inline, depending on var type }; -},{}],201:[function(require,module,exports){ +},{}],197:[function(require,module,exports){ 'use strict'; // Note: we can't get significant speed boost here. @@ -150240,7 +148311,7 @@ function crc32(crc, buf, len, pos) { module.exports = crc32; -},{}],202:[function(require,module,exports){ +},{}],198:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -152116,7 +150187,7 @@ exports.deflatePrime = deflatePrime; exports.deflateTune = deflateTune; */ -},{"../utils/common":198,"./adler32":199,"./crc32":201,"./messages":206,"./trees":207}],203:[function(require,module,exports){ +},{"../utils/common":194,"./adler32":195,"./crc32":197,"./messages":202,"./trees":203}],199:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -152463,7 +150534,7 @@ module.exports = function inflate_fast(strm, start) { return; }; -},{}],204:[function(require,module,exports){ +},{}],200:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154021,7 +152092,7 @@ exports.inflateSyncPoint = inflateSyncPoint; exports.inflateUndermine = inflateUndermine; */ -},{"../utils/common":198,"./adler32":199,"./crc32":201,"./inffast":203,"./inftrees":205}],205:[function(require,module,exports){ +},{"../utils/common":194,"./adler32":195,"./crc32":197,"./inffast":199,"./inftrees":201}],201:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154366,7 +152437,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta return 0; }; -},{"../utils/common":198}],206:[function(require,module,exports){ +},{"../utils/common":194}],202:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154400,7 +152471,7 @@ module.exports = { '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ }; -},{}],207:[function(require,module,exports){ +},{}],203:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -155622,7 +153693,7 @@ exports._tr_flush_block = _tr_flush_block; exports._tr_tally = _tr_tally; exports._tr_align = _tr_align; -},{"../utils/common":198}],208:[function(require,module,exports){ +},{"../utils/common":194}],204:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -155671,7 +153742,7 @@ function ZStream() { module.exports = ZStream; -},{}],209:[function(require,module,exports){ +},{}],205:[function(require,module,exports){ (function (process){ 'use strict'; @@ -155718,7 +153789,7 @@ function nextTick(fn, arg1, arg2, arg3) { } }).call(this,require('_process')) -},{"_process":210}],210:[function(require,module,exports){ +},{"_process":206}],206:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -155904,7 +153975,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],211:[function(require,module,exports){ +},{}],207:[function(require,module,exports){ (function (global){ /*! https://mths.be/punycode v1.4.1 by @mathias */ ;(function(root) { @@ -156441,7 +154512,7 @@ process.umask = function() { return 0; }; }(this)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],212:[function(require,module,exports){ +},{}],208:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156527,7 +154598,7 @@ var isArray = Array.isArray || function (xs) { return Object.prototype.toString.call(xs) === '[object Array]'; }; -},{}],213:[function(require,module,exports){ +},{}],209:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156614,16 +154685,16 @@ var objectKeys = Object.keys || function (obj) { return res; }; -},{}],214:[function(require,module,exports){ +},{}],210:[function(require,module,exports){ 'use strict'; exports.decode = exports.parse = require('./decode'); exports.encode = exports.stringify = require('./encode'); -},{"./decode":212,"./encode":213}],215:[function(require,module,exports){ +},{"./decode":208,"./encode":209}],211:[function(require,module,exports){ module.exports = require('./lib/_stream_duplex.js'); -},{"./lib/_stream_duplex.js":216}],216:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":212}],212:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156748,7 +154819,7 @@ function forEach(xs, f) { f(xs[i], i); } } -},{"./_stream_readable":218,"./_stream_writable":220,"core-util-is":191,"inherits":195,"process-nextick-args":209}],217:[function(require,module,exports){ +},{"./_stream_readable":214,"./_stream_writable":216,"core-util-is":187,"inherits":191,"process-nextick-args":205}],213:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156796,7 +154867,7 @@ function PassThrough(options) { PassThrough.prototype._transform = function (chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":219,"core-util-is":191,"inherits":195}],218:[function(require,module,exports){ +},{"./_stream_transform":215,"core-util-is":187,"inherits":191}],214:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -157806,7 +155877,7 @@ function indexOf(xs, x) { return -1; } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":216,"./internal/streams/BufferList":221,"./internal/streams/destroy":222,"./internal/streams/stream":223,"_process":210,"core-util-is":191,"events":192,"inherits":195,"isarray":197,"process-nextick-args":209,"safe-buffer":228,"string_decoder/":234,"util":185}],219:[function(require,module,exports){ +},{"./_stream_duplex":212,"./internal/streams/BufferList":217,"./internal/streams/destroy":218,"./internal/streams/stream":219,"_process":206,"core-util-is":187,"events":188,"inherits":191,"isarray":193,"process-nextick-args":205,"safe-buffer":224,"string_decoder/":230,"util":181}],215:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -158021,7 +156092,7 @@ function done(stream, er, data) { return stream.push(null); } -},{"./_stream_duplex":216,"core-util-is":191,"inherits":195}],220:[function(require,module,exports){ +},{"./_stream_duplex":212,"core-util-is":187,"inherits":191}],216:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -158688,7 +156759,7 @@ Writable.prototype._destroy = function (err, cb) { cb(err); }; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":216,"./internal/streams/destroy":222,"./internal/streams/stream":223,"_process":210,"core-util-is":191,"inherits":195,"process-nextick-args":209,"safe-buffer":228,"util-deprecate":238}],221:[function(require,module,exports){ +},{"./_stream_duplex":212,"./internal/streams/destroy":218,"./internal/streams/stream":219,"_process":206,"core-util-is":187,"inherits":191,"process-nextick-args":205,"safe-buffer":224,"util-deprecate":234}],217:[function(require,module,exports){ 'use strict'; /**/ @@ -158763,7 +156834,7 @@ module.exports = function () { return BufferList; }(); -},{"safe-buffer":228}],222:[function(require,module,exports){ +},{"safe-buffer":224}],218:[function(require,module,exports){ 'use strict'; /**/ @@ -158836,13 +156907,13 @@ module.exports = { destroy: destroy, undestroy: undestroy }; -},{"process-nextick-args":209}],223:[function(require,module,exports){ +},{"process-nextick-args":205}],219:[function(require,module,exports){ module.exports = require('events').EventEmitter; -},{"events":192}],224:[function(require,module,exports){ +},{"events":188}],220:[function(require,module,exports){ module.exports = require('./readable').PassThrough -},{"./readable":225}],225:[function(require,module,exports){ +},{"./readable":221}],221:[function(require,module,exports){ exports = module.exports = require('./lib/_stream_readable.js'); exports.Stream = exports; exports.Readable = exports; @@ -158851,13 +156922,13 @@ exports.Duplex = require('./lib/_stream_duplex.js'); exports.Transform = require('./lib/_stream_transform.js'); exports.PassThrough = require('./lib/_stream_passthrough.js'); -},{"./lib/_stream_duplex.js":216,"./lib/_stream_passthrough.js":217,"./lib/_stream_readable.js":218,"./lib/_stream_transform.js":219,"./lib/_stream_writable.js":220}],226:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":212,"./lib/_stream_passthrough.js":213,"./lib/_stream_readable.js":214,"./lib/_stream_transform.js":215,"./lib/_stream_writable.js":216}],222:[function(require,module,exports){ module.exports = require('./readable').Transform -},{"./readable":225}],227:[function(require,module,exports){ +},{"./readable":221}],223:[function(require,module,exports){ module.exports = require('./lib/_stream_writable.js'); -},{"./lib/_stream_writable.js":220}],228:[function(require,module,exports){ +},{"./lib/_stream_writable.js":216}],224:[function(require,module,exports){ /* eslint-disable node/no-deprecated-api */ var buffer = require('buffer') var Buffer = buffer.Buffer @@ -158921,7 +156992,7 @@ SafeBuffer.allocUnsafeSlow = function (size) { return buffer.SlowBuffer(size) } -},{"buffer":188}],229:[function(require,module,exports){ +},{"buffer":184}],225:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -159050,7 +157121,7 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"events":192,"inherits":195,"readable-stream/duplex.js":215,"readable-stream/passthrough.js":224,"readable-stream/readable.js":225,"readable-stream/transform.js":226,"readable-stream/writable.js":227}],230:[function(require,module,exports){ +},{"events":188,"inherits":191,"readable-stream/duplex.js":211,"readable-stream/passthrough.js":220,"readable-stream/readable.js":221,"readable-stream/transform.js":222,"readable-stream/writable.js":223}],226:[function(require,module,exports){ (function (global){ var ClientRequest = require('./lib/request') var extend = require('xtend') @@ -159132,7 +157203,7 @@ http.METHODS = [ 'UNSUBSCRIBE' ] }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./lib/request":232,"builtin-status-codes":189,"url":236,"xtend":242}],231:[function(require,module,exports){ +},{"./lib/request":228,"builtin-status-codes":185,"url":232,"xtend":238}],227:[function(require,module,exports){ (function (global){ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) @@ -159205,7 +157276,7 @@ function isFunction (value) { xhr = null // Help gc }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],232:[function(require,module,exports){ +},{}],228:[function(require,module,exports){ (function (process,global,Buffer){ var capability = require('./capability') var inherits = require('inherits') @@ -159515,7 +157586,7 @@ var unsafeHeaders = [ ] }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"./capability":231,"./response":233,"_process":210,"buffer":188,"inherits":195,"readable-stream":225,"to-arraybuffer":235}],233:[function(require,module,exports){ +},{"./capability":227,"./response":229,"_process":206,"buffer":184,"inherits":191,"readable-stream":221,"to-arraybuffer":231}],229:[function(require,module,exports){ (function (process,global,Buffer){ var capability = require('./capability') var inherits = require('inherits') @@ -159701,7 +157772,7 @@ IncomingMessage.prototype._onXHRProgress = function () { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"./capability":231,"_process":210,"buffer":188,"inherits":195,"readable-stream":225}],234:[function(require,module,exports){ +},{"./capability":227,"_process":206,"buffer":184,"inherits":191,"readable-stream":221}],230:[function(require,module,exports){ 'use strict'; var Buffer = require('safe-buffer').Buffer; @@ -159974,7 +158045,7 @@ function simpleWrite(buf) { function simpleEnd(buf) { return buf && buf.length ? this.write(buf) : ''; } -},{"safe-buffer":228}],235:[function(require,module,exports){ +},{"safe-buffer":224}],231:[function(require,module,exports){ var Buffer = require('buffer').Buffer module.exports = function (buf) { @@ -160003,7 +158074,7 @@ module.exports = function (buf) { } } -},{"buffer":188}],236:[function(require,module,exports){ +},{"buffer":184}],232:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -160737,7 +158808,7 @@ Url.prototype.parseHost = function() { if (host) this.hostname = host; }; -},{"./util":237,"punycode":211,"querystring":214}],237:[function(require,module,exports){ +},{"./util":233,"punycode":207,"querystring":210}],233:[function(require,module,exports){ 'use strict'; module.exports = { @@ -160755,7 +158826,7 @@ module.exports = { } }; -},{}],238:[function(require,module,exports){ +},{}],234:[function(require,module,exports){ (function (global){ /** @@ -160826,16 +158897,16 @@ function config (name) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],239:[function(require,module,exports){ -arguments[4][195][0].apply(exports,arguments) -},{"dup":195}],240:[function(require,module,exports){ +},{}],235:[function(require,module,exports){ +arguments[4][191][0].apply(exports,arguments) +},{"dup":191}],236:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],241:[function(require,module,exports){ +},{}],237:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -161425,7 +159496,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":240,"_process":210,"inherits":239}],242:[function(require,module,exports){ +},{"./support/isBuffer":236,"_process":206,"inherits":235}],238:[function(require,module,exports){ module.exports = extend var hasOwnProperty = Object.prototype.hasOwnProperty; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aax.js index 9c71e445f..3b8be7dc2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, ExchangeNotAvailable, OrderNotFound, InvalidOrder, CancelPending, RateLimitExceeded, InsufficientFunds, BadRequest, BadSymbol, PermissionDenied } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -35,6 +36,7 @@ module.exports = class aax extends Exchange { 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, + 'fetchStatus': true, 'fetchTicker': 'emulated', 'fetchTickers': true, 'fetchTrades': true, @@ -233,6 +235,37 @@ module.exports = class aax extends Exchange { }); } + async fetchStatus (params = {}) { + const response = await this.publicGetAnnouncementMaintenance (params); + // + // { + // "code": 1, + // "data": { + // "startTime":"2020-06-25T02:15:00.000Z", + // "endTime":"2020-06-25T02:45:00.000Z", + // "description":"Spot Trading :UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45),Futures Trading: UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45).We apologize for any inconvenience caused. Thank you for your patience and understanding.Should you have any enquiries, please do not hesitate our live chat support or via email at cs@aax.com." + // }, + // "message":"success", + // "ts":1593043237000 + // } + // + const data = this.safeValue (response, 'data', {}); + const timestamp = this.milliseconds (); + const startTime = this.parse8601 (this.safeString (data, 'startTime')); + const endTime = this.parse8601 (this.safeString (data, 'endTime')); + const update = { + 'updated': this.safeInteger (response, 'ts', timestamp), + }; + if (endTime !== undefined) { + const startTimeIsOk = (startTime === undefined) ? true : (timestamp < startTime); + const isOk = (timestamp > endTime) || startTimeIsOk; + update['eta'] = endTime; + update['status'] = isOk ? 'ok' : 'maintenance'; + } + this.status = this.extend (this.status, update); + return this.status; + } + async fetchMarkets (params = {}) { const response = await this.publicGetInstruments (params); // @@ -318,8 +351,8 @@ module.exports = class aax extends Exchange { const quote = this.safeCurrencyCode (quoteId); const status = this.safeString (market, 'status'); const active = (status === 'enable'); - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); const type = this.safeString (market, 'type'); let inverse = undefined; let linear = undefined; @@ -337,8 +370,8 @@ module.exports = class aax extends Exchange { symbol = base + '/' + quote; } const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; result.push ({ 'id': id, @@ -396,8 +429,8 @@ module.exports = class aax extends Exchange { const timestamp = this.safeInteger (ticker, 't'); const marketId = this.safeString (ticker, 's'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'c'); - const open = this.safeFloat (ticker, 'o'); + const last = this.safeNumber (ticker, 'c'); + const open = this.safeNumber (ticker, 'o'); let change = undefined; let percentage = undefined; let average = undefined; @@ -408,13 +441,13 @@ module.exports = class aax extends Exchange { } average = this.sum (last, open) / 2; } - const quoteVolume = this.safeFloat (ticker, 'v'); + const quoteVolume = this.safeNumber (ticker, 'v'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'h'), - 'low': this.safeFloat (ticker, 'l'), + 'high': this.safeNumber (ticker, 'h'), + 'low': this.safeNumber (ticker, 'l'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -561,8 +594,8 @@ module.exports = class aax extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let price = this.safeFloat2 (trade, 'p', 'filledPrice'); - const amount = this.safeFloat2 (trade, 'q', 'filledQty'); + let priceString = this.safeString2 (trade, 'p', 'filledPrice'); + const amountString = this.safeString2 (trade, 'q', 'filledQty'); const orderId = this.safeString (trade, 'orderID'); const isTaker = this.safeValue (trade, 'taker'); let takerOrMaker = undefined; @@ -576,17 +609,15 @@ module.exports = class aax extends Exchange { side = 'sell'; } if (side === undefined) { - side = (price > 0) ? 'buy' : 'sell'; - } - side = (price > 0) ? 'buy' : 'sell'; - price = Math.abs (price); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; + side = (priceString[0] === '-') ? 'sell' : 'buy'; } + priceString = (priceString[0] === '-') ? priceString.slice (1) : priceString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderType = this.parseOrderType (this.safeString (trade, 'orderType')); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -654,11 +685,11 @@ module.exports = class aax extends Exchange { // return [ this.safeTimestamp (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -743,12 +774,12 @@ module.exports = class aax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'unavailable'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'unavailable'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -776,7 +807,7 @@ module.exports = class aax extends Exchange { request['clOrdID'] = clientOrderId; params = this.omit (params, [ 'clOrdID', 'clientOrderId' ]); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { if ((orderType === 'STOP-LIMIT') || (orderType === 'STOP')) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for ' + orderType + ' orders'); @@ -894,7 +925,7 @@ module.exports = class aax extends Exchange { // 'price': this.priceToPrecision (symbol, price), // 'stopPrice': this.priceToPrecision (symbol, stopPrice), }; - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1531,15 +1562,18 @@ module.exports = class aax extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const price = this.safeFloat (order, 'price'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const price = this.safeNumber (order, 'price'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'Post-Only'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeString (order, 'leavesQty'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + let remaining = this.safeNumber (order, 'leavesQty'); + if ((filled === 0) && (remaining === 0)) { + remaining = undefined; + } let cost = undefined; let lastTradeTimestamp = undefined; if (filled !== undefined) { @@ -1554,7 +1588,7 @@ module.exports = class aax extends Exchange { } } let fee = undefined; - const feeCost = this.safeFloat (order, 'commission'); + const feeCost = this.safeNumber (order, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/acx.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/acx.js deleted file mode 100644 index e10ec85ca..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/acx.js +++ /dev/null @@ -1,487 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { InsufficientFunds, OrderNotFound } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class acx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'acx', - 'name': 'ACX', - 'countries': [ 'AU' ], - 'rateLimit': 1000, - 'version': 'v2', - 'has': { - 'cancelOrder': true, - 'CORS': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchMarkets': true, - 'fetchOHLCV': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTime': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '12h': '720', - '1d': '1440', - '3d': '4320', - '1w': '10080', - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg', - 'extension': '.json', - 'api': 'https://acx.io/api', - 'www': 'https://acx.io', - 'doc': 'https://acx.io/documents/api_v2', - }, - 'api': { - 'public': { - 'get': [ - 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. - 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator - 'k', // Get OHLC(k line) of specific market - 'markets', // Get all available markets - 'order_book', // Get the order book of specified market - 'order_book/{market}', - 'tickers', // Get ticker of all markets - 'tickers/{market}', // Get ticker of specific market - 'timestamp', // Get server current time, in seconds since Unix epoch - 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. - 'trades/{market}', - ], - }, - 'private': { - 'get': [ - 'members/me', // Get your profile and accounts info - 'deposits', // Get your deposits history - 'deposit', // Get details of specific deposit - 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. - 'orders', // Get your orders, results is paginated - 'order', // Get information of specified order - 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. - 'withdraws', // Get your cryptocurrency withdraws - 'withdraw', // Get your cryptocurrency withdraw - ], - 'post': [ - 'orders', // Create a Sell/Buy order - 'orders/multi', // Create multiple sell/buy orders - 'orders/clear', // Cancel all my orders - 'order/delete', // Cancel an order - 'withdraw', // Create a withdraw - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': false, - 'percentage': true, - 'maker': 0.2 / 100, - 'taker': 0.2 / 100, - }, - 'funding': { - 'tierBased': false, - 'percentage': true, - 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account. - }, - }, - 'commonCurrencies': { - 'PLA': 'Plair', - }, - 'exceptions': { - '2002': InsufficientFunds, - '2003': OrderNotFound, - }, - }); - } - - async fetchMarkets (params = {}) { - const markets = await this.publicGetMarkets (params); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = market['id']; - const symbol = market['name']; - let baseId = this.safeString (market, 'base_unit'); - let quoteId = this.safeString (market, 'quote_unit'); - if ((baseId === undefined) || (quoteId === undefined)) { - const ids = symbol.split ('/'); - baseId = ids[0].toLowerCase (); - quoteId = ids[1].toLowerCase (); - } - let base = baseId.toUpperCase (); - let quote = quoteId.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - // todo: find out their undocumented precision and limits - const precision = { - 'amount': 8, - 'price': 8, - }; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'precision': precision, - 'info': market, - 'active': undefined, - 'limits': this.limits, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetMembersMe (params); - const balances = this.safeValue (response, 'accounts'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 300 - } - const orderbook = await this.publicGetDepth (this.extend (request, params)); - const timestamp = this.safeTimestamp (orderbook, 'timestamp'); - return this.parseOrderBook (orderbook, timestamp); - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.safeTimestamp (ticker, 'at'); - ticker = ticker['ticker']; - let symbol = undefined; - if (market) { - symbol = market['symbol']; - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetTickers (params); - const ids = Object.keys (response); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let market = undefined; - let symbol = id; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } else { - let base = id.slice (0, 3); - let quote = id.slice (3, 6); - base = base.toUpperCase (); - quote = quote.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - symbol = base + '/' + quote; - } - result[symbol] = this.parseTicker (response[id], market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTickersMarket (this.extend (request, params)); - return this.parseTicker (response, market); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const id = this.safeString (trade, 'tid'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': undefined, - 'side': undefined, - 'order': undefined, - 'takerOrMaker': undefined, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), - 'cost': this.safeFloat (trade, 'funds'), - 'fee': undefined, - }; - } - - async fetchTime (params = {}) { - const response = await this.publicGetTimestamp (params); - // - // 1594911427 - // - return response * 1000; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - return [ - this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (limit === undefined) { - limit = 500; // default is 30 - } - const request = { - 'market': market['id'], - 'period': this.timeframes[timeframe], - 'limit': limit, - }; - if (since !== undefined) { - request['timestamp'] = parseInt (since / 1000); - } - const response = await this.publicGetK (this.extend (request, params)); - return this.parseOHLCVs (response, market, timeframe, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'done': 'closed', - 'wait': 'open', - 'cancel': 'canceled', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - const marketId = this.safeString (order, 'market'); - const symbol = this.safeSymbol (marketId, market); - const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const status = this.parseOrderStatus (this.safeString (order, 'state')); - const type = this.safeString (order, 'type'); - const side = this.safeString (order, 'side'); - const id = this.safeString (order, 'id'); - return { - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': this.safeFloat (order, 'price'), - 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'volume'), - 'filled': this.safeFloat (order, 'executed_volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'trades': undefined, - 'fee': undefined, - 'info': order, - 'cost': undefined, - 'average': undefined, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': parseInt (id), - }; - const response = await this.privateGetOrder (this.extend (request, params)); - return this.parseOrder (response); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'market': this.marketId (symbol), - 'side': side, - 'volume': amount.toString (), - 'ord_type': type, - }; - if (type === 'limit') { - request['price'] = price.toString (); - } - const response = await this.privatePostOrders (this.extend (request, params)); - const marketId = this.safeValue (response, 'market'); - const market = this.safeValue (this.markets_by_id, marketId); - return this.parseOrder (response, market); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - const response = await this.privatePostOrderDelete (this.extend (request, params)); - const order = this.parseOrder (response); - const status = order['status']; - if (status === 'closed' || status === 'canceled') { - throw new OrderNotFound (this.id + ' ' + this.json (order)); - } - return order; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - // they have XRP but no docs on memo/tag - const request = { - 'currency': currency['id'], - 'sum': amount, - 'address': address, - }; - const response = await this.privatePostWithdraw (this.extend (request, params)); - // withdrawal response is undocumented - return { - 'info': response, - 'id': undefined, - }; - } - - nonce () { - return this.milliseconds (); - } - - encodeParams (params) { - if ('orders' in params) { - const orders = params['orders']; - let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); - for (let i = 0; i < orders.length; i++) { - const order = orders[i]; - const keys = Object.keys (order); - for (let k = 0; k < keys.length; k++) { - const key = keys[k]; - const value = order[key]; - query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); - } - } - return query; - } - return this.urlencode (this.keysort (params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let request = '/api/' + this.version + '/' + this.implodeParams (path, params); - if ('extension' in this.urls) { - request += this.urls['extension']; - } - const query = this.omit (params, this.extractParams (path)); - let url = this.urls['api'] + request; - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce ().toString (); - const query = this.encodeParams (this.extend ({ - 'access_key': this.apiKey, - 'tonce': nonce, - }, params)); - const auth = method + '|' + request + '|' + query; - const signed = this.hmac (this.encode (auth), this.encode (this.secret)); - const suffix = query + '&signature=' + signed; - if (method === 'GET') { - url += '?' + suffix; - } else { - body = suffix; - headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; - } - if (code === 400) { - const error = this.safeValue (response, 'error'); - const errorCode = this.safeString (error, 'code'); - const feedback = this.id + ' ' + this.json (response); - this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); - // fallback to default error handler - } - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aofex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aofex.js index 7899f09d5..69264394e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aofex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/aofex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, BadSymbol, InvalidOrder, PermissionDenied, InvalidAddress, AuthenticationError, InvalidNonce, BadRequest, InsufficientFunds, OrderNotFound } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -193,8 +194,8 @@ module.exports = class aofex extends Exchange { const symbol = base + '/' + quote; const numericId = this.safeInteger (market, 'id'); const precision = this.safeValue (precisions, id, {}); - const makerFee = this.safeFloat (market, 'maker_fee'); - const takerFee = this.safeFloat (market, 'taker_fee'); + const makerFee = this.safeNumber (market, 'maker_fee'); + const takerFee = this.safeNumber (market, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -212,12 +213,12 @@ module.exports = class aofex extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -245,11 +246,11 @@ module.exports = class aofex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -328,11 +329,11 @@ module.exports = class aofex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -355,8 +356,8 @@ module.exports = class aofex extends Exchange { return { 'info': response, 'symbol': symbol, - 'maker': this.safeFloat (result, 'fromFee'), - 'taker': this.safeFloat (result, 'toFee'), + 'maker': this.safeNumber (result, 'fromFee'), + 'taker': this.safeNumber (result, 'toFee'), }; } @@ -413,8 +414,8 @@ module.exports = class aofex extends Exchange { if (market) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); let change = undefined; if (symbol !== undefined) { change = parseFloat (this.priceToPrecision (symbol, last - open)); @@ -423,8 +424,8 @@ module.exports = class aofex extends Exchange { } const average = this.sum (last, open) / 2; const percentage = change / open * 100; - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); let vwap = this.vwap (baseVolume, quoteVolume); if (vwap !== undefined) { vwap = parseFloat (this.priceToPrecision (symbol, vwap)); @@ -433,8 +434,8 @@ module.exports = class aofex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -552,13 +553,15 @@ module.exports = class aofex extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'number'); - let cost = this.safeFloat (trade, 'total_price'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'number'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total_price'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -702,21 +705,21 @@ module.exports = class aofex extends Exchange { const orderType = this.safeString (order, 'type'); const type = (orderType === '2') ? 'limit' : 'market'; const side = this.safeString (order, 'side'); - // const amount = this.safeFloat (order, 'number'); - // const price = this.safeFloat (order, 'price'); + // const amount = this.safeNumber (order, 'number'); + // const price = this.safeNumber (order, 'price'); let cost = undefined; let price = undefined; let amount = undefined; let average = undefined; - const number = this.safeFloat (order, 'number'); - const totalPrice = this.safeFloat (order, 'total_price'); + const number = this.safeNumber (order, 'number'); + const totalPrice = this.safeNumber (order, 'total_price'); if (type === 'limit') { amount = number; - price = this.safeFloat (order, 'price'); + price = this.safeNumber (order, 'price'); } else { - average = this.safeFloat (order, 'deal_price'); + average = this.safeNumber (order, 'deal_price'); if (side === 'buy') { - amount = this.safeFloat (order, 'deal_number'); + amount = this.safeNumber (order, 'deal_number'); } else { amount = number; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ascendex.js similarity index 93% rename from Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmax.js rename to Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ascendex.js index 62cbf55d5..753148db2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ascendex.js @@ -4,16 +4,17 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class bitmax extends Exchange { +module.exports = class ascendex extends Exchange { describe () { return this.deepExtend (super.describe (), { - 'id': 'bitmax', - 'name': 'BitMax', - 'countries': [ 'CN' ], // China + 'id': 'ascendex', + 'name': 'AscendEX', + 'countries': [ 'SG', 'CN' ], // Singapore, China 'rateLimit': 500, // new metainfo interface 'has': { @@ -55,14 +56,14 @@ module.exports = class bitmax extends Exchange { }, 'version': 'v1', 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg', - 'api': 'https://bitmax.io', + 'logo': 'https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg', + 'api': 'https://ascendex.com', 'test': 'https://bitmax-test.io', - 'www': 'https://bitmax.io', + 'www': 'https://ascendex.com', 'doc': [ 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', ], - 'fees': 'https://bitmax.io/#/feeRate/tradeRate', + 'fees': 'https://ascendex.com/en/feerate/transactionfee-traderate', 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', }, 'api': { @@ -131,6 +132,7 @@ module.exports = class bitmax extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'taker': 0.002, @@ -212,6 +214,7 @@ module.exports = class bitmax extends Exchange { 'broad': {}, }, 'commonCurrencies': { + 'BOND': 'BONDED', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', }, @@ -294,7 +297,7 @@ module.exports = class bitmax extends Exchange { const code = this.safeCurrencyCode (id); const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); // why would the exchange API have different names for the same field - const fee = this.safeFloat2 (currency, 'withdrawFee', 'withdrawalFee'); + const fee = this.safeNumber2 (currency, 'withdrawFee', 'withdrawalFee'); const status = this.safeString2 (currency, 'status', 'statusCode'); const active = (status === 'Normal'); const margin = ('borrowAssetCode' in currency); @@ -322,7 +325,7 @@ module.exports = class bitmax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawalAmt'), + 'min': this.safeNumber (currency, 'minWithdrawalAmt'), 'max': undefined, }, }, @@ -423,8 +426,8 @@ module.exports = class bitmax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'Normal'); @@ -450,16 +453,16 @@ module.exports = class bitmax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minQty'), - 'max': this.safeFloat (market, 'maxQty'), + 'min': this.safeNumber (market, 'minQty'), + 'max': this.safeNumber (market, 'maxQty'), }, 'price': { - 'min': this.safeFloat (market, 'tickSize'), + 'min': this.safeNumber (market, 'tickSize'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minNotional'), - 'max': this.safeFloat (market, 'maxNotional'), + 'min': this.safeNumber (market, 'minNotional'), + 'max': this.safeNumber (market, 'maxNotional'), }, }, }); @@ -467,28 +470,6 @@ module.exports = class bitmax extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - // TODO: fee calculation here is incorrect, we need to support tiered fee calculation. - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { let accountGroup = this.safeString (this.options, 'account-group'); let response = undefined; @@ -593,11 +574,11 @@ module.exports = class bitmax extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -669,10 +650,10 @@ module.exports = class bitmax extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', []); const ask = this.safeValue (ticker, 'ask', []); - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; let average = undefined; @@ -687,12 +668,12 @@ module.exports = class bitmax extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 0), - 'bidVolume': this.safeFloat (bid, 1), - 'ask': this.safeFloat (ask, 0), - 'askVolume': this.safeFloat (ask, 1), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 0), + 'bidVolume': this.safeNumber (bid, 1), + 'ask': this.safeNumber (ask, 0), + 'askVolume': this.safeNumber (ask, 1), 'vwap': undefined, 'open': open, 'close': close, @@ -701,20 +682,12 @@ module.exports = class bitmax extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -791,11 +764,11 @@ module.exports = class bitmax extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.safeInteger (data, 'ts'), - this.safeFloat (data, 'o'), - this.safeFloat (data, 'h'), - this.safeFloat (data, 'l'), - this.safeFloat (data, 'c'), - this.safeFloat (data, 'v'), + this.safeNumber (data, 'o'), + this.safeNumber (data, 'h'), + this.safeNumber (data, 'l'), + this.safeNumber (data, 'c'), + this.safeNumber (data, 'v'), ]; } @@ -860,12 +833,11 @@ module.exports = class bitmax extends Exchange { // } // const timestamp = this.safeInteger (trade, 'ts'); - const price = this.safeFloat2 (trade, 'price', 'p'); - const amount = this.safeFloat (trade, 'q'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString2 (trade, 'price', 'p'); + const amountString = this.safeString (trade, 'q'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const buyerIsMaker = this.safeValue (trade, 'bm', false); const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; const side = buyerIsMaker ? 'buy' : 'sell'; @@ -989,26 +961,12 @@ module.exports = class bitmax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '/'); - let timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); - let lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const average = this.safeFloat (order, 'avgPx'); - const filled = this.safeFloat2 (order, 'cumFilledQty', 'cumQty'); - let remaining = undefined; - if (filled !== undefined) { - if (filled === 0) { - timestamp = lastTradeTimestamp; - lastTradeTimestamp = undefined; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - let cost = undefined; - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } + const timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); + const lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const average = this.safeNumber (order, 'avgPx'); + const filled = this.safeNumber2 (order, 'cumFilledQty', 'cumQty'); const id = this.safeString (order, 'orderId'); let clientOrderId = this.safeString (order, 'id'); if (clientOrderId !== undefined) { @@ -1018,7 +976,7 @@ module.exports = class bitmax extends Exchange { } const type = this.safeStringLower (order, 'orderType'); const side = this.safeStringLower (order, 'side'); - const feeCost = this.safeFloat (order, 'cumFee'); + const feeCost = this.safeNumber (order, 'cumFee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeAsset'); @@ -1028,8 +986,8 @@ module.exports = class bitmax extends Exchange { 'currency': feeCurrencyCode, }; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1044,14 +1002,14 @@ module.exports = class bitmax extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1088,7 +1046,7 @@ module.exports = class bitmax extends Exchange { request['orderPrice'] = this.priceToPrecision (symbol, price); } if ((type === 'stop_limit') || (type === 'stop_market')) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); } else { @@ -1624,7 +1582,7 @@ module.exports = class bitmax extends Exchange { // } // const id = this.safeString (transaction, 'requestId'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const destAddress = this.safeValue (transaction, 'destAddress', {}); const address = this.safeString (destAddress, 'address'); const tag = this.safeString (destAddress, 'destTag'); @@ -1634,7 +1592,7 @@ module.exports = class bitmax extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'commission'); + const feeCost = this.safeNumber (transaction, 'commission'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Exchange.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Exchange.js index eb017b5bf..0cf2c9fb0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Exchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Exchange.js @@ -44,6 +44,7 @@ const { // eslint-disable-line object-curly-newline const { TRUNCATE, ROUND, DECIMAL_PLACES, NO_PADDING } = functions.precisionConstants const BN = require ('../static_dependencies/BN/bn') +const Precise = require ('./Precise') // ---------------------------------------------------------------------------- @@ -224,6 +225,11 @@ module.exports = class Exchange { this.minFundingAddressLength = 1 // used in checkAddress this.substituteCommonCurrencyCodes = true // reserved + this.quoteJsonNumbers = true // treat numbers in json as quoted precise strings + this.number = Number // or String (a pointer to a function) + + // whether fees should be summed by currency code + this.reduceFees = true // do not delete this line, it is needed for users to be able to define their own fetchImplementation this.fetchImplementation = defaultFetch @@ -519,7 +525,7 @@ module.exports = class Exchange { parseJson (jsonString) { try { if (this.isJsonEncodedObject (jsonString)) { - return JSON.parse (jsonString) + return JSON.parse (this.onJsonResponse (jsonString)) } } catch (e) { // SyntaxError @@ -598,7 +604,11 @@ module.exports = class Exchange { } onRestResponse (statusCode, statusText, url, method, responseHeaders, responseBody, requestHeaders, requestBody) { - return responseBody.trim ().replace (/:(\d{15,}),/g, ':"$1",'); + return responseBody.trim () + } + + onJsonResponse (responseBody) { + return this.quoteJsonNumbers ? responseBody.replace (/":([+.0-9eE-]+),/g, '":"$1",') : responseBody; } setMarkets (markets, currencies = undefined) { @@ -918,8 +928,8 @@ module.exports = class Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = parseFloat (bidask[priceKey]) - const amount = parseFloat (bidask[amountKey]) + const price = this.safeNumber (bidask, priceKey) + const amount = this.safeNumber (bidask, amountKey) return [ price, amount ] } @@ -945,7 +955,7 @@ module.exports = class Exchange { } } - parseBalance (balance) { + parseBalance (balance, legacy = true) { const codes = Object.keys (this.omit (balance, [ 'info', 'free', 'used', 'total' ])); @@ -957,20 +967,34 @@ module.exports = class Exchange { const code = codes[i] if (balance[code].total === undefined) { if (balance[code].free !== undefined && balance[code].used !== undefined) { - balance[code].total = this.sum (balance[code].free, balance[code].used) + if (legacy) { + balance[code].total = this.sum (balance[code].free, balance[code].used) + } else { + balance[code].total = Precise.stringAdd (balance[code].free, balance[code].used) + } } } if (balance[code].free === undefined) { if (balance[code].total !== undefined && balance[code].used !== undefined) { - balance[code].free = this.sum (balance[code].total, -balance[code].used) + if (legacy) { + balance[code].free = this.sum (balance[code].total, -balance[code].used) + } else { + balance[code].free = Precise.stringSub (balance[code].total, balance[code].used) + } } } if (balance[code].used === undefined) { if (balance[code].total !== undefined && balance[code].free !== undefined) { - balance[code].used = this.sum (balance[code].total, -balance[code].free) + if (legacy) { + balance[code].used = this.sum (balance[code].total, -balance[code].free) + } else { + balance[code].used = Precise.stringSub (balance[code].total, balance[code].free) + } } } - + balance[code].free = this.parseNumber (balance[code].free) + balance[code].used = this.parseNumber (balance[code].used) + balance[code].total = this.parseNumber (balance[code].total) balance.free[code] = balance[code].free balance.used[code] = balance[code].used balance.total[code] = balance[code].total @@ -979,6 +1003,10 @@ module.exports = class Exchange { return balance } + async fetchBalance (params = {}) { + throw new NotSupported (this.id + ' fetchBalance not supported yet') + } + async fetchPartialBalance (part, params = {}) { const balance = await this.fetchBalance (params) return balance[part] @@ -1088,11 +1116,27 @@ module.exports = class Exchange { return indexed ? indexBy (result, key) : result } + parseTickers (tickers, symbols = undefined) { + const result = []; + for (let i = 0; i < tickers.length; i++) { + result.push (this.parseTicker (tickers[i])); + } + return this.filterByArray (result, 'symbol', symbols); + } + + parseDepositAddresses (addresses, codes = undefined) { + let result = []; + for (let i = 0; i < addresses.length; i++) { + const address = this.parseDepositAddress (addresses[i]); + result.push (address); + } + if (codes) { + result = this.filterByArray (result, 'currency', codes); + } + return this.indexBy (result, 'currency'); + } + parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (trades)) { - // throw new ExchangeError (this.id + ' parseTrades expected an array in the trades argument, but got ' + typeof trades); - // } let result = Object.values (trades || []).map ((trade) => this.extend (this.parseTrade (trade, market), params)) result = sortBy (result, 'timestamp') const symbol = (market !== undefined) ? market['symbol'] : undefined @@ -1101,10 +1145,6 @@ module.exports = class Exchange { } parseTransactions (transactions, currency = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (transactions)) { - // throw new ExchangeError (this.id + ' parseTransactions expected an array in the transactions argument, but got ' + typeof transactions); - // } let result = Object.values (transactions || []).map ((transaction) => this.extend (this.parseTransaction (transaction, currency), params)) result = this.sortBy (result, 'timestamp'); const code = (currency !== undefined) ? currency['code'] : undefined; @@ -1112,6 +1152,14 @@ module.exports = class Exchange { return this.filterByCurrencySinceLimit (result, code, since, limit, tail); } + parseTransfers (transfers, currency = undefined, since = undefined, limit = undefined, params = {}) { + let result = Object.values (transfers || []).map ((transfer) => this.extend (this.parseTransfer (transfer, currency), params)) + result = this.sortBy (result, 'timestamp'); + const code = (currency !== undefined) ? currency['code'] : undefined; + const tail = since === undefined; + return this.filterByCurrencySinceLimit (result, code, since, limit, tail); + } + parseLedger (data, currency = undefined, since = undefined, limit = undefined, params = {}) { let result = []; const array = Object.values (data || []); @@ -1256,19 +1304,19 @@ module.exports = class Exchange { return this.createOrder (symbol, ...args) } - createLimitOrder (symbol, side, amount, price = undefined, params = {}) { + createLimitOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'limit', side, amount, price, params) } - createMarketOrder (symbol, side, amount, price = undefined, params = {}) { + createMarketOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'market', side, amount, price, params) } - createLimitBuyOrder (symbol, amount, price = undefined, params = {}) { + createLimitBuyOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'buy', amount, price, params) } - createLimitSellOrder (symbol, amount, price = undefined, params = {}) { + createLimitSellOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'sell', amount, price, params) } @@ -1301,15 +1349,43 @@ module.exports = class Exchange { } calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol] - const rate = market[takerOrMaker] - const cost = parseFloat (this.costToPrecision (symbol, amount * price)) + const market = this.markets[symbol]; + const feeSide = this.safeString (market, 'feeSide', 'quote'); + let key = 'quote'; + let cost = undefined; + if (feeSide === 'quote') { + // the fee is always in quote currency + cost = amount * price; + } else if (feeSide === 'base') { + // the fee is always in base currency + cost = amount; + } else if (feeSide === 'get') { + // the fee is always in the currency you get + cost = amount; + if (side === 'sell') { + cost *= price; + } else { + key = 'base'; + } + } else if (feeSide === 'give') { + // the fee is always in the currency you give + cost = amount; + if (side === 'buy') { + cost *= price; + } else { + key = 'base'; + } + } + const rate = market[takerOrMaker]; + if (cost !== undefined) { + cost *= rate; + } return { 'type': takerOrMaker, - 'currency': market['quote'], + 'currency': market[key], 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, rate * cost)), - } + 'cost': cost, + }; } checkRequiredDependencies () { @@ -1393,6 +1469,25 @@ module.exports = class Exchange { return new BN (a).pow (new BN (b)) } + reduceFeesByCurrency (fees) { + const reduced = {}; + for (let i = 0; i < fees.length; i++) { + const fee = fees[i]; + const feeCurrencyCode = this.safeValue (fee, 'currency'); + if (feeCurrencyCode !== undefined) { + if (feeCurrencyCode in reduced) { + reduced[feeCurrencyCode]['cost'] = this.sum (reduced[feeCurrencyCode]['cost'], fee['cost']); + } else { + reduced[feeCurrencyCode] = { + 'cost': fee['cost'], + 'currency': feeCurrencyCode, + }; + } + } + } + return Object.values (reduced); + } + safeOrder (order) { // Cost // Remaining @@ -1401,65 +1496,143 @@ module.exports = class Exchange { // Amount // Filled // - // First we try to calculate filled from the trades - const parseFilled = order['filled'] === undefined; - const parseCost = order['cost'] === undefined; - if (parseFilled) { - order['filled'] = 0 - } - if (parseCost) { - order['cost'] = 0 - } - if (parseFilled || parseCost) { - if (Array.isArray (order['trades'])) { - for (let i = 0; i < order['trades'].length; i++) { - const trade = order['trades'][i] - if (parseFilled) { - order['filled'] = this.sum (order['filled'], trade['amount']) + // first we try to calculate the order fields from the trades + let amount = this.safeValue (order, 'amount'); + let remaining = this.safeValue (order, 'remaining'); + let filled = this.safeValue (order, 'filled'); + let cost = this.safeValue (order, 'cost'); + let average = this.safeValue (order, 'average'); + let price = this.safeValue (order, 'price'); + let lastTradeTimeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); + const parseFilled = (filled === undefined); + const parseCost = (cost === undefined); + const parseLastTradeTimeTimestamp = (lastTradeTimeTimestamp === undefined); + const parseFee = this.safeValue (order, 'fee') === undefined; + const parseFees = this.safeValue (order, 'fees') === undefined; + const shouldParseFees = parseFee || parseFees; + const fees = shouldParseFees ? [] : undefined; + if (parseFilled || parseCost || shouldParseFees) { + const trades = this.safeValue (order, 'trades'); + if (trades !== undefined) { + if (parseFilled) { + filled = 0; + } + if (parseCost) { + cost = 0; + } + for (let i = 0; i < trades.length; i++) { + const trade = trades[i]; + const tradeAmount = this.safeValue (trade, 'amount'); + if (parseFilled && (tradeAmount !== undefined)) { + filled = this.sum (filled, tradeAmount); } - if (parseCost) { - order['cost'] = this.sum (order['cost'], trade['cost']) + const tradeCost = this.safeValue (trade, 'cost'); + if (parseCost && (tradeCost !== undefined)) { + cost = this.sum (cost, tradeCost); + } + const tradeTimestamp = this.safeValue (trade, 'timestamp'); + if (parseLastTradeTimeTimestamp && (tradeTimestamp !== undefined)) { + if (lastTradeTimeTimestamp === undefined) { + lastTradeTimeTimestamp = tradeTimestamp; + } else { + lastTradeTimeTimestamp = Math.max (lastTradeTimeTimestamp, tradeTimestamp); + } + } + if (shouldParseFees) { + const tradeFees = this.safeValue (trade, 'fees'); + if (tradeFees !== undefined) { + for (let j = 0; j < tradeFees.length; j++) { + const tradeFee = tradeFees[j]; + fees.push (this.extend ({}, tradeFee)); + } + } else { + const tradeFee = this.safeValue (trade, 'fee'); + if (tradeFee !== undefined) { + fees.push (this.extend ({}, tradeFee)); + } + } } } } } - // We ensure amount = filled + remaining - if (order['amount'] === undefined) { - if (order['filled'] !== undefined && order['remaining'] !== undefined) { - order['amount'] = this.sum (order['filled'], order['remaining']) + if (shouldParseFees) { + const reducedFees = this.reduceFees ? this.reduceFeesByCurrency (fees) : fees; + const reducedLength = reducedFees.length; + if (!parseFee && (reducedLength === 0)) { + reducedFees.push (order['fee']); + } + if (parseFees) { + order['fees'] = reducedFees; + } + if (parseFee && (reducedLength === 1)) { + order['fee'] = reducedFees[0]; } } - if (order['filled'] === undefined) { - if (order['amount'] !== undefined && order['remaining'] !== undefined) { - order['filled'] = Math.max (this.sum (order['amount'], -order['remaining']), 0) + if (amount === undefined) { + // ensure amount = filled + remaining + if (filled !== undefined && remaining !== undefined) { + amount = this.sum (filled, remaining); + } else if (this.safeString (order, 'status') === 'closed') { + amount = filled; } } - if (order['remaining'] === undefined) { - if (order['amount'] !== undefined && order['filled'] !== undefined) { - order['remaining'] = Math.max (this.sum (order['amount'], -order['filled']), 0) + if (filled === undefined) { + if (amount !== undefined && remaining !== undefined) { + filled = Math.max (this.sum (amount, -remaining), 0); } } - // We ensure that the average field is calculated correctly - if (order['average'] === undefined) { - if (order['filled'] !== undefined && order['cost'] !== undefined && order['cost'] > 0) { - order['average'] = order['filled'] / order['cost'] + if (remaining === undefined) { + if (amount !== undefined && filled !== undefined) { + remaining = Math.max (this.sum (amount, -filled), 0); } } - // We also ensure the cost field is calculated correctly - const costPriceExists = (order['average'] !== undefined) || (order['price'] !== undefined) - if ((order['filled'] !== undefined) && costPriceExists) { - let costPrice = undefined; - if (order['average'] === undefined) { - costPrice = order['price'] - } else { - costPrice = order['average'] + // ensure that the average field is calculated correctly + if (average === undefined) { + if ((filled !== undefined) && (cost !== undefined) && (cost > 0)) { + average = cost / filled; } - order['cost'] = costPrice * order['filled'] } - // We add support for market orders - if (order['price'] === undefined && order['type'] === 'market') { - order['price'] = order['average'] + // also ensure the cost field is calculated correctly + const costPriceExists = (average !== undefined) || (price !== undefined); + if (parseCost && (filled !== undefined) && costPriceExists) { + cost = (average === undefined) ? (price * filled) : (average * filled); } - return order + // support for market orders + const orderType = this.safeValue (order, 'type'); + const emptyPrice = (price === undefined) || (price === 0.0); + if (emptyPrice && (orderType === 'market')) { + price = average; + } + return this.extend (order, { + 'lastTradeTimestamp': lastTradeTimeTimestamp, + 'price': price, + 'amount': amount, + 'cost': cost, + 'average': average, + 'filled': filled, + 'remaining': remaining, + }); + } + + parseNumber (value, d = undefined) { + if (value === undefined) { + return d + } else { + try { + return this.number (value) + } catch (e) { + return d + } + } + } + + safeNumber (object, key, d = undefined) { + const value = this.safeString (object, key) + return this.parseNumber (value, d) + } + + safeNumber2 (object, key1, key2, d = undefined) { + const value = this.safeString2 (object, key1, key2) + return this.parseNumber (value, d) } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Precise.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Precise.js new file mode 100644 index 000000000..9bf17ad8d --- /dev/null +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/Precise.js @@ -0,0 +1,145 @@ +'use strict' + +const BN = require ('../static_dependencies/BN/bn') + +class Precise { + constructor (number, decimals = 0) { + const isBN = number instanceof BN + const isString = typeof number === 'string' + if (!(isBN || isString)) { + throw new Error ('Precise initiated with something other than a string or BN') + } + if (isBN) { + this.integer = number + this.decimals = decimals + } else { + if (decimals) { + throw new Error ('Cannot set decimals when initializing with a string') + } + let modifier = 0 + number = number.toLowerCase () + if (number.indexOf ('e') > -1) { + [ number, modifier ] = number.split ('e') + modifier = parseInt (modifier) + } + const decimalIndex = number.indexOf ('.') + this.decimals = (decimalIndex > -1) ? number.length - decimalIndex - 1 : 0 + const integerString = number.replace ('.', '') + this.integer = new BN (integerString) + this.decimals = this.decimals - modifier + } + this.base = 10 + this.reduce () + } + + mul (other) { + // other must be another instance of Precise + const integerResult = this.integer.mul (other.integer) + return new Precise (integerResult, this.decimals + other.decimals) + } + + div (other, precision = 18) { + const distance = precision - this.decimals + other.decimals + let numerator + if (distance === 0) { + numerator = this.integer + } else if (distance < 0) { + const exponent = new BN (this.base).pow (new BN (-distance)) + numerator = this.integer.div (exponent) + } else { + const exponent = new BN (this.base).pow (new BN (distance)) + numerator = this.integer.mul (exponent) + } + const result = numerator.div (other.integer) + return new Precise (result, precision) + } + + add (other) { + if (this.decimals === other.decimals) { + const integerResult = this.integer.add (other.integer) + return new Precise (integerResult, this.decimals) + } else { + const [ smaller, bigger ] = + (this.decimals > other.decimals) ? [ other, this ] : [ this, other ] + const exponent = new BN (bigger.decimals - smaller.decimals) + const normalised = smaller.integer.mul (new BN (this.base).pow (exponent)) + const result = normalised.add (bigger.integer) + return new Precise (result, bigger.decimals) + } + } + + sub (other) { + const negative = new Precise (other.integer.neg (), other.decimals) + return this.add (negative) + } + + reduce () { + const zero = new BN (0) + if (this.integer.eq (zero)) { + this.decimals = 0 + return this + } + const base = new BN (this.base) + let divmod = this.integer.divmod (base) + while (divmod.mod.eq (zero)) { + this.integer = divmod.div + this.decimals-- + divmod = this.integer.divmod (base) + } + return this + } + + toString () { + const sign = this.integer.negative ? '-' : '' + const integerArray = Array.from (this.integer.abs ().toString (this.base).padStart (this.decimals, '0')) + const index = integerArray.length - this.decimals + let item + if (index === 0) { + // if we are adding to the front + item = '0.' + } else if (this.decimals < 0) { + item = '0'.repeat (-this.decimals) + } else if (this.decimals === 0) { + item = '' + } else { + item = '.' + } + integerArray.splice (index, 0, item) + return sign + integerArray.join ('') + } + + static stringMul (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).mul (new Precise (string2)).toString () + } + + static stringDiv (string1, string2, precision = 18) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).div (new Precise (string2), precision).toString () + } + + static stringAdd (string1, string2) { + if ((string1 === undefined) && (string2 === undefined)) { + return undefined + } + if (string1 === undefined) { + return string2 + } else if (string2 === undefined) { + return string1 + } + return (new Precise (string1)).add (new Precise (string2)).toString () + } + + static stringSub (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).sub (new Precise (string2)).toString () + } +} + +module.exports = Precise; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/functions/encode.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/functions/encode.js index 0b4331ccf..e64251dbc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/functions/encode.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/base/functions/encode.js @@ -19,7 +19,6 @@ let base58Encoder = null module.exports = { json: (data, params = undefined) => JSON.stringify (data) - , unjson: JSON.parse , isJsonEncodedObject: object => ( (typeof object === 'string') && diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bibox.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bibox.js index 4d46d8f35..ed9826a1a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bibox.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bibox.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AccountSuspended, ArgumentsRequired, AuthenticationError, DDoSProtection, ExchangeNotAvailable, InvalidOrder, OrderNotFound, PermissionDenied, InsufficientFunds, BadSymbol, RateLimitExceeded, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -229,9 +230,9 @@ module.exports = class bibox extends Exchange { const quote = this.safeCurrencyCode (quoteId); symbol = base + '/' + quote; } - const last = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); - const baseVolume = this.safeFloat2 (ticker, 'vol', 'vol24H'); + const last = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); + const baseVolume = this.safeNumber2 (ticker, 'vol', 'vol24H'); let open = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; @@ -245,11 +246,11 @@ module.exports = class bibox extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -260,7 +261,7 @@ module.exports = class bibox extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': baseVolume, - 'quoteVolume': this.safeFloat (ticker, 'amount'), + 'quoteVolume': this.safeNumber (ticker, 'amount'), 'info': ticker, }; } @@ -276,17 +277,6 @@ module.exports = class bibox extends Exchange { return this.parseTicker (response['result'], market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - const ticker = this.parseTicker (rawTickers[i]); - if ((symbols === undefined) || (this.inArray (ticker['symbol'], symbols))) { - tickers.push (ticker); - } - } - return tickers; - } - async fetchTickers (symbols = undefined, params = {}) { const request = { 'cmd': 'marketAll', @@ -319,7 +309,7 @@ module.exports = class bibox extends Exchange { symbol = market['symbol']; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = this.safeString (trade, 'fee_symbol'); if (feeCurrency !== undefined) { if (feeCurrency in this.currencies_by_id) { @@ -329,12 +319,11 @@ module.exports = class bibox extends Exchange { } } const feeRate = undefined; // todo: deduce from market if market is defined - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if (feeCost !== undefined) { fee = { 'cost': -feeCost, @@ -385,7 +374,7 @@ module.exports = class bibox extends Exchange { request['size'] = limit; // default = 200 } const response = await this.publicGetMdata (this.extend (request, params)); - return this.parseOrderBook (response['result'], this.safeFloat (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); + return this.parseOrderBook (response['result'], this.safeNumber (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); } parseOHLCV (ohlcv, market = undefined) { @@ -401,11 +390,11 @@ module.exports = class bibox extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -497,7 +486,7 @@ module.exports = class bibox extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw_min'), + 'min': this.safeNumber (currency, 'withdraw_min'), 'max': undefined, }, }, @@ -629,19 +618,17 @@ module.exports = class bibox extends Exchange { code = this.currencies_by_id[code]['code']; } const account = this.account (); - let balance = indexed[id]; + const balance = indexed[id]; if (typeof balance === 'string') { - balance = parseFloat (balance); account['free'] = balance; - account['used'] = 0.0; account['total'] = balance; } else { - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -732,8 +719,8 @@ module.exports = class bibox extends Exchange { let tag = this.safeString (transaction, 'addr_remark'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'fee'); if (type === 'deposit') { feeCost = 0; tag = undefined; @@ -841,26 +828,19 @@ module.exports = class bibox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const type = (order['order_type'] === 1) ? 'market' : 'limit'; - const timestamp = order['createdAt']; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'deal_price'); - const filled = this.safeFloat (order, 'deal_amount'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat2 (order, 'deal_money', 'money'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - cost = price * filled; - } - } - const side = (order['order_side'] === 1) ? 'buy' : 'sell'; + const rawType = this.safeString (order, 'order_type'); + const type = (rawType === '1') ? 'market' : 'limit'; + const timestamp = this.safeInteger (order, 'createdAt'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'deal_price'); + const filled = this.safeNumber (order, 'deal_amount'); + const amount = this.safeNumber (order, 'amount'); + const cost = this.safeNumber2 (order, 'deal_money', 'money'); + const rawSide = this.safeString (order, 'order_side'); + const side = (rawSide === '1') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -868,8 +848,7 @@ module.exports = class bibox extends Exchange { 'currency': undefined, }; } - cost = cost ? cost : (parseFloat (price) * filled); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -887,11 +866,11 @@ module.exports = class bibox extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -1059,7 +1038,7 @@ module.exports = class bibox extends Exchange { }; const response = await this.privatePostTransfer (request); info[code] = response; - withdrawFees[code] = this.safeFloat (response['result'], 'withdraw_fee'); + withdrawFees[code] = this.safeNumber (response['result'], 'withdraw_fee'); } return { 'info': info, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bigone.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bigone.js index d6e940c4d..f30eec7a4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bigone.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bigone.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, OrderNotFound, InsufficientFunds, PermissionDenied, BadRequest, RateLimitExceeded, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -260,28 +261,28 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (ticker, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = undefined; - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', {}); const ask = this.safeValue (ticker, 'ask', {}); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 'price'), - 'bidVolume': this.safeFloat (bid, 'quantity'), - 'ask': this.safeFloat (ask, 'price'), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 'price'), + 'bidVolume': this.safeNumber (bid, 'quantity'), + 'ask': this.safeNumber (ask, 'price'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'daily_change'), + 'change': this.safeNumber (ticker, 'daily_change'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -446,16 +447,13 @@ module.exports = class bigone extends Exchange { // } // const timestamp = this.parse8601 (this.safeString2 (trade, 'created_at', 'inserted_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } let side = this.safeString (trade, 'side'); const takerSide = this.safeString (trade, 'taker_side'); let takerOrMaker = undefined; @@ -529,8 +527,8 @@ module.exports = class bigone extends Exchange { takerCurrencyCode = market['quote']; } } - const makerFeeCost = this.safeFloat (trade, 'maker_fee'); - const takerFeeCost = this.safeFloat (trade, 'taker_fee'); + const makerFeeCost = this.safeNumber (trade, 'maker_fee'); + const takerFeeCost = this.safeNumber (trade, 'taker_fee'); if (makerFeeCost !== undefined) { if (takerFeeCost !== undefined) { result['fees'] = [ @@ -593,11 +591,11 @@ module.exports = class bigone extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -668,11 +666,11 @@ module.exports = class bigone extends Exchange { const symbol = this.safeString (balance, 'asset_symbol'); const code = this.safeCurrencyCode (symbol); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -694,13 +692,9 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (order, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (amount !== undefined && filled !== undefined) { - remaining = Math.max (0, amount - filled); - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); const status = this.parseOrderStatus (this.safeString (order, 'state')); let side = this.safeString (order, 'side'); if (side === 'BID') { @@ -708,15 +702,9 @@ module.exports = class bigone extends Exchange { } else { side = 'sell'; } - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'updated_at')); - const average = this.safeFloat (order, 'avg_deal_price'); - return { + const average = this.safeNumber (order, 'avg_deal_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -731,14 +719,14 @@ module.exports = class bigone extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -762,7 +750,7 @@ module.exports = class bigone extends Exchange { const isStopLimit = (uppercaseType === 'STOP_LIMIT'); const isStopMarket = (uppercaseType === 'STOP_MARKET'); if (isStopLimit || isStopMarket) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price parameter'); } @@ -1101,7 +1089,7 @@ module.exports = class bigone extends Exchange { const currencyId = this.safeString (transaction, 'asset_symbol'); const code = this.safeCurrencyCode (currencyId); const id = this.safeInteger (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const timestamp = this.parse8601 (this.safeString (transaction, 'inserted_at')); const updated = this.parse8601 (this.safeString2 (transaction, 'updated_at', 'completed_at')); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/binance.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/binance.js index a115b3f7b..a5865c442 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/binance.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/binance.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, NotSupported, BadRequest, BadSymbol, AccountSuspended, OrderImmediatelyFillable } = require ('./base/errors'); -const { ROUND, TRUNCATE } = require ('./base/functions/number'); +const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -47,6 +48,8 @@ module.exports = class binance extends Exchange { 'fetchTransactions': false, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, + 'fetchTransfers': true, }, 'timeframes': { '1m': '1m', @@ -195,6 +198,26 @@ module.exports = class binance extends Exchange { 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/recentRecord', 'apiReferral/kickback/historicalRecord', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccount', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/info', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/recentRecord', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/status', + 'broker/subAccount/depositHist', + 'broker/subAccount/spotSummary', + 'broker/subAccount/marginSummary', + 'broker/subAccount/futuresSummary', + 'broker/rebate/futures/recentRecord', + 'broker/subAccountApi/ipRestriction', + 'broker/universalTransfer', + // v2 not supported yet + // GET /sapi/v2/broker/subAccount/futuresSummary ], 'post': [ 'asset/dust', @@ -234,11 +257,30 @@ module.exports = class binance extends Exchange { // leveraged token endpoints 'blvt/subscribe', 'blvt/redeem', - // broker api + // brokerage API 'apiReferral/customization', 'apiReferral/userCustomization', 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/historicalRecord', + 'broker/subAccount', + 'broker/subAccount/margin', + 'broker/subAccount/futures', + 'broker/subAccountApi', + 'broker/subAccountApi/permission', + 'broker/subAccountApi/commission', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/spot', + 'broker/subAccount/bnbBurn/marginInterest', + 'broker/subAccount/blvt', + 'broker/subAccountApi/ipRestriction', + 'broker/subAccountApi/ipRestriction/ipList', + 'broker/universalTransfer', + 'broker/subAccountApi/permission/universalTransfer', + 'broker/subAccountApi/permission/vanillaOptions', ], 'put': [ 'userDataStream', @@ -249,6 +291,9 @@ module.exports = class binance extends Exchange { 'margin/order', 'userDataStream', 'userDataStream/isolated', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccountApi/ipRestriction/ipList', ], }, 'wapi': { @@ -385,6 +430,8 @@ module.exports = class binance extends Exchange { 'positionSide/dual', 'userTrades', 'income', + 'commissionRate', + 'apiTradingStatus', // broker endpoints 'apiReferral/ifNewUser', 'apiReferral/customization', @@ -474,6 +521,7 @@ module.exports = class binance extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.001, @@ -498,7 +546,7 @@ module.exports = class binance extends Exchange { 'parseOrderToPrecision': false, // force amounts and costs in parseOrder to precision 'newOrderRespType': { 'market': 'FULL', // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills - 'limit': 'RESULT', // we change it from 'ACK' by default to 'RESULT' + 'limit': 'FULL', // we change it from 'ACK' by default to 'FULL' (returns immediately if limit is not hit) }, 'quoteOrderQty': true, // whether market orders support amounts in quote currency 'broker': { @@ -507,6 +555,25 @@ module.exports = class binance extends Exchange { 'future': 'x-xcKtGhcu', 'delivery': 'x-xcKtGhcu', }, + 'fetchPositions': { + 'future': 'fapiPrivateV2GetAccount', // 'fapiPrivateGetPositionRisk' + 'delivery': 'dapiPrivateGetAccount', // 'dapiPrivateGetPositionRisk' + }, + 'accountsByType': { + 'main': 'MAIN', + 'spot': 'MAIN', + 'margin': 'MARGIN', + 'future': 'UMFUTURE', + 'delivery': 'CMFUTURE', + 'mining': 'MINING', + }, + 'typesByAccount': { + 'MAIN': 'spot', + 'MARGIN': 'margin', + 'UMFUTURE': 'future', + 'CMFUTURE': 'delivery', + 'MINING': 'mining', + }, }, // https://binance-docs.github.io/apidocs/spot/en/#error-codes-2 'exceptions': { @@ -564,6 +631,8 @@ module.exports = class binance extends Exchange { '-3010': ExchangeError, // {"code":-3010,"msg":"Repay not allowed. Repay amount exceeds borrow amount."} '-3022': AccountSuspended, // You account's trading is banned. '-4028': BadRequest, // {"code":-4028,"msg":"Leverage 100 is not valid"} + '-3020': InsufficientFunds, // {"code":-3020,"msg":"Transfer out amount exceeds max amount."} + '-3041': InsufficientFunds, // {"code":-3041,"msg":"Balance is not enough"} '-5013': InsufficientFunds, // Asset transfer failed: insufficient balance" }, }); @@ -706,13 +775,14 @@ module.exports = class binance extends Exchange { let fee = undefined; for (let j = 0; j < networkList.length; j++) { const networkItem = networkList[j]; - const name = this.safeString (networkItem, 'name'); - const withdrawFee = this.safeFloat (networkItem, 'withdrawFee'); + const network = this.safeString (networkItem, 'network'); + // const name = this.safeString (networkItem, 'name'); + const withdrawFee = this.safeNumber (networkItem, 'withdrawFee'); const depositEnable = this.safeValue (networkItem, 'depositEnable'); const withdrawEnable = this.safeValue (networkItem, 'withdrawEnable'); isDepositEnabled = isDepositEnabled || depositEnable; isWithdrawEnabled = isWithdrawEnabled || withdrawEnable; - fees[name] = withdrawFee; + fees[network] = withdrawFee; const isDefault = this.safeValue (networkItem, 'isDefault'); if (isDefault || fee === undefined) { fee = withdrawFee; @@ -898,7 +968,7 @@ module.exports = class binance extends Exchange { if (this.options['adjustForTimeDifference']) { await this.loadTimeDifference (); } - const markets = this.safeValue (response, 'symbols'); + const markets = this.safeValue (response, 'symbols', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -963,10 +1033,10 @@ module.exports = class binance extends Exchange { // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } @@ -977,47 +1047,26 @@ module.exports = class binance extends Exchange { const stepSize = this.safeString (filter, 'stepSize'); entry['precision']['amount'] = this.precisionFromString (stepSize); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat2 (filter, 'minNotional', 'notional'); + entry['limits']['cost']['min'] = this.safeNumber2 (filter, 'minNotional', 'notional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'spot'); @@ -1188,8 +1237,8 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -1202,13 +1251,13 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['used'] = this.safeFloat (balance, 'initialMargin'); - account['total'] = this.safeFloat2 (balance, 'marginBalance', 'balance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['used'] = this.safeString (balance, 'initialMargin'); + account['total'] = this.safeString2 (balance, 'marginBalance', 'balance'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -1261,36 +1310,36 @@ module.exports = class binance extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'openPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'openPrice'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } async fetchStatus (params = {}) { const response = await this.wapiGetSystemStatus (params); - let status = this.safeValue (response, 'status'); + let status = this.safeString (response, 'status'); if (status !== undefined) { - status = (status === 0) ? 'ok' : 'maintenance'; + status = (status === '0') ? 'ok' : 'maintenance'; this.status = this.extend (this.status, { 'status': status, 'updated': this.milliseconds (), @@ -1319,14 +1368,6 @@ module.exports = class binance extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBidsAsks', 'defaultType', 'spot'); @@ -1381,11 +1422,11 @@ module.exports = class binance extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -1516,8 +1557,11 @@ module.exports = class binance extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -1535,7 +1579,7 @@ module.exports = class binance extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -1548,10 +1592,6 @@ module.exports = class binance extends Exchange { } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } return { 'info': trade, 'timestamp': timestamp, @@ -1670,7 +1710,7 @@ module.exports = class binance extends Exchange { parseOrder (order, market = undefined) { // - // spot + // spot // // { // "symbol": "LTCBTC", @@ -1691,7 +1731,7 @@ module.exports = class binance extends Exchange { // "isWorking": true // } // - // futures + // futures // // { // "symbol": "BTCUSDT", @@ -1709,6 +1749,33 @@ module.exports = class binance extends Exchange { // "updateTime": 1499827319559 // } // + // createOrder with { "newOrderRespType": "FULL" } + // + // { + // "symbol": "BTCUSDT", + // "orderId": 5403233939, + // "orderListId": -1, + // "clientOrderId": "x-R4BD3S825e669e75b6c14f69a2c43e", + // "transactTime": 1617151923742, + // "price": "0.00000000", + // "origQty": "0.00050000", + // "executedQty": "0.00050000", + // "cummulativeQuoteQty": "29.47081500", + // "status": "FILLED", + // "timeInForce": "GTC", + // "type": "MARKET", + // "side": "BUY", + // "fills": [ + // { + // "price": "58941.63000000", + // "qty": "0.00050000", + // "commission": "0.00007050", + // "commissionAsset": "BNB", + // "tradeId": 737466631 + // } + // ] + // } + // const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -1718,80 +1785,26 @@ module.exports = class binance extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); // - Spot/Margin market: cummulativeQuoteQty // - Futures market: cumQuote. // Note this is not the actual cost, since Binance futures uses leverage to calculate margins. - let cost = this.safeFloat2 (order, 'cummulativeQuoteQty', 'cumQuote'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const cost = this.safeNumber2 (order, 'cummulativeQuoteQty', 'cumQuote'); const id = this.safeString (order, 'orderId'); let type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - if (this.options['parseOrderToPrecision']) { - price = parseFloat (this.priceToPrecision (symbol, price)); - } - } - } - } - } else if (type === 'limit_maker') { + if (type === 'limit_maker') { type = 'limit'; } const side = this.safeStringLower (order, 'side'); - let fee = undefined; - let trades = undefined; - const fills = this.safeValue (order, 'fills'); - if (fills !== undefined) { - trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - if (this.options['parseOrderToPrecision']) { - average = parseFloat (this.priceToPrecision (symbol, average)); - } - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const fills = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (fills, market); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1807,13 +1820,13 @@ module.exports = class binance extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1860,8 +1873,11 @@ module.exports = class binance extends Exchange { } else { request['newClientOrderId'] = clientOrderId; } - if (market['spot']) { + if ((orderType === 'spot') || (orderType === 'margin')) { request['newOrderRespType'] = this.safeValue (this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills + } else { + // delivery and future + request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK" } // additional required fields depending on the order type let timeInForceIsRequired = false; @@ -1891,7 +1907,7 @@ module.exports = class binance extends Exchange { if (uppercaseType === 'MARKET') { const quoteOrderQty = this.safeValue (this.options, 'quoteOrderQty', false); if (quoteOrderQty) { - const quoteOrderQty = this.safeFloat (params, 'quoteOrderQty'); + const quoteOrderQty = this.safeNumber (params, 'quoteOrderQty'); const precision = market['precision']['price']; if (quoteOrderQty !== undefined) { request['quoteOrderQty'] = this.decimalToPrecision (quoteOrderQty, TRUNCATE, precision, this.precisionMode); @@ -1911,7 +1927,7 @@ module.exports = class binance extends Exchange { } else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) { stopPriceIsRequired = true; quantityIsRequired = true; - if (market['future']) { + if (market['future'] || market['delivery']) { priceIsRequired = true; } } else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) { @@ -1934,7 +1950,7 @@ module.exports = class binance extends Exchange { stopPriceIsRequired = true; } else if (uppercaseType === 'TRAILING_STOP_MARKET') { quantityIsRequired = true; - const callbackRate = this.safeFloat (params, 'callbackRate'); + const callbackRate = this.safeNumber (params, 'callbackRate'); if (callbackRate === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a callbackRate extra param for a ' + type + ' order'); } @@ -1952,7 +1968,7 @@ module.exports = class binance extends Exchange { request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -2168,10 +2184,15 @@ module.exports = class binance extends Exchange { } } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.fetchBalance (params); - const info = this.safeValue (response, 'info', {}); + const defaultType = this.safeString (this.options, 'defaultType', 'future'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + const options = this.safeValue (this.options, 'fetchPositions', {}); + const defaultMethod = (type === 'delivery') ? 'dapiPrivateGetAccount' : 'fapiPrivateV2GetAccount'; + const method = this.safeString (options, type, defaultMethod); + const response = await this[method] (params); // // futures, delivery // @@ -2214,9 +2235,44 @@ module.exports = class binance extends Exchange { // ] // } // - const positions = this.safeValue2 (info, 'positions', 'userAssets', []); - // todo unify parsePosition/parsePositions - return positions; + // fapiPrivateGetPositionRisk, dapiPrivateGetPositionRisk + // + // [ + // { + // symbol: 'XRPUSD_210625', + // positionAmt: '0', + // entryPrice: '0.00000000', + // markPrice: '0.00000000', + // unRealizedProfit: '0.00000000', + // liquidationPrice: '0', + // leverage: '20', + // maxQty: '500000', + // marginType: 'cross', + // isolatedMargin: '0.00000000', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0', + // isolatedWallet: '0' + // }, + // { + // symbol: 'BTCUSD_210326', + // positionAmt: '1', + // entryPrice: '60665.79999885', + // markPrice: '60696.76856843', + // unRealizedProfit: '0.00000084', + // liquidationPrice: '58034.68208092', + // leverage: '20', + // maxQty: '50', + // marginType: 'isolated', + // isolatedMargin: '0.00008345', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0.00164753', + // isolatedWallet: '0.00008261' + // }, + // ] + // + return this.safeValue (response, 'positions', response); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -2354,7 +2410,7 @@ module.exports = class binance extends Exchange { // const fee = { 'currency': earnedCurrency, - 'cost': this.safeFloat (trade, 'serviceChargeAmount'), + 'cost': this.safeNumber (trade, 'serviceChargeAmount'), }; let symbol = undefined; let amount = undefined; @@ -2362,13 +2418,13 @@ module.exports = class binance extends Exchange { let side = undefined; if (tradedCurrencyIsQuote) { symbol = applicantSymbol; - amount = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); - cost = this.safeFloat (trade, 'amount'); + amount = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); + cost = this.safeNumber (trade, 'amount'); side = 'buy'; } else { symbol = tradedCurrency + '/' + earnedCurrency; - amount = this.safeFloat (trade, 'amount'); - cost = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); + amount = this.safeNumber (trade, 'amount'); + cost = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); side = 'sell'; } let price = undefined; @@ -2541,8 +2597,8 @@ module.exports = class binance extends Exchange { } } const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'transactionFee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'transactionFee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -2569,6 +2625,151 @@ module.exports = class binance extends Exchange { }; } + parseTransferStatus (status) { + const statuses = { + 'CONFIRMED': 'ok', + }; + return this.safeString (statuses, status, status); + } + + parseTransfer (transfer, currency = undefined) { + // + // transfer + // + // { + // "tranId":13526853623 + // } + // + // fetchTransfers + // + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // } + // + const id = this.safeString (transfer, 'tranId'); + const currencyId = this.safeString (transfer, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const amount = this.safeNumber (transfer, 'amount'); + const type = this.safeString (transfer, 'type'); + let fromAccount = undefined; + let toAccount = undefined; + const typesByAccount = this.safeValue (this.options, 'typesByAccount', {}); + if (type !== undefined) { + const parts = type.split ('_'); + fromAccount = this.safeValue (parts, 0); + toAccount = this.safeValue (parts, 1); + fromAccount = this.safeString (typesByAccount, fromAccount, fromAccount); + toAccount = this.safeString (typesByAccount, toAccount, toAccount); + } + const timestamp = this.safeInteger (transfer, 'timestamp'); + const status = this.parseTransferStatus (this.safeString (transfer, 'status')); + return { + 'info': transfer, + 'id': id, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'currency': code, + 'amount': amount, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': status, + }; + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount, fromAccount); + const toId = this.safeString (accountsByType, toAccount, toAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'asset': currency['id'], + 'amount': this.currencyToPrecision (code, amount), + 'type': type, + }; + const response = await this.sapiPostAssetTransfer (this.extend (request, params)); + // + // { + // "tranId":13526853623 + // } + // + const transfer = this.parseTransfer (response, currency); + return this.extend (transfer, { + 'amount': amount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + }); + } + + async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const defaultType = this.safeString2 (this.options, 'fetchTransfers', 'defaultType', 'spot'); + const fromAccount = this.safeString (params, 'fromAccount', defaultType); + const defaultTo = (fromAccount === 'future') ? 'spot' : 'future'; + const toAccount = this.safeString (params, 'toAccount', defaultTo); + let type = this.safeString (params, 'type'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + if (type === undefined) { + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount parameter must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount parameter must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'type': type, + }; + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['size'] = limit; + } + const response = await this.sapiGetAssetTransfer (this.extend (request, params)); + // + // { + // total: 3, + // rows: [ + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // }, + // ] + // } + // + const rows = this.safeValue (response, 'rows', []); + return this.parseTransfers (rows, currency, since, limit); + } + async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -2631,7 +2832,7 @@ module.exports = class binance extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (detail[id], 'withdrawFee'); + withdrawFees[code] = this.safeNumber (detail[id], 'withdrawFee'); } return { 'withdraw': withdrawFees, @@ -2678,8 +2879,8 @@ module.exports = class binance extends Exchange { return { 'info': fee, 'symbol': symbol, - 'maker': this.safeFloat (fee, 'maker'), - 'taker': this.safeFloat (fee, 'taker'), + 'maker': this.safeNumber (fee, 'maker'), + 'taker': this.safeNumber (fee, 'taker'), }; } @@ -2741,7 +2942,6 @@ module.exports = class binance extends Exchange { if (api === 'wapi') { url += '.html'; } - const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); if (path === 'historicalTrades') { if (this.apiKey) { headers = { @@ -2750,19 +2950,22 @@ module.exports = class binance extends Exchange { } else { throw new AuthenticationError (this.id + ' historicalTrades endpoint requires `apiKey` credential'); } - } else if (userDataStream) { + } + const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); + if (userDataStream) { if (this.apiKey) { // v1 special case for userDataStream - body = this.urlencode (params); headers = { 'X-MBX-APIKEY': this.apiKey, 'Content-Type': 'application/x-www-form-urlencoded', }; + if (method !== 'GET') { + body = this.urlencode (params); + } } else { throw new AuthenticationError (this.id + ' userDataStream endpoint requires `apiKey` credential'); } - } - if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { + } else if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { this.checkRequiredCredentials (); let query = undefined; const recvWindow = this.safeInteger (this.options, 'recvWindow', 5000); @@ -2794,13 +2997,8 @@ module.exports = class binance extends Exchange { headers['Content-Type'] = 'application/x-www-form-urlencoded'; } } else { - // userDataStream endpoints are public, but POST, PUT, DELETE - // therefore they don't accept URL query arguments - // https://github.com/ccxt/ccxt/issues/5224 - if (!userDataStream) { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } + if (Object.keys (params).length) { + url += '?' + this.urlencode (params); } } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bit2c.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bit2c.js index a4d60733a..1f58d3f75 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bit2c.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bit2c.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, InvalidNonce, AuthenticationError, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -155,12 +156,12 @@ module.exports = class bit2c extends Exchange { const currencyId = this.currencyId (code); const uppercase = currencyId.toUpperCase (); if (uppercase in balance) { - account['free'] = this.safeFloat (balance, 'AVAILABLE_' + uppercase); - account['total'] = this.safeFloat (balance, uppercase); + account['free'] = this.safeString (balance, 'AVAILABLE_' + uppercase); + account['total'] = this.safeString (balance, uppercase); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -179,22 +180,22 @@ module.exports = class bit2c extends Exchange { }; const ticker = await this.publicGetExchangesPairTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const averagePrice = this.safeFloat (ticker, 'av'); - const baseVolume = this.safeFloat (ticker, 'a'); + const averagePrice = this.safeNumber (ticker, 'av'); + const baseVolume = this.safeNumber (ticker, 'a'); let quoteVolume = undefined; if (baseVolume !== undefined && averagePrice !== undefined) { quoteVolume = baseVolume * averagePrice; } - const last = this.safeFloat (ticker, 'll'); + const last = this.safeNumber (ticker, 'll'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'h'), + 'bid': this.safeNumber (ticker, 'h'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'l'), + 'ask': this.safeNumber (ticker, 'l'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -276,14 +277,8 @@ module.exports = class bit2c extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -296,7 +291,7 @@ module.exports = class bit2c extends Exchange { } const id = this.safeString (order, 'id'); const status = this.safeString (order, 'status'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -313,12 +308,12 @@ module.exports = class bit2c extends Exchange { 'amount': amount, 'filled': undefined, 'remaining': undefined, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -344,16 +339,16 @@ module.exports = class bit2c extends Exchange { parseTrade (trade, market = undefined) { let timestamp = undefined; let id = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let orderId = undefined; let feeCost = undefined; let side = undefined; const reference = this.safeString (trade, 'reference'); if (reference !== undefined) { timestamp = this.safeTimestamp (trade, 'ticks'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'firstAmount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'firstAmount'); const reference_parts = reference.split ('|'); // reference contains 'pair|orderId|tradeId' if (market === undefined) { const marketId = this.safeString (trade, 'pair'); @@ -371,12 +366,12 @@ module.exports = class bit2c extends Exchange { } else if (side === 1) { side = 'sell'; } - feeCost = this.safeFloat (trade, 'feeAmount'); + feeCost = this.safeNumber (trade, 'feeAmount'); } else { timestamp = this.safeTimestamp (trade, 'date'); id = this.safeString (trade, 'tid'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'amount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'amount'); side = this.safeValue (trade, 'isBid'); if (side !== undefined) { if (side) { @@ -390,6 +385,9 @@ module.exports = class bit2c extends Exchange { if (market !== undefined) { symbol = market['symbol']; } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -402,7 +400,7 @@ module.exports = class bit2c extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': { 'cost': feeCost, 'currency': 'NIS', diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbank.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbank.js index d357531d7..c3626b01f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbank.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbank.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -78,21 +79,23 @@ module.exports = class bitbank extends Exchange { }, }, 'markets': { + 'BAT/JPY': { 'id': 'bat_jpy', 'symbol': 'BAT/JPY', 'base': 'BAT', 'quote': 'JPY', 'baseId': 'bat', 'quoteId': 'jpy' }, + 'BAT/BTC': { 'id': 'bat_btc', 'symbol': 'BAT/BTC', 'base': 'BAT', 'quote': 'BTC', 'baseId': 'bat', 'quoteId': 'btc' }, 'BCH/BTC': { 'id': 'bcc_btc', 'symbol': 'BCH/BTC', 'base': 'BCH', 'quote': 'BTC', 'baseId': 'bcc', 'quoteId': 'btc' }, 'BCH/JPY': { 'id': 'bcc_jpy', 'symbol': 'BCH/JPY', 'base': 'BCH', 'quote': 'JPY', 'baseId': 'bcc', 'quoteId': 'jpy' }, + 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, + 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, + 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, + 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, + 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, 'MONA/BTC': { 'id': 'mona_btc', 'symbol': 'MONA/BTC', 'base': 'MONA', 'quote': 'BTC', 'baseId': 'mona', 'quoteId': 'btc' }, 'MONA/JPY': { 'id': 'mona_jpy', 'symbol': 'MONA/JPY', 'base': 'MONA', 'quote': 'JPY', 'baseId': 'mona', 'quoteId': 'jpy' }, 'QTUM/BTC': { 'id': 'qtum_btc', 'symbol': 'QTUM/BTC', 'base': 'QTUM', 'quote': 'BTC', 'baseId': 'qtum', 'quoteId': 'btc' }, 'QTUM/JPY': { 'id': 'qtum_jpy', 'symbol': 'QTUM/JPY', 'base': 'QTUM', 'quote': 'JPY', 'baseId': 'qtum', 'quoteId': 'jpy' }, - 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, - 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, - 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, - 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, - 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, - 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, - 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, - 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, 'XLM/BTC': { 'id': 'xlm_btc', 'symbol': 'XLM/BTC', 'base': 'XLM', 'quote': 'BTC', 'baseId': 'xlm', 'quoteId': 'btc' }, + 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, + 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, + 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, }, 'fees': { 'trading': { @@ -141,16 +144,16 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -160,7 +163,7 @@ module.exports = class bitbank extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -196,18 +199,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; feeCurrency = market['quote']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'transaction_id', 'trade_id'); const takerOrMaker = this.safeString (trade, 'maker_taker'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee_amount_quote'); + const feeCost = this.safeNumber (trade, 'fee_amount_quote'); if (feeCost !== undefined) { fee = { 'currency': feeCurrency, @@ -259,11 +259,11 @@ module.exports = class bitbank extends Exchange { // return [ this.safeInteger (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -314,14 +314,13 @@ module.exports = class bitbank extends Exchange { const balance = assets[i]; const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'free_amount'), - 'used': this.safeFloat (balance, 'locked_amount'), - 'total': this.safeFloat (balance, 'onhand_amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'free_amount'); + account['used'] = this.safeString (balance, 'locked_amount'); + account['total'] = this.safeString (balance, 'onhand_amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -346,21 +345,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (order, 'ordered_at'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'start_amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const average = this.safeFloat (order, 'average_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'start_amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const average = this.safeNumber (order, 'average_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -374,7 +367,7 @@ module.exports = class bitbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, @@ -382,7 +375,7 @@ module.exports = class bitbank extends Exchange { 'trades': undefined, 'fee': undefined, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbay.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbay.js index 4f502e934..760fc7aa2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbay.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitbay.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { InvalidNonce, InsufficientFunds, AuthenticationError, InvalidOrder, ExchangeError, OrderNotFound, AccountSuspended, BadSymbol, OrderImmediatelyFillable, RateLimitExceeded, OnMaintenance, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -278,8 +279,8 @@ module.exports = class bitbay extends Exchange { if (this.inArray (base, fiatCurrencies) || this.inArray (quote, fiatCurrencies)) { fees = this.safeValue (this.fees, 'fiat', {}); } - const maker = this.safeFloat (fees, 'maker'); - const taker = this.safeFloat (fees, 'taker'); + const maker = this.safeNumber (fees, 'maker'); + const taker = this.safeNumber (fees, 'taker'); // todo: check that the limits have ben interpreted correctly // todo: parse the fees page result.push ({ @@ -295,7 +296,7 @@ module.exports = class bitbay extends Exchange { 'taker': taker, 'limits': { 'amount': { - 'min': this.safeFloat (first, 'minOffer'), + 'min': this.safeNumber (first, 'minOffer'), 'max': undefined, }, 'price': { @@ -303,7 +304,7 @@ module.exports = class bitbay extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (second, 'minOffer'), + 'min': this.safeNumber (second, 'minOffer'), 'max': undefined, }, }, @@ -343,16 +344,10 @@ module.exports = class bitbay extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (order, 'time'); - const amount = this.safeFloat (order, 'startAmount'); - const remaining = this.safeFloat (order, 'currentAmount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } + const amount = this.safeNumber (order, 'startAmount'); + const remaining = this.safeNumber (order, 'currentAmount'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'info': order, @@ -365,16 +360,16 @@ module.exports = class bitbay extends Exchange { 'timeInForce': undefined, 'postOnly': postOnly, 'side': this.safeStringLower (order, 'offerType'), - 'price': this.safeFloat (order, 'rate'), + 'price': this.safeNumber (order, 'rate'), 'stopPrice': undefined, 'amount': amount, 'cost': undefined, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'average': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -427,11 +422,11 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lockedFunds'); - account['free'] = this.safeFloat (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'lockedFunds'); + account['free'] = this.safeString (balance, 'availableFunds'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -450,22 +445,22 @@ module.exports = class bitbay extends Exchange { }; const ticker = await this.publicGetIdTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'volume'); - const vwap = this.safeFloat (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max'), + 'low': this.safeNumber (ticker, 'min'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -474,7 +469,7 @@ module.exports = class bitbay extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), + 'average': this.safeNumber (ticker, 'average'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -775,7 +770,7 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const change = this.safeValue (item, 'change', {}); - let amount = this.safeFloat (change, 'total'); + let amount = this.safeNumber (change, 'total'); let direction = 'in'; if (amount < 0) { direction = 'out'; @@ -787,9 +782,9 @@ module.exports = class bitbay extends Exchange { const referenceId = this.safeString (item, 'detailId'); const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const fundsBefore = this.safeValue (item, 'fundsBefore', {}); - const before = this.safeFloat (fundsBefore, 'total'); + const before = this.safeNumber (fundsBefore, 'total'); const fundsAfter = this.safeValue (item, 'fundsAfter', {}); - const after = this.safeFloat (fundsAfter, 'total'); + const after = this.safeNumber (fundsAfter, 'total'); return { 'info': item, 'id': id, @@ -846,11 +841,11 @@ module.exports = class bitbay extends Exchange { const first = this.safeValue (ohlcv, 1, {}); return [ this.safeInteger (ohlcv, 0), - this.safeFloat (first, 'o'), - this.safeFloat (first, 'h'), - this.safeFloat (first, 'l'), - this.safeFloat (first, 'c'), - this.safeFloat (first, 'v'), + this.safeNumber (first, 'o'), + this.safeNumber (first, 'h'), + this.safeNumber (first, 'l'), + this.safeNumber (first, 'c'), + this.safeNumber (first, 'v'), ]; } @@ -933,15 +928,12 @@ module.exports = class bitbay extends Exchange { if (wasTaker !== undefined) { takerOrMaker = wasTaker ? 'taker' : 'maker'; } - const price = this.safeFloat2 (trade, 'rate', 'r'); - const amount = this.safeFloat2 (trade, 'amount', 'a'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'commissionValue'); + const priceString = this.safeString2 (trade, 'rate', 'r'); + const amountString = this.safeString2 (trade, 'amount', 'a'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'commissionValue'); const marketId = this.safeString (trade, 'market'); market = this.safeMarket (marketId, market, '-'); const symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex.js index 6d34687ff..1d7643454 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { NotSupported, RateLimitExceeded, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, InvalidNonce, BadSymbol } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -45,6 +46,7 @@ module.exports = class bitfinex extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': '1m', @@ -158,6 +160,7 @@ module.exports = class bitfinex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'maker': 0.1 / 100, @@ -344,6 +347,8 @@ module.exports = class bitfinex extends Exchange { 'No summary found.': ExchangeError, // fetchTradingFees (summary) endpoint can give this vague error message 'Cannot evaluate your available balance, please try again': ExchangeNotAvailable, 'Unknown symbol': BadSymbol, + 'Cannot complete transfer. Exchange balance insufficient.': InsufficientFunds, + 'Momentary balance check. Please wait few seconds and try the transfer again.': ExchangeError, }, 'broad': { 'Invalid X-BFX-SIGNATURE': AuthenticationError, @@ -441,6 +446,15 @@ module.exports = class bitfinex extends Exchange { 'limit': 'exchange limit', 'market': 'exchange market', }, + 'accountsByType': { + 'spot': 'exchange', + 'margin': 'trading', + 'funding': 'deposit', + 'exchange': 'exchange', + 'trading': 'trading', + 'deposit': 'deposit', + 'derivatives': 'trading', + }, }, }); } @@ -454,7 +468,7 @@ module.exports = class bitfinex extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdraw[code] = this.safeFloat (fees, id); + withdraw[code] = this.safeNumber (fees, id); } return { 'info': response, @@ -490,14 +504,31 @@ module.exports = class bitfinex extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } async fetchMarkets (params = {}) { const ids = await this.publicGetSymbols (); + // + // [ "btcusd", "ltcusd", "ltcbtc" ] + // const details = await this.publicGetSymbolsDetails (); + // + // [ + // { + // "pair":"btcusd", + // "price_precision":5, + // "initial_margin":"10.0", + // "minimum_margin":"5.0", + // "maximum_order_size":"2000.0", + // "minimum_order_size":"0.0002", + // "expiration":"NA", + // "margin":true + // }, + // ] + // const result = []; for (let i = 0; i < details.length; i++) { const market = details[i]; @@ -528,8 +559,8 @@ module.exports = class bitfinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -540,6 +571,7 @@ module.exports = class bitfinex extends Exchange { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -548,6 +580,8 @@ module.exports = class bitfinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': true, + 'type': 'spot', + 'margin': margin, 'precision': precision, 'limits': limits, 'info': market, @@ -572,40 +606,15 @@ module.exports = class bitfinex extends Exchange { return this.decimalToPrecision (price, TRUNCATE, 8, DECIMAL_PLACES); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - const code = market[key]; - const currency = this.safeValue (this.currencies, code); - if (currency !== undefined) { - const precision = this.safeInteger (currency, 'precision'); - if (precision !== undefined) { - cost = parseFloat (this.currencyToPrecision (code, cost)); - } - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); - const types = { - 'exchange': 'exchange', - 'deposit': 'funding', - 'trading': 'margin', - }; - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } const query = this.omit (params, 'type'); const response = await this.privatePostBalances (query); // [ { type: 'deposit', @@ -621,12 +630,16 @@ module.exports = class bitfinex extends Exchange { // amount: '0.0005', // available: '0.0005' } ], const result = { 'info': response }; + const isDerivative = requestedType === 'derivatives'; for (let i = 0; i < response.length; i++) { const balance = response[i]; const type = this.safeString (balance, 'type'); - const parsedType = this.safeString (types, type); - if ((parsedType === balanceType) || (type === balanceType)) { - const currencyId = this.safeString (balance, 'currency'); + const currencyId = this.safeStringLower (balance, 'currency', ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { const code = this.safeCurrencyCode (currencyId); // bitfinex had BCH previously, now it's BAB, but the old // BCH symbol is kept for backward-compatibility @@ -635,13 +648,80 @@ module.exports = class bitfinex extends Exchange { // https://github.com/ccxt/ccxt/issues/4989 if (!(code in result)) { const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currencyId = this.currencyId (code); + const fromCurrencyId = this.convertDerivativesId (currencyId, fromAccount); + const toCurrencyId = this.convertDerivativesId (currencyId, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'walletfrom': fromId, + 'walletto': toId, + }; + const response = await this.privatePostTransfer (this.extend (request, params)); + // [ + // { + // status: 'success', + // message: '0.0001 Bitcoin transfered from Margin to Exchange' + // } + // ] + const result = this.safeValue (response, 0); + const status = this.safeString (result, 'status'); + const message = this.safeString (result, 'message'); + if (message === undefined) { + throw new ExchangeError (this.id + ' transfer failed'); + } + // [{"status":"error","message":"Momentary balance check. Please wait few seconds and try the transfer again."}] + if (status === 'error') { + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + return { + 'info': response, + 'status': status, + 'amount': requestedAmount, + 'code': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'timestamp': undefined, + 'datetime': undefined, + }; + } + + convertDerivativesId (currencyId, type) { + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if ((type !== 'derivatives' && type !== 'trading' && type !== 'margin') && isDerivativeCode) { + currencyId = currencyId.slice (0, start); + } else if (type === 'derivatives' && !isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + return currencyId; } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -680,7 +760,7 @@ module.exports = class bitfinex extends Exchange { } parseTicker (ticker, market = undefined) { - let timestamp = this.safeFloat (ticker, 'timestamp'); + let timestamp = this.safeNumber (ticker, 'timestamp'); if (timestamp !== undefined) { timestamp *= 1000; } @@ -703,16 +783,16 @@ module.exports = class bitfinex extends Exchange { } } } - const last = this.safeFloat (ticker, 'last_price'); + const last = this.safeNumber (ticker, 'last_price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -721,8 +801,8 @@ module.exports = class bitfinex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'mid'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'mid'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -730,24 +810,21 @@ module.exports = class bitfinex extends Exchange { parseTrade (trade, market) { const id = this.safeString (trade, 'tid'); - let timestamp = this.safeFloat (trade, 'timestamp'); + let timestamp = this.safeNumber (trade, 'timestamp'); if (timestamp !== undefined) { timestamp = parseInt (timestamp) * 1000; } const type = undefined; const side = this.safeStringLower (trade, 'type'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; if ('fee_amount' in trade) { - const feeCost = -this.safeFloat (trade, 'fee_amount'); + const feeCost = -this.safeNumber (trade, 'fee_amount'); const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { @@ -862,6 +939,30 @@ module.exports = class bitfinex extends Exchange { } parseOrder (order, market = undefined) { + // + // { + // id: 57334010955, + // cid: 1611584840966, + // cid_date: null, + // gid: null, + // symbol: 'ltcbtc', + // exchange: null, + // price: '0.0042125', + // avg_execution_price: '0.0042097', + // side: 'sell', + // type: 'exchange market', + // timestamp: '1611584841.0', + // is_live: false, + // is_cancelled: false, + // is_hidden: 0, + // oco_order: 0, + // was_forced: false, + // original_amount: '0.205176', + // remaining_amount: '0.0', + // executed_amount: '0.205176', + // src: 'web' + // } + // const side = this.safeString (order, 'side'); const open = this.safeValue (order, 'is_live'); const canceled = this.safeValue (order, 'is_cancelled'); @@ -873,30 +974,17 @@ module.exports = class bitfinex extends Exchange { } else { status = 'closed'; } - let symbol = undefined; - if (market === undefined) { - const marketId = this.safeStringUpper (order, 'symbol'); - if (marketId !== undefined) { - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } - } - } - if (market !== undefined) { - symbol = market['symbol']; - } - let orderType = order['type']; + const marketId = this.safeStringUpper (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market); + let orderType = this.safeString (order, 'type', ''); const exchange = orderType.indexOf ('exchange ') >= 0; if (exchange) { const parts = order['type'].split (' '); orderType = parts[1]; } - let timestamp = this.safeFloat (order, 'timestamp'); - if (timestamp !== undefined) { - timestamp = parseInt (timestamp) * 1000; - } + const timestamp = this.safeTimestamp (order, 'timestamp'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -908,17 +996,17 @@ module.exports = class bitfinex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': side, - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_execution_price'), - 'amount': this.safeFloat (order, 'original_amount'), - 'remaining': this.safeFloat (order, 'remaining_amount'), - 'filled': this.safeFloat (order, 'executed_amount'), + 'average': this.safeNumber (order, 'avg_execution_price'), + 'amount': this.safeNumber (order, 'original_amount'), + 'remaining': this.safeNumber (order, 'remaining_amount'), + 'filled': this.safeNumber (order, 'executed_amount'), 'status': status, 'fee': undefined, 'cost': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -973,11 +1061,11 @@ module.exports = class bitfinex extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -1125,11 +1213,11 @@ module.exports = class bitfinex extends Exchange { // "timestamp_created": "1561716066.0" // } // - let timestamp = this.safeFloat (transaction, 'timestamp_created'); + let timestamp = this.safeNumber (transaction, 'timestamp_created'); if (timestamp !== undefined) { timestamp = parseInt (timestamp * 1000); } - let updated = this.safeFloat (transaction, 'timestamp'); + let updated = this.safeNumber (transaction, 'timestamp'); if (updated !== undefined) { updated = parseInt (updated * 1000); } @@ -1137,7 +1225,7 @@ module.exports = class bitfinex extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const type = this.safeStringLower (transaction, 'type'); // DEPOSIT or WITHDRAWAL const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -1150,7 +1238,7 @@ module.exports = class bitfinex extends Exchange { 'address': this.safeString (transaction, 'address'), // todo: this is actually the tag for XRP transfers (the address is missing) 'tag': undefined, // refix it properly for the tag from description 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -1204,7 +1292,7 @@ module.exports = class bitfinex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex2.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex2.js index b47da9faf..9313f2025 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex2.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitfinex2.js @@ -286,6 +286,15 @@ module.exports = class bitfinex2 extends bitfinex { 'JPY': 'JPY', 'GBP': 'GBP', }, + // actually the correct names unlike the v1 + // we don't want to extend this with accountsByType in v1 + 'v2AccountsByType': { + 'spot': 'exchange', + 'exchange': 'exchange', + 'funding': 'funding', + 'margin': 'margin', + 'derivatives': 'margin', + }, }, 'exceptions': { 'exact': { @@ -367,8 +376,8 @@ module.exports = class bitfinex2 extends bitfinex { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -379,6 +388,7 @@ module.exports = class bitfinex2 extends bitfinex { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -393,6 +403,7 @@ module.exports = class bitfinex2 extends bitfinex { 'type': type, 'swap': false, 'spot': spot, + 'margin': margin, 'futures': futures, }); } @@ -505,7 +516,7 @@ module.exports = class bitfinex2 extends bitfinex { const ids = this.safeValue (response, 0, []); const result = {}; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; const code = this.safeCurrencyCode (id); const label = this.safeValue (indexed['label'], id, []); const name = this.safeString (label, 1); @@ -513,13 +524,14 @@ module.exports = class bitfinex2 extends bitfinex { const type = this.safeString (pool, 1); const feeValues = this.safeValue (indexed['fees'], id, []); const fees = this.safeValue (feeValues, 1, []); - const fee = this.safeFloat (fees, 1); + const fee = this.safeNumber (fees, 1); + const undl = this.safeValue (indexed['undl'], id, []); const precision = 8; // default precision, todo: fix "magic constants" - id = 'f' + id; + const fid = 'f' + id; result[code] = { - 'id': id, + 'id': fid, 'code': code, - 'info': [ id, label, pool, feeValues ], + 'info': [ id, label, pool, feeValues, undl ], 'type': type, 'name': name, 'active': true, @@ -550,40 +562,117 @@ module.exports = class bitfinex2 extends bitfinex { async fetchBalance (params = {}) { // this api call does not return the 'used' amount - use the v1 version instead (which also returns zero balances) + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 await this.loadMarkets (); - const response = await this.privatePostAuthRWallets (params); - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } + const isDerivative = requestedType === 'derivatives'; + const query = this.omit (params, 'type'); + const response = await this.privatePostAuthRWallets (query); const result = { 'info': response }; - for (let b = 0; b < response.length; b++) { - const balance = response[b]; - const accountType = balance[0]; - let currency = balance[1]; - const total = balance[2]; - const available = balance[4]; - if (accountType === balanceType) { - if (currency[0] === 't') { - currency = currency.slice (1); - } - const code = this.safeCurrencyCode (currency); + for (let i = 0; i < response.length; i++) { + const balance = response[i]; + const type = this.safeString (balance, 0); + const currencyId = this.safeStringLower (balance, 1, ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { + const code = this.safeCurrencyCode (currencyId); const account = this.account (); - // do not fill in zeroes and missing values in the parser - // rewrite and unify the following to use the unified parseBalance - account['total'] = total; - if (!available) { - if (available === 0) { - account['free'] = 0; - account['used'] = total; - } else { - account['free'] = total; - } - } else { - account['free'] = available; - account['used'] = account['total'] - account['free']; - } + account['total'] = this.safeString (balance, 2); + account['free'] = this.safeString (balance, 4); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currency = this.currency (code); + const fromCurrencyId = this.convertDerivativesId (currency, fromAccount); + const toCurrencyId = this.convertDerivativesId (currency, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + // this request is slightly different from v1 fromAccount -> from + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'from': fromId, + 'to': toId, + }; + const response = await this.privatePostAuthWTransfer (this.extend (request, params)); + // [1616451183763,"acc_tf",null,null,[1616451183763,"exchange","margin",null,"UST","UST",null,1],null,"SUCCESS","1.0 Tether USDt transfered from Exchange to Margin"] + const timestamp = this.safeInteger (response, 0); + // ["error",10001,"Momentary balance check. Please wait few seconds and try the transfer again."] + const error = this.safeString (response, 0); + if (error === 'error') { + const message = this.safeString (response, 2, ''); + // same message as in v1 + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + const info = this.safeValue (response, 4); + const fromResponse = this.safeString (info, 1); + const toResponse = this.safeString (info, 2); + const toCode = this.safeCurrencyCode (this.safeString (info, 5)); + const success = this.safeString (response, 6); + const status = (success === 'SUCCESS') ? 'ok' : undefined; + return { + 'info': response, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'status': status, + 'amount': requestedAmount, + 'code': toCode, + 'fromAccount': fromResponse, + 'toAccount': toResponse, + }; + } + + convertDerivativesId (currency, type) { + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 + // { + // id: 'fUSTF0', + // code: 'USTF0', + // info: [ 'USTF0', [], [], [], [ 'USTF0', 'UST' ] ], + const info = this.safeValue (currency, 'info'); + const transferId = this.safeString (info, 0); + const underlying = this.safeValue (info, 4, []); + let currencyId = undefined; + if (type === 'derivatives') { + currencyId = this.safeString (underlying, 0, transferId); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if (!isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + } else if (type !== 'margin') { + currencyId = this.safeString (underlying, 1, transferId); + } else { + currencyId = transferId; + } + return currencyId; } async fetchOrder (id, symbol = undefined, params = {}) { @@ -613,9 +702,10 @@ module.exports = class bitfinex2 extends bitfinex { const priceIndex = (fullRequest['precision'] === 'R0') ? 1 : 0; for (let i = 0; i < orderbook.length; i++) { const order = orderbook[i]; - const price = order[priceIndex]; - const amount = Math.abs (order[2]); - const side = (order[2] > 0) ? 'bids' : 'asks'; + const price = this.safeNumber (order, priceIndex); + const signedAmount = this.safeNumber (order, 2); + const amount = Math.abs (signedAmount); + const side = (signedAmount > 0) ? 'bids' : 'asks'; result[side].push ([ price, amount ]); } result['bids'] = this.sortBy (result['bids'], 0, true); @@ -630,26 +720,26 @@ module.exports = class bitfinex2 extends bitfinex { symbol = market['symbol']; } const length = ticker.length; - const last = ticker[length - 4]; + const last = this.safeNumber (ticker, length - 4); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': ticker[length - 2], - 'low': ticker[length - 1], - 'bid': ticker[length - 10], + 'high': this.safeNumber (ticker, length - 2), + 'low': this.safeNumber (ticker, length - 1), + 'bid': this.safeNumber (ticker, length - 10), 'bidVolume': undefined, - 'ask': ticker[length - 8], + 'ask': this.safeNumber (ticker, length - 8), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': ticker[length - 6], - 'percentage': ticker[length - 5] * 100, + 'change': this.safeNumber (ticker, length - 6), + 'percentage': this.safeNumber (ticker, length - 5) * 100, 'average': undefined, - 'baseVolume': ticker[length - 3], + 'baseVolume': this.safeNumber (ticker, length - 3), 'quoteVolume': undefined, 'info': ticker, }; @@ -738,12 +828,12 @@ module.exports = class bitfinex2 extends bitfinex { // const tradeLength = trade.length; const isPrivate = (tradeLength > 5); - const id = trade[0].toString (); + const id = this.safeString (trade, 0); const amountIndex = isPrivate ? 4 : 2; - let amount = trade[amountIndex]; + let amount = this.safeNumber (trade, amountIndex); let cost = undefined; const priceIndex = isPrivate ? 5 : 3; - const price = trade[priceIndex]; + const price = this.safeNumber (trade, priceIndex); let side = undefined; let orderId = undefined; let takerOrMaker = undefined; @@ -751,7 +841,7 @@ module.exports = class bitfinex2 extends bitfinex { let fee = undefined; let symbol = undefined; const timestampIndex = isPrivate ? 2 : 1; - const timestamp = trade[timestampIndex]; + const timestamp = this.safeInteger (trade, timestampIndex); if (isPrivate) { const marketId = trade[1]; if (marketId in this.markets_by_id) { @@ -760,10 +850,12 @@ module.exports = class bitfinex2 extends bitfinex { } else { symbol = this.parseSymbol (marketId); } - orderId = trade[3].toString (); - takerOrMaker = (trade[8] === 1) ? 'maker' : 'taker'; - let feeCost = trade[9]; - const feeCurrency = this.safeCurrencyCode (trade[10]); + orderId = this.safeString (trade, 3); + const maker = this.safeInteger (trade, 8); + takerOrMaker = (maker === 1) ? 'maker' : 'taker'; + let feeCost = this.safeNumber (trade, 9); + const feeCurrencyId = this.safeString (trade, 10); + const feeCurrency = this.safeCurrencyCode (feeCurrencyId); if (feeCost !== undefined) { feeCost = -feeCost; if (symbol in this.markets) { @@ -904,10 +996,10 @@ module.exports = class bitfinex2 extends bitfinex { // https://github.com/ccxt/ccxt/issues/6686 // const timestamp = this.safeTimestamp (order, 5); const timestamp = this.safeInteger (order, 5); - const remaining = Math.abs (this.safeFloat (order, 6)); - const amount = Math.abs (this.safeFloat (order, 7)); - const filled = amount - remaining; - const side = (order[7] < 0) ? 'sell' : 'buy'; + const remaining = Math.abs (this.safeNumber (order, 6)); + const signedAmount = this.safeNumber (order, 7); + const amount = Math.abs (signedAmount); + const side = (signedAmount < 0) ? 'sell' : 'buy'; const orderType = this.safeString (order, 8); const type = this.safeString (this.safeValue (this.options, 'exchangeTypes'), orderType); let status = undefined; @@ -916,11 +1008,10 @@ module.exports = class bitfinex2 extends bitfinex { const parts = statusString.split (' @ '); status = this.parseOrderStatus (this.safeString (parts, 0)); } - const price = this.safeFloat (order, 16); - const average = this.safeFloat (order, 17); - const cost = price * filled; + const price = this.safeNumber (order, 16); + const average = this.safeNumber (order, 17); const clientOrderId = this.safeString (order, 2); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -935,14 +1026,14 @@ module.exports = class bitfinex2 extends bitfinex { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -959,11 +1050,11 @@ module.exports = class bitfinex2 extends bitfinex { if ((orderType === 'LIMIT') || (orderType === 'EXCHANGE LIMIT')) { request['price'] = this.numberToString (price); } else if ((orderType === 'STOP') || (orderType === 'EXCHANGE STOP')) { - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'STOP LIMIT') || (orderType === 'EXCHANGE STOP LIMIT')) { - const priceAuxLimit = this.safeFloat (params, 'price_aux_limit'); - let stopPrice = this.safeFloat (params, 'stopPrice'); + const priceAuxLimit = this.safeNumber (params, 'price_aux_limit'); + let stopPrice = this.safeNumber (params, 'stopPrice'); if (priceAuxLimit === undefined) { if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter or a price_aux_limit parameter for a ' + orderType + ' order'); @@ -978,9 +1069,9 @@ module.exports = class bitfinex2 extends bitfinex { } request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'TRAILING STOP') || (orderType === 'EXCHANGE TRAILING STOP')) { - const priceTrailing = this.safeFloat (params, 'price_trailing'); + const priceTrailing = this.safeNumber (params, 'price_trailing'); request['price_trailing'] = this.numberToString (priceTrailing); - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'FOK') || (orderType === 'EXCHANGE FOK') || (orderType === 'IOC') || (orderType === 'EXCHANGE IOC')) { request['price'] = this.numberToString (price); @@ -1312,11 +1403,11 @@ module.exports = class bitfinex2 extends bitfinex { if (currency !== undefined) { code = currency['code']; } - feeCost = this.safeFloat (data, 8); + feeCost = this.safeNumber (data, 8); if (feeCost !== undefined) { feeCost = -feeCost; } - amount = this.safeFloat (data, 5); + amount = this.safeNumber (data, 5); id = this.safeValue (data, 0); status = 'ok'; if (id === 0) { @@ -1330,7 +1421,7 @@ module.exports = class bitfinex2 extends bitfinex { timestamp = this.safeInteger (transaction, 5); updated = this.safeInteger (transaction, 6); status = this.parseTransactionStatus (this.safeString (transaction, 9)); - amount = this.safeFloat (transaction, 12); + amount = this.safeNumber (transaction, 12); if (amount !== undefined) { if (amount < 0) { type = 'withdrawal'; @@ -1338,7 +1429,7 @@ module.exports = class bitfinex2 extends bitfinex { type = 'deposit'; } } - feeCost = this.safeFloat (transaction, 13); + feeCost = this.safeNumber (transaction, 13); if (feeCost !== undefined) { feeCost = -feeCost; } @@ -1466,7 +1557,7 @@ module.exports = class bitfinex2 extends bitfinex { }); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitflyer.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitflyer.js index f9c19b59a..911cb61f0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitflyer.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitflyer.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -185,11 +186,11 @@ module.exports = class bitflyer extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'amount'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -208,16 +209,16 @@ module.exports = class bitflyer extends Exchange { }; const ticker = await this.publicGetGetticker (this.extend (request, params)); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'ltp'); + const last = this.safeNumber (ticker, 'ltp'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'best_bid'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -227,7 +228,7 @@ module.exports = class bitflyer extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_by_product'), + 'baseVolume': this.safeNumber (ticker, 'volume_by_product'), 'quoteVolume': undefined, 'info': ticker, }; @@ -251,14 +252,11 @@ module.exports = class bitflyer extends Exchange { order = this.safeString (trade, 'child_order_acceptance_id'); } const timestamp = this.parse8601 (this.safeString (trade, 'exec_date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -334,18 +332,17 @@ module.exports = class bitflyer extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'child_order_date')); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'outstanding_size'); - const filled = this.safeFloat (order, 'executed_size'); - const price = this.safeFloat (order, 'price'); - const cost = price * filled; + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'outstanding_size'); + const filled = this.safeNumber (order, 'executed_size'); + const price = this.safeNumber (order, 'price'); const status = this.parseOrderStatus (this.safeString (order, 'child_order_state')); const type = this.safeStringLower (order, 'child_order_type'); const side = this.safeStringLower (order, 'side'); const marketId = this.safeString (order, 'product_code'); const symbol = this.safeSymbol (marketId, market); let fee = undefined; - const feeCost = this.safeFloat (order, 'total_commission'); + const feeCost = this.safeNumber (order, 'total_commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -354,7 +351,7 @@ module.exports = class bitflyer extends Exchange { }; } const id = this.safeString (order, 'child_order_acceptance_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -369,14 +366,14 @@ module.exports = class bitflyer extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrders (symbol = undefined, since = undefined, limit = 100, params = {}) { @@ -439,7 +436,7 @@ module.exports = class bitflyer extends Exchange { return this.parseTrades (response, market, since, limit); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { if (symbols === undefined) { throw new ArgumentsRequired (this.id + ' fetchPositions() requires a `symbols` argument, exactly one symbol in an array'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitforex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitforex.js index 8fa337979..0dfebbef7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitforex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitforex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, DDoSProtection, PermissionDenied, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -259,7 +260,7 @@ module.exports = class bitforex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -295,14 +296,11 @@ module.exports = class bitforex extends Exchange { const timestamp = this.safeInteger (trade, 'time'); const id = this.safeString (trade, 'tid'); const orderId = undefined; - const amount = this.safeFloat (trade, 'amount'); - const price = this.safeFloat (trade, 'price'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const sideId = this.safeInteger (trade, 'direction'); const side = this.parseSide (sideId); return { @@ -345,12 +343,12 @@ module.exports = class bitforex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'active'); - account['total'] = this.safeFloat (balance, 'fix'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'active'); + account['total'] = this.safeString (balance, 'fix'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTicker (symbol, params = {}) { @@ -366,21 +364,21 @@ module.exports = class bitforex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (data, 'high'), - 'low': this.safeFloat (data, 'low'), - 'bid': this.safeFloat (data, 'buy'), + 'high': this.safeNumber (data, 'high'), + 'low': this.safeNumber (data, 'low'), + 'bid': this.safeNumber (data, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (data, 'sell'), + 'ask': this.safeNumber (data, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (data, 'last'), - 'last': this.safeFloat (data, 'last'), + 'close': this.safeNumber (data, 'last'), + 'last': this.safeNumber (data, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (data, 'vol'), + 'baseVolume': this.safeNumber (data, 'vol'), 'quoteVolume': undefined, 'info': response, }; @@ -400,11 +398,11 @@ module.exports = class bitforex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -472,26 +470,24 @@ module.exports = class bitforex extends Exchange { parseOrder (order, market = undefined) { const id = this.safeString (order, 'orderId'); - const timestamp = this.safeFloat (order, 'createTime'); - const lastTradeTimestamp = this.safeFloat (order, 'lastTime'); + const timestamp = this.safeNumber (order, 'createTime'); + const lastTradeTimestamp = this.safeNumber (order, 'lastTime'); const symbol = market['symbol']; const sideId = this.safeInteger (order, 'tradeType'); const side = this.parseSide (sideId); const type = undefined; - const price = this.safeFloat (order, 'orderPrice'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderAmount'); - const filled = this.safeFloat (order, 'dealAmount'); - const remaining = amount - filled; + const price = this.safeNumber (order, 'orderPrice'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderAmount'); + const filled = this.safeNumber (order, 'dealAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderState')); - const cost = filled * price; const feeSide = (side === 'buy') ? 'base' : 'quote'; const feeCurrency = market[feeSide]; const fee = { - 'cost': this.safeFloat (order, 'tradeFee'), + 'cost': this.safeNumber (order, 'tradeFee'), 'currency': feeCurrency, }; - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -505,16 +501,15 @@ module.exports = class bitforex extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitget.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitget.js index 3c9581955..75e458fe0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitget.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitget.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -793,7 +794,7 @@ module.exports = class bitget extends Exchange { let swap = false; const baseId = this.safeString2 (market, 'base_currency', 'coin'); const quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { marketType = 'swap'; spot = false; @@ -811,7 +812,7 @@ module.exports = class bitget extends Exchange { 'amount': parseFloat ('1e-' + sizeIncrement), 'price': parseFloat ('1e-' + tickSize), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const status = this.safeString (market, 'status'); let active = undefined; if (status !== undefined) { @@ -1068,26 +1069,26 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat2 (ticker, 'last', 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'last', 'close'); + const open = this.safeNumber (ticker, 'open'); let bidVolume = undefined; let askVolume = undefined; let bid = this.safeValue (ticker, 'bid'); if (bid === undefined) { - bid = this.safeFloat (ticker, 'best_bid'); + bid = this.safeNumber (ticker, 'best_bid'); } else { - bidVolume = this.safeFloat (bid, 1); - bid = this.safeFloat (bid, 0); + bidVolume = this.safeNumber (bid, 1); + bid = this.safeNumber (bid, 0); } let ask = this.safeValue (ticker, 'ask'); if (ask === undefined) { - ask = this.safeFloat (ticker, 'best_ask'); + ask = this.safeNumber (ticker, 'best_ask'); } else { - askVolume = this.safeFloat (ask, 1); - ask = this.safeFloat (ask, 0); + askVolume = this.safeNumber (ask, 1); + ask = this.safeNumber (ask, 0); } - const baseVolume = this.safeFloat2 (ticker, 'amount', 'volume_24h'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber2 (ticker, 'amount', 'volume_24h'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; @@ -1101,8 +1102,8 @@ module.exports = class bitget extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -1337,9 +1338,12 @@ module.exports = class bitget extends Exchange { } let timestamp = this.safeInteger (trade, 'created_at'); timestamp = this.safeInteger2 (trade, 'timestamp', 'ts', timestamp); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'filled_amount', 'order_qty'); - amount = this.safeFloat2 (trade, 'size', 'amount', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'filled_amount', 'order_qty'); + amountString = this.safeString2 (trade, 'size', 'amount', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -1358,18 +1362,13 @@ module.exports = class bitget extends Exchange { type = this.parseOrderType (side); side = this.parseOrderSide (side); } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - let feeCost = this.safeFloat (trade, 'fee'); - if (feeCost === undefined) { - feeCost = this.safeFloat (trade, 'filled_fees'); + let feeCostString = this.safeString (trade, 'fee'); + if (feeCostString === undefined) { + feeCostString = this.safeString (trade, 'filled_fees'); } else { - feeCost = -feeCost; + feeCostString = (feeCostString[0] === '-') ? feeCostString.slice (1) : feeCostString; } + const feeCost = this.parseNumber (feeCostString); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -1492,23 +1491,23 @@ module.exports = class bitget extends Exchange { const volumeIndex = this.safeString (volume, market['type'], 'amount'); return [ this.safeInteger (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets ]; } else { const volumeIndex = this.safeValue (volume, market['type'], 6); return [ this.safeInteger (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, volumeIndex), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, volumeIndex), // Base Volume ]; } } @@ -1610,13 +1609,13 @@ module.exports = class bitget extends Exchange { } const type = this.safeValue (balance, 'type'); if (type === 'trade') { - result[code]['free'] = this.safeFloat (balance, 'balance'); + result[code]['free'] = this.safeString (balance, 'balance'); } else if ((type === 'frozen') || (type === 'lock')) { - const used = this.safeFloat (result[code], 'used'); - result[code]['used'] = this.sum (used, this.safeFloat (balance, 'balance')); + const used = this.safeString (result[code], 'used'); + result[code]['used'] = Precise.stringAdd (used, this.safeString (balance, 'balance')); } } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseSwapBalance (response) { @@ -1640,11 +1639,11 @@ module.exports = class bitget extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeString (balance, 'equity'); + account['free'] = this.safeString (balance, 'total_avail_balance'); result[symbol] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchAccounts (params = {}) { @@ -1921,26 +1920,13 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let amount = this.safeFloat2 (order, 'amount', 'size'); - const filled = this.safeFloat2 (order, 'filled_amount', 'filled_qty'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - amount = Math.max (amount, filled); - remaining = Math.max (0, amount - filled); - } - } - if (type === 'market') { - remaining = 0; - } - const cost = this.safeFloat (order, 'filled_cash_amount'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); - if ((average === undefined) && (filled !== undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } + const amount = this.safeNumber2 (order, 'amount', 'size'); + const filled = this.safeNumber2 (order, 'filled_amount', 'filled_qty'); + const cost = this.safeNumber (order, 'filled_cash_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'price_avg'); const status = this.parseOrderStatus (this.safeString2 (order, 'state', 'status')); - const feeCost = this.safeFloat2 (order, 'filled_fees', 'fee'); + const feeCost = this.safeNumber2 (order, 'filled_fees', 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -1950,7 +1936,7 @@ module.exports = class bitget extends Exchange { }; } const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1968,11 +1954,11 @@ module.exports = class bitget extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -2019,7 +2005,7 @@ module.exports = class bitget extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'amount'); + let cost = this.safeNumber (params, 'amount'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2569,12 +2555,12 @@ module.exports = class bitget extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const txid = this.safeString (transaction, 'tx_hash'); const timestamp = this.safeInteger (transaction, 'created_at'); const updated = this.safeInteger (transaction, 'updated_at'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -2764,7 +2750,7 @@ module.exports = class bitget extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.swapGetPositionAllPosition (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bithumb.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bithumb.js index ef4e7d479..051562718 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bithumb.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bithumb.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, AuthenticationError, BadRequest, PermissionDenied, InvalidAddress, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); const { DECIMAL_PLACES, SIGNIFICANT_DIGITS, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -198,12 +199,12 @@ module.exports = class bithumb extends Exchange { const account = this.account (); const currency = this.currency (code); const lowerCurrencyId = this.safeStringLower (currency, 'id'); - account['total'] = this.safeFloat (balances, 'total_' + lowerCurrencyId); - account['used'] = this.safeFloat (balances, 'in_use_' + lowerCurrencyId); - account['free'] = this.safeFloat (balances, 'available_' + lowerCurrencyId); + account['total'] = this.safeString (balances, 'total_' + lowerCurrencyId); + account['used'] = this.safeString (balances, 'in_use_' + lowerCurrencyId); + account['free'] = this.safeString (balances, 'available_' + lowerCurrencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -265,8 +266,8 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'opening_price'); - const close = this.safeFloat (ticker, 'closing_price'); + const open = this.safeNumber (ticker, 'opening_price'); + const close = this.safeNumber (ticker, 'closing_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -277,18 +278,18 @@ module.exports = class bithumb extends Exchange { } average = this.sum (open, close) / 2; } - const baseVolume = this.safeFloat (ticker, 'units_traded_24H'); - const quoteVolume = this.safeFloat (ticker, 'acc_trade_value_24H'); + const baseVolume = this.safeNumber (ticker, 'units_traded_24H'); + const quoteVolume = this.safeNumber (ticker, 'acc_trade_value_24H'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -394,11 +395,11 @@ module.exports = class bithumb extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -488,18 +489,16 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'units_traded', 'units'); - let cost = this.safeFloat (trade, 'total'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'units_traded', 'units'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.commonCurrencyCode (feeCurrencyId); @@ -702,14 +701,14 @@ module.exports = class bithumb extends Exchange { const sideProperty = this.safeValue2 (order, 'type', 'side'); const side = (sideProperty === 'bid') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'order_status')); - let price = this.safeFloat2 (order, 'order_price', 'price'); + let price = this.safeNumber2 (order, 'order_price', 'price'); let type = 'limit'; if (price === 0) { price = undefined; type = 'market'; } - const amount = this.safeFloat2 (order, 'order_qty', 'units'); - let remaining = this.safeFloat (order, 'units_remaining'); + const amount = this.safeNumber2 (order, 'order_qty', 'units'); + let remaining = this.safeNumber (order, 'units_remaining'); if (remaining === undefined) { if (status === 'closed') { remaining = 0; @@ -728,65 +727,14 @@ module.exports = class bithumb extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let filled = undefined; - let cost = undefined; - let average = undefined; const id = this.safeString (order, 'order_id'); - const rawTrades = this.safeValue (order, 'contract'); - let trades = undefined; - let fee = undefined; - let fees = undefined; - let feesByCurrency = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'side': side, - 'symbol': symbol, - 'order': id, - }); - filled = 0; - feesByCurrency = {}; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - filled = this.sum (filled, trade['amount']); - cost = this.sum (cost, trade['cost']); - const tradeFee = trade['fee']; - const feeCurrency = tradeFee['currency']; - if (feeCurrency in feesByCurrency) { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': this.sum (feesByCurrency[feeCurrency]['cost'], tradeFee['cost']), - }; - } else { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': tradeFee['cost'], - }; - } - } - const feeCurrencies = Object.keys (feesByCurrency); - const feeCurrenciesLength = feeCurrencies.length; - if (feeCurrenciesLength > 1) { - fees = []; - for (let i = 0; i < feeCurrencies.length; i++) { - const feeCurrency = feeCurrencies[i]; - fees.push (feesByCurrency[feeCurrency]); - } - } else { - fee = this.safeValue (feesByCurrency, feeCurrencies[0]); - } - if (filled !== 0) { - average = cost / filled; - } - } - if (amount !== undefined) { - if ((filled === undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if ((remaining === undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const result = { + const rawTrades = this.safeValue (order, 'contract', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'side': side, + 'symbol': symbol, + 'order': id, + }); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -801,20 +749,14 @@ module.exports = class bithumb extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, + 'cost': undefined, + 'average': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': trades, - }; - if (fee !== undefined) { - result['fee'] = fee; - } else if (fees !== undefined) { - result['fees'] = fees; - } - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmart.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmart.js index 4ad47118a..9ec806c6e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmart.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmart.js @@ -435,16 +435,16 @@ module.exports = class bitmart extends Exchange { // const pricePrecision = this.safeInteger (market, 'price_max_precision'); const precision = { - 'amount': this.safeFloat (market, 'base_min_size'), + 'amount': this.safeNumber (market, 'base_min_size'), 'price': parseFloat (this.decimalToPrecision (Math.pow (10, -pricePrecision), ROUND, 10)), }; - const minBuyCost = this.safeFloat (market, 'min_buy_amount'); - const minSellCost = this.safeFloat (market, 'min_sell_amount'); + const minBuyCost = this.safeNumber (market, 'min_buy_amount'); + const minSellCost = this.safeNumber (market, 'min_sell_amount'); const minCost = Math.max (minBuyCost, minSellCost); const limits = { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': { 'min': undefined, @@ -554,16 +554,16 @@ module.exports = class bitmart extends Exchange { // // the docs are wrong: https://github.com/ccxt/ccxt/issues/5612 // - const amountPrecision = this.safeFloat (contract, 'vol_unit'); - const pricePrecision = this.safeFloat (contract, 'price_unit'); + const amountPrecision = this.safeNumber (contract, 'vol_unit'); + const pricePrecision = this.safeNumber (contract, 'price_unit'); const precision = { 'amount': amountPrecision, 'price': pricePrecision, }; const limits = { 'amount': { - 'min': this.safeFloat (contract, 'min_vol'), - 'max': this.safeFloat (contract, 'max_vol'), + 'min': this.safeNumber (contract, 'min_vol'), + 'max': this.safeNumber (contract, 'max_vol'), }, 'price': { 'min': undefined, @@ -586,8 +586,8 @@ module.exports = class bitmart extends Exchange { future = true; } const feeConfig = this.safeValue (market, 'fee_config', {}); - const maker = this.safeFloat (feeConfig, 'maker_fee'); - const taker = this.safeFloat (feeConfig, 'taker_fee'); + const maker = this.safeNumber (feeConfig, 'maker_fee'); + const taker = this.safeNumber (feeConfig, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -675,33 +675,33 @@ module.exports = class bitmart extends Exchange { const timestamp = this.safeTimestamp (ticker, 'timestamp', this.milliseconds ()); const marketId = this.safeString2 (ticker, 'symbol', 'contract_id'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat2 (ticker, 'close_24h', 'last_price'); - let percentage = this.safeFloat (ticker, 'fluctuation', 'rise_fall_rate'); + const last = this.safeNumber2 (ticker, 'close_24h', 'last_price'); + let percentage = this.safeNumber (ticker, 'fluctuation', 'rise_fall_rate'); if (percentage !== undefined) { percentage *= 100; } - const baseVolume = this.safeFloat2 (ticker, 'base_volume_24h', 'base_coin_volume'); - const quoteVolume = this.safeFloat2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); + const baseVolume = this.safeNumber2 (ticker, 'base_volume_24h', 'base_coin_volume'); + const quoteVolume = this.safeNumber2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const open = this.safeFloat2 (ticker, 'open_24h', 'open'); + const open = this.safeNumber2 (ticker, 'open_24h', 'open'); let average = undefined; if ((last !== undefined) && (open !== undefined)) { average = this.sum (last, open) / 2; } - average = this.safeFloat (ticker, 'avg_price', average); + average = this.safeNumber (ticker, 'avg_price', average); const price = this.safeValue (ticker, 'depth_price', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), - 'bid': this.safeFloat (price, 'best_bid', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (price, 'best_ask', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), + 'bid': this.safeNumber (price, 'best_bid', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (price, 'best_ask', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open_24h'), + 'open': this.safeNumber (ticker, 'open_24h'), 'close': last, 'last': last, 'previousClose': undefined, @@ -1005,18 +1005,18 @@ module.exports = class bitmart extends Exchange { if (execType !== undefined) { takerOrMaker = (execType === 'M') ? 'maker' : 'taker'; } - let price = this.safeFloat2 (trade, 'price', 'deal_price'); - price = this.safeFloat (trade, 'price_avg', price); - let amount = this.safeFloat2 (trade, 'amount', 'deal_vol'); - amount = this.safeFloat (trade, 'size', amount); - let cost = this.safeFloat2 (trade, 'count', 'notional'); + let price = this.safeNumber2 (trade, 'price', 'deal_price'); + price = this.safeNumber (trade, 'price_avg', price); + let amount = this.safeNumber2 (trade, 'amount', 'deal_vol'); + amount = this.safeNumber (trade, 'size', amount); + let cost = this.safeNumber2 (trade, 'count', 'notional'); if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { cost = amount * price; } const orderId = this.safeInteger (trade, 'order_id'); const marketId = this.safeString2 (trade, 'contract_id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (trade, 'fees'); + const feeCost = this.safeNumber (trade, 'fees'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_coin_name'); @@ -1144,11 +1144,11 @@ module.exports = class bitmart extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1475,11 +1475,11 @@ module.exports = class bitmart extends Exchange { currencyId = this.safeString (balance, 'coind_code', currencyId); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat2 (balance, 'available', 'available_vol'); - account['used'] = this.safeFloat2 (balance, 'frozen', 'freeze_vol'); + account['free'] = this.safeString2 (balance, 'available', 'available_vol'); + account['used'] = this.safeString2 (balance, 'frozen', 'freeze_vol'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -1548,29 +1548,10 @@ module.exports = class bitmart extends Exchange { if (market !== undefined) { status = this.parseOrderStatusByType (market['type'], this.safeString (order, 'status')); } - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat2 (order, 'price_avg', 'done_avg_price'); - const amount = this.safeFloat2 (order, 'size', 'vol'); - let cost = undefined; - let filled = this.safeFloat2 (order, 'filled_size', 'done_vol'); - let remaining = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - if (filled === undefined) { - filled = Math.max (0, amount - remaining); - } - } - if (filled !== undefined) { - if (remaining === undefined) { - remaining = Math.max (0, amount - filled); - } - if (cost === undefined) { - if (average !== undefined) { - cost = average * filled; - } - } - } - } + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber2 (order, 'price_avg', 'done_avg_price'); + const amount = this.safeNumber2 (order, 'size', 'vol'); + const filled = this.safeNumber2 (order, 'filled_size', 'done_vol'); let side = this.safeString (order, 'side'); // 1 = Open long // 2 = Close short @@ -1592,7 +1573,7 @@ module.exports = class bitmart extends Exchange { average = undefined; } } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -1607,14 +1588,14 @@ module.exports = class bitmart extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatusByType (type, status) { @@ -1655,7 +1636,7 @@ module.exports = class bitmart extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2241,12 +2222,12 @@ module.exports = class bitmart extends Exchange { type = 'deposit'; id = depositId; } - const amount = this.safeFloat (transaction, 'arrival_amount'); + const amount = this.safeNumber (transaction, 'arrival_amount'); const timestamp = this.safeInteger (transaction, 'tapply_timeime'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmex.js index 4f5a0552a..8eddc8287 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, BadRequest, DDoSProtection, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -215,8 +216,8 @@ module.exports = class bitmex extends Exchange { 'amount': undefined, 'price': undefined, }; - const lotSize = this.safeFloat (market, 'lotSize'); - const tickSize = this.safeFloat (market, 'tickSize'); + const lotSize = this.safeNumber (market, 'lotSize'); + const tickSize = this.safeNumber (market, 'tickSize'); if (lotSize !== undefined) { precision['amount'] = lotSize; } @@ -230,7 +231,7 @@ module.exports = class bitmex extends Exchange { }, 'price': { 'min': tickSize, - 'max': this.safeFloat (market, 'maxPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { 'min': undefined, @@ -240,7 +241,7 @@ module.exports = class bitmex extends Exchange { const limitField = (position === quote) ? 'cost' : 'amount'; limits[limitField] = { 'min': lotSize, - 'max': this.safeFloat (market, 'maxOrderQty'), + 'max': this.safeNumber (market, 'maxOrderQty'), }; result.push ({ 'id': id, @@ -252,8 +253,8 @@ module.exports = class bitmex extends Exchange { 'active': active, 'precision': precision, 'limits': limits, - 'taker': this.safeFloat (market, 'takerFee'), - 'maker': this.safeFloat (market, 'makerFee'), + 'taker': this.safeNumber (market, 'takerFee'), + 'maker': this.safeNumber (market, 'makerFee'), 'type': type, 'spot': false, 'swap': swap, @@ -319,21 +320,17 @@ module.exports = class bitmex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - let free = this.safeFloat (balance, 'availableMargin'); - let total = this.safeFloat (balance, 'marginBalance'); + let free = this.safeString (balance, 'availableMargin'); + let total = this.safeString (balance, 'marginBalance'); if (code === 'BTC') { - if (free !== undefined) { - free /= 100000000; - } - if (total !== undefined) { - total /= 100000000; - } + free = Precise.stringDiv (free, '1e8'); + total = Precise.stringDiv (total, '1e8'); } account['free'] = free; account['total'] = total; result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -412,8 +409,8 @@ module.exports = class bitmex extends Exchange { for (let i = 0; i < response.length; i++) { const order = response[i]; const side = (order['side'] === 'Sell') ? 'asks' : 'bids'; - const amount = this.safeFloat (order, 'size'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const price = this.safeNumber (order, 'price'); // https://github.com/ccxt/ccxt/issues/4926 // https://github.com/ccxt/ccxt/issues/4927 // the exchange sometimes returns null price in the orderbook @@ -619,7 +616,7 @@ module.exports = class bitmex extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'transactType')); const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount !== undefined) { amount = amount / 100000000; } @@ -630,7 +627,7 @@ module.exports = class bitmex extends Exchange { // for unrealized pnl and other transactions without a timestamp timestamp = 0; // see comments above } - let feeCost = this.safeFloat (item, 'fee', 0); + let feeCost = this.safeNumber (item, 'fee', 0); if (feeCost !== undefined) { feeCost = feeCost / 100000000; } @@ -638,7 +635,7 @@ module.exports = class bitmex extends Exchange { 'cost': feeCost, 'currency': code, }; - let after = this.safeFloat (item, 'walletBalance'); + let after = this.safeNumber (item, 'walletBalance'); if (after !== undefined) { after = after / 100000000; } @@ -957,8 +954,8 @@ module.exports = class bitmex extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const open = this.safeFloat (ticker, 'prevPrice24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'prevPrice24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; if (last !== undefined && open !== undefined) { @@ -971,13 +968,13 @@ module.exports = class bitmex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askPrice'), + 'ask': this.safeNumber (ticker, 'askPrice'), 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'vwap'), + 'vwap': this.safeNumber (ticker, 'vwap'), 'open': open, 'close': last, 'last': last, @@ -985,8 +982,8 @@ module.exports = class bitmex extends Exchange { 'change': change, 'percentage': percentage, 'average': this.sum (open, last) / 2, - 'baseVolume': this.safeFloat (ticker, 'homeNotional24h'), - 'quoteVolume': this.safeFloat (ticker, 'foreignNotional24h'), + 'baseVolume': this.safeNumber (ticker, 'homeNotional24h'), + 'quoteVolume': this.safeNumber (ticker, 'foreignNotional24h'), 'info': ticker, }; } @@ -1011,11 +1008,11 @@ module.exports = class bitmex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1144,23 +1141,23 @@ module.exports = class bitmex extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat2 (trade, 'avgPx', 'price'); - const amount = this.safeFloat2 (trade, 'size', 'lastQty'); + const price = this.safeNumber2 (trade, 'avgPx', 'price'); + const amount = this.safeNumber2 (trade, 'size', 'lastQty'); const id = this.safeString (trade, 'trdMatchID'); const order = this.safeString (trade, 'orderID'); const side = this.safeStringLower (trade, 'side'); // price * amount doesn't work for all symbols (e.g. XBT, ETH) - let cost = this.safeFloat (trade, 'execCost'); + let cost = this.safeNumber (trade, 'execCost'); if (cost !== undefined) { cost = Math.abs (cost) / 100000000; } let fee = undefined; if ('execComm' in trade) { - let feeCost = this.safeFloat (trade, 'execComm'); + let feeCost = this.safeNumber (trade, 'execComm'); feeCost = feeCost / 100000000; const currencyId = this.safeString (trade, 'settlCurrency'); const feeCurrency = this.safeCurrencyCode (currencyId); - const feeRate = this.safeFloat (trade, 'commission'); + const feeRate = this.safeNumber (trade, 'commission'); fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -1262,33 +1259,19 @@ module.exports = class bitmex extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'transactTime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty', 0.0); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (amount - filled, 0.0); - } - } - const average = this.safeFloat (order, 'avgPx'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = average * filled; - } else if (price !== undefined) { - cost = price * filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty', 0.0); + const average = this.safeNumber (order, 'avgPx'); const id = this.safeString (order, 'orderID'); const type = this.safeStringLower (order, 'ordType'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'clOrdID'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'ParticipateDoNotInitiate'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1303,14 +1286,14 @@ module.exports = class bitmex extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { @@ -1371,7 +1354,7 @@ module.exports = class bitmex extends Exchange { 'ordType': orderType, }; if ((orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched')) { - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPx or stopPrice parameter for the ' + orderType + ' order type'); } else { @@ -1488,7 +1471,7 @@ module.exports = class bitmex extends Exchange { return this.parseOrders (response, market); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPosition (params); // [ diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitpanda.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitpanda.js index b440aba7d..5f857014b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitpanda.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitpanda.js @@ -328,7 +328,7 @@ module.exports = class bitpanda extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; @@ -401,9 +401,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -450,8 +450,8 @@ module.exports = class bitpanda extends Exchange { const activeFeeTier = this.safeValue (response, 'active_fee_tier', {}); const result = { 'info': response, - 'maker': this.safeFloat (activeFeeTier, 'maker_fee'), - 'taker': this.safeFloat (activeFeeTier, 'taker_fee'), + 'maker': this.safeNumber (activeFeeTier, 'maker_fee'), + 'taker': this.safeNumber (activeFeeTier, 'taker_fee'), 'percentage': true, 'tierBased': true, }; @@ -460,9 +460,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -500,27 +500,27 @@ module.exports = class bitpanda extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last_price'); - const percentage = this.safeFloat (ticker, 'price_change_percentage'); - const change = this.safeFloat (ticker, 'price_change'); + const last = this.safeNumber (ticker, 'last_price'); + const percentage = this.safeNumber (ticker, 'price_change_percentage'); + const change = this.safeNumber (ticker, 'price_change'); let open = undefined; let average = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'best_bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -705,11 +705,11 @@ module.exports = class bitpanda extends Exchange { const volumeField = this.safeString (options, 'volume', 'total_amount'); return [ alignedTimestamp, - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -795,21 +795,21 @@ module.exports = class bitpanda extends Exchange { timestamp = this.parse8601 (this.safeString (trade, 'time')); } const side = this.safeStringLower2 (trade, 'side', 'taker_side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + let cost = this.safeNumber (trade, 'volume'); if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { cost = amount * price; } const marketId = this.safeString (trade, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (feeInfo, 'fee_amount'); + const feeCost = this.safeNumber (feeInfo, 'fee_amount'); let takerOrMaker = undefined; let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (feeInfo, 'fee_percentage'); + const feeRate = this.safeNumber (feeInfo, 'fee_percentage'); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, @@ -892,11 +892,11 @@ module.exports = class bitpanda extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -1150,12 +1150,12 @@ module.exports = class bitpanda extends Exchange { // } // const id = this.safeString (transaction, 'transaction_id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const currencyId = this.safeString (transaction, 'currency'); currency = this.safeCurrency (currencyId, currency); const status = 'ok'; // the exchange returns cleared transactions only - const feeCost = this.safeFloat2 (transaction, 'fee_amount', 'fee'); + const feeCost = this.safeNumber2 (transaction, 'fee_amount', 'fee'); let fee = undefined; const addressTo = this.safeString (transaction, 'recipient'); const tagTo = this.safeString (transaction, 'destination_tag'); @@ -1270,72 +1270,34 @@ module.exports = class bitpanda extends Exchange { // ] // } // - const rawTrades = this.safeValue (order, 'trades', []); - order = this.safeValue (order, 'order', order); - const id = this.safeString (order, 'order_id'); - const clientOrderId = this.safeString (order, 'client_id'); - const timestamp = this.parse8601 (this.safeString (order, 'time')); - let status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'instrument_code'); + const rawOrder = this.safeValue (order, 'order', order); + const id = this.safeString (rawOrder, 'order_id'); + const clientOrderId = this.safeString (rawOrder, 'client_id'); + const timestamp = this.parse8601 (this.safeString (rawOrder, 'time')); + const rawStatus = this.parseOrderStatus (this.safeString (rawOrder, 'status')); + const status = this.parseOrderStatus (rawStatus); + const marketId = this.safeString (rawOrder, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - if (status === undefined) { - if (remaining > 0) { - status = 'open'; - } else { - status = 'closed'; - } - } - } - } - const side = this.safeStringLower (order, 'side'); - const type = this.safeStringLower (order, 'type'); - const trades = this.parseTrades (rawTrades, market, undefined, undefined); - const fees = []; - const numTrades = trades.length; - let lastTradeTimestamp = undefined; - let tradeCost = undefined; - let tradeAmount = undefined; - if (numTrades > 0) { - lastTradeTimestamp = trades[0]['timestamp']; - tradeCost = 0; - tradeAmount = 0; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - fees.push (trade['fee']); - lastTradeTimestamp = Math.max (lastTradeTimestamp, trade['timestamp']); - tradeCost = this.sum (tradeCost, trade['cost']); - tradeAmount = this.sum (tradeAmount, trade['amount']); - } - } - let average = this.safeFloat (order, 'average_price'); - if (average === undefined) { - if ((tradeCost !== undefined) && (tradeAmount !== undefined) && (tradeAmount !== 0)) { - average = tradeCost / tradeAmount; - } - } - if (cost === undefined) { - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - } - const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'trigger_price'); - const postOnly = this.safeValue (order, 'is_post_only'); - const result = { + const price = this.safeNumber (rawOrder, 'price'); + const amount = this.safeNumber (rawOrder, 'amount'); + const filledString = this.safeString (rawOrder, 'filled_amount'); + const filled = this.parseNumber (filledString); + const side = this.safeStringLower (rawOrder, 'side'); + const type = this.safeStringLower (rawOrder, 'type'); + const timeInForce = this.parseTimeInForce (this.safeString (rawOrder, 'time_in_force')); + const stopPrice = this.safeNumber (rawOrder, 'trigger_price'); + const postOnly = this.safeValue (rawOrder, 'is_post_only'); + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'type': type, + }); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -1344,41 +1306,14 @@ module.exports = class bitpanda extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, // 'fee': undefined, 'trades': trades, - }; - const numFees = fees.length; - if (numFees > 0) { - if (numFees === 1) { - result['fee'] = fees[0]; - } else { - const feesByCurrency = this.groupBy (fees, 'currency'); - const feeCurrencies = Object.keys (feesByCurrency); - const numFeesByCurrency = feeCurrencies.length; - if (numFeesByCurrency === 1) { - const feeCurrency = feeCurrencies[0]; - const feeArray = this.safeValue (feesByCurrency, feeCurrency); - let feeCost = 0; - for (let i = 0; i < feeArray.length; i++) { - feeCost = this.sum (feeCost, feeArray[i]['cost']); - } - result['fee'] = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } else { - result['fees'] = fees; - } - } - } else { - result['fee'] = undefined; - } - return result; + }); } parseTimeInForce (timeInForce) { @@ -1412,7 +1347,7 @@ module.exports = class bitpanda extends Exchange { priceIsRequired = true; } if (uppercaseType === 'STOP') { - const triggerPrice = this.safeFloat (params, 'trigger_price'); + const triggerPrice = this.safeNumber (params, 'trigger_price'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a trigger_price param for ' + type + ' orders'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitso.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitso.js index d8bc07145..defcece54 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitso.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitso.js @@ -157,28 +157,28 @@ module.exports = class bitso extends Exchange { const symbol = base + '/' + quote; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), - 'max': this.safeFloat (market, 'maximum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), + 'max': this.safeNumber (market, 'maximum_amount'), }, 'price': { - 'min': this.safeFloat (market, 'minimum_price'), - 'max': this.safeFloat (market, 'maximum_price'), + 'min': this.safeNumber (market, 'minimum_price'), + 'max': this.safeNumber (market, 'maximum_price'), }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), - 'max': this.safeFloat (market, 'maximum_value'), + 'min': this.safeNumber (market, 'minimum_value'), + 'max': this.safeNumber (market, 'maximum_value'), }, }; - const defaultPricePrecision = this.safeFloat (this.options['precision'], quote, this.options['defaultPrecision']); - const pricePrecision = this.safeFloat (market, 'tick_size', defaultPricePrecision); + const defaultPricePrecision = this.safeNumber (this.options['precision'], quote, this.options['defaultPrecision']); + const pricePrecision = this.safeNumber (market, 'tick_size', defaultPricePrecision); const precision = { - 'amount': this.safeFloat (this.options['precision'], base, this.options['defaultPrecision']), + 'amount': this.safeNumber (this.options['precision'], base, this.options['defaultPrecision']), 'price': pricePrecision, }; const fees = this.safeValue (market, 'fees', {}); const flatRate = this.safeValue (fees, 'flat_rate', {}); - const maker = this.safeFloat (flatRate, 'maker'); - const taker = this.safeFloat (flatRate, 'taker'); + const maker = this.safeNumber (flatRate, 'maker'); + const taker = this.safeNumber (flatRate, 'taker'); const feeTiers = this.safeValue (fees, 'structure', []); const fee = { 'taker': parseFloat (this.decimalToPrecision (taker / 100, ROUND, 0.00000001, TICK_SIZE)), @@ -190,9 +190,9 @@ module.exports = class bitso extends Exchange { const makerFees = []; for (let j = 0; j < feeTiers.length; j++) { const tier = feeTiers[j]; - const volume = this.safeFloat (tier, 'volume'); - const takerFee = this.safeFloat (tier, 'taker'); - const makerFee = this.safeFloat (tier, 'maker'); + const volume = this.safeNumber (tier, 'volume'); + const takerFee = this.safeNumber (tier, 'taker'); + const makerFee = this.safeNumber (tier, 'maker'); const takerFeeToPrecision = parseFloat (this.decimalToPrecision (takerFee / 100, ROUND, 0.00000001, TICK_SIZE)); const makerFeeToPrecision = parseFloat (this.decimalToPrecision (makerFee / 100, ROUND, 0.00000001, TICK_SIZE)); takerFees.push ([ volume, takerFeeToPrecision ]); @@ -232,14 +232,13 @@ module.exports = class bitso extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'locked'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -261,22 +260,22 @@ module.exports = class bitso extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'payload'); const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -297,12 +296,12 @@ module.exports = class bitso extends Exchange { const marketId = this.safeString (trade, 'book'); const symbol = this.safeSymbol (marketId, market, '_'); const side = this.safeString2 (trade, 'side', 'maker_side'); - let amount = this.safeFloat2 (trade, 'amount', 'major'); + let amount = this.safeNumber2 (trade, 'amount', 'major'); if (amount !== undefined) { amount = Math.abs (amount); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fees_amount'); + const feeCost = this.safeNumber (trade, 'fees_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fees_currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -311,11 +310,11 @@ module.exports = class bitso extends Exchange { 'currency': feeCurrency, }; } - let cost = this.safeFloat (trade, 'minor'); + let cost = this.safeNumber (trade, 'minor'); if (cost !== undefined) { cost = Math.abs (cost); } - const price = this.safeFloat (trade, 'price'); + const price = this.safeNumber (trade, 'price'); const orderId = this.safeString (trade, 'oid'); const id = this.safeString (trade, 'tid'); return { @@ -416,17 +415,11 @@ module.exports = class bitso extends Exchange { const symbol = this.safeSymbol (marketId, market, '_'); const orderType = this.safeString (order, 'type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'unfilled_amount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'unfilled_amount'); const clientOrderId = this.safeString (order, 'client_id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -443,12 +436,12 @@ module.exports = class bitso extends Exchange { 'amount': amount, 'cost': undefined, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = 25, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp.js index 4671385bf..0ac6fe9f7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp.js @@ -115,6 +115,16 @@ module.exports = class bitstamp extends Exchange { 'usdc_address/', 'omg_withdrawal/', 'omg_address/', + 'dai_withdrawal/', + 'dai_address/', + 'knc_withdrawal/', + 'knc_address/', + 'mkr_withdrawal/', + 'mkr_address/', + 'zrx_withdrawal/', + 'zrx_address/', + 'gusd_withdrawal/', + 'gusd_address/', 'transfer-to-main/', 'transfer-from-main/', 'withdrawal-requests/', @@ -249,13 +259,15 @@ module.exports = class bitstamp extends Exchange { const symbolId = baseId + '_' + quoteId; const id = this.safeString (market, 'url_symbol'); const precision = { - 'amount': market['base_decimals'], - 'price': market['counter_decimals'], + 'amount': this.safeInteger (market, 'base_decimals'), + 'price': this.safeInteger (market, 'counter_decimals'), }; - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; // let [ cost, currency ] = market['minimum_order'].split (' '); - const active = (market['trading'] === 'Enabled'); + const trading = this.safeString (market, 'trading'); + const active = (trading === 'Enabled'); result.push ({ 'id': id, 'symbol': symbol, @@ -299,7 +311,7 @@ module.exports = class bitstamp extends Exchange { 'type': currencyType, 'name': name, 'active': true, - 'fee': this.safeFloat (description['fees']['funding']['withdraw'], code), + 'fee': this.safeNumber (description['fees']['funding']['withdraw'], code), 'precision': precision, 'limits': { 'amount': { @@ -352,13 +364,16 @@ module.exports = class bitstamp extends Exchange { quote = this.safeCurrencyCode (quote); const description = this.safeString (market, 'description'); const [ baseDescription, quoteDescription ] = description.split (' / '); - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; if (!(base in result)) { - result[base] = this.constructCurrencyObject (baseId, base, baseDescription, market['base_decimals'], undefined, market); + const baseDecimals = this.safeInteger (market, 'base_decimals'); + result[base] = this.constructCurrencyObject (baseId, base, baseDescription, baseDecimals, undefined, market); } if (!(quote in result)) { - result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, market['counter_decimals'], parseFloat (cost), market); + const counterDecimals = this.safeInteger (market, 'counter_decimals'); + result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, counterDecimals, parseFloat (cost), market); } } return result; @@ -400,25 +415,25 @@ module.exports = class bitstamp extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -461,7 +476,7 @@ module.exports = class bitstamp extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; if (id.indexOf ('_') < 0) { - const value = this.safeFloat (transaction, id); + const value = this.safeNumber (transaction, id); if ((value !== undefined) && (value !== 0)) { return id; } @@ -543,11 +558,11 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString2 (trade, 'id', 'tid'); let symbol = undefined; let side = undefined; - let price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat (trade, 'amount'); + let price = this.safeNumber (trade, 'price'); + let amount = this.safeNumber (trade, 'amount'); const orderId = this.safeString (trade, 'order_id'); const type = undefined; - let cost = this.safeFloat (trade, 'cost'); + let cost = this.safeNumber (trade, 'cost'); if (market === undefined) { const keys = Object.keys (trade); for (let i = 0; i < keys.length; i++) { @@ -564,12 +579,12 @@ module.exports = class bitstamp extends Exchange { market = this.getMarketFromTrade (trade); } } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = undefined; if (market !== undefined) { - price = this.safeFloat (trade, market['symbolId'], price); - amount = this.safeFloat (trade, market['baseId'], amount); - cost = this.safeFloat (trade, market['quoteId'], cost); + price = this.safeNumber (trade, market['symbolId'], price); + amount = this.safeNumber (trade, market['baseId'], amount); + cost = this.safeNumber (trade, market['quoteId'], cost); feeCurrency = market['quote']; symbol = market['symbol']; } @@ -638,7 +653,7 @@ module.exports = class bitstamp extends Exchange { parseTradingFee (balances, symbol) { const market = this.market (symbol); - const tradeFee = this.safeFloat (balances, market['id'] + '_fee'); + const tradeFee = this.safeNumber (balances, market['id'] + '_fee'); return { 'symbol': symbol, 'maker': tradeFee, @@ -688,11 +703,11 @@ module.exports = class bitstamp extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -750,12 +765,12 @@ module.exports = class bitstamp extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -802,7 +817,7 @@ module.exports = class bitstamp extends Exchange { if (id.indexOf ('_withdrawal_fee') >= 0) { const currencyId = id.split ('_')[0]; const code = this.safeCurrencyCode (currencyId); - withdraw[code] = this.safeFloat (balance, id); + withdraw[code] = this.safeNumber (balance, id); } } return { @@ -1048,16 +1063,16 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString (transaction, 'id'); const currencyId = this.getCurrencyIdFromTransaction (transaction); const code = this.safeCurrencyCode (currencyId, currency); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let feeCurrency = undefined; let amount = undefined; if ('amount' in transaction) { - amount = this.safeFloat (transaction, 'amount'); + amount = this.safeNumber (transaction, 'amount'); } else if (currency !== undefined) { - amount = this.safeFloat (transaction, currency['id'], amount); + amount = this.safeNumber (transaction, currency['id'], amount); feeCurrency = currency['code']; } else if ((code !== undefined) && (currencyId !== undefined)) { - amount = this.safeFloat (transaction, currencyId, amount); + amount = this.safeNumber (transaction, currencyId, amount); feeCurrency = code; } if (amount !== undefined) { @@ -1182,83 +1197,23 @@ module.exports = class bitstamp extends Exchange { } // there is no timestamp from fetchOrder const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - let lastTradeTimestamp = undefined; - let symbol = undefined; - let marketId = this.safeStringLower (order, 'currency_pair'); - if (marketId !== undefined) { - marketId = marketId.replace ('/', ''); - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - symbol = market['symbol']; - } - } - let amount = this.safeFloat (order, 'amount'); - let filled = 0.0; - const trades = []; - const transactions = this.safeValue (order, 'transactions', []); - let feeCost = undefined; - let cost = undefined; - const numTransactions = transactions.length; - if (numTransactions > 0) { - feeCost = 0.0; - for (let i = 0; i < numTransactions; i++) { - const trade = this.parseTrade (this.extend ({ - 'order_id': id, - 'side': side, - }, transactions[i]), market); - filled = this.sum (filled, trade['amount']); - feeCost = this.sum (feeCost, trade['fee']['cost']); - if (cost === undefined) { - cost = 0.0; - } - cost = this.sum (cost, trade['cost']); - trades.push (trade); - } - lastTradeTimestamp = trades[numTransactions - 1]['timestamp']; - } + const marketId = this.safeStringLower (order, 'currency_pair'); + let symbol = this.safeSymbol (marketId, market, '/'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((status === 'closed') && (amount === undefined)) { - amount = filled; + const amount = this.safeNumber (order, 'amount'); + const transactions = this.safeValue (order, 'transactions', []); + const trades = this.parseTrades (transactions, market); + const length = trades.length; + if (length) { + symbol = trades[0]['symbol']; } - let remaining = undefined; - if (amount !== undefined) { - remaining = amount - filled; - } - let price = this.safeFloat (order, 'price'); - if (market === undefined) { - market = this.getMarketFromTrades (trades); - } - let feeCurrency = undefined; - if (market !== undefined) { - if (symbol === undefined) { - symbol = market['symbol']; - } - feeCurrency = market['quote']; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if (price === undefined) { - if (filled > 0) { - price = cost / filled; - } - } - let fee = undefined; - if (feeCost !== undefined) { - if (feeCurrency !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { + const price = this.safeNumber (order, 'price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': undefined, @@ -1267,15 +1222,15 @@ module.exports = class bitstamp extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, - 'filled': filled, - 'remaining': remaining, + 'filled': undefined, + 'remaining': undefined, 'trades': trades, - 'fee': fee, + 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } parseLedgerEntryType (type) { @@ -1355,11 +1310,11 @@ module.exports = class bitstamp extends Exchange { const parsedTransaction = this.parseTransaction (item); let direction = undefined; if ('amount' in item) { - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); direction = amount > 0 ? 'in' : 'out'; } else if (('currency' in parsedTransaction) && parsedTransaction['currency'] !== undefined) { const currencyId = this.currencyId (parsedTransaction['currency']); - const amount = this.safeFloat (item, currencyId); + const amount = this.safeNumber (item, currencyId); direction = amount > 0 ? 'in' : 'out'; } return { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp1.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp1.js index 8d8de5db1..2b6b70a04 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp1.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitstamp1.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -100,25 +101,25 @@ module.exports = class bitstamp1 extends Exchange { await this.loadMarkets (); const ticker = await this.publicGetTicker (params); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -141,14 +142,11 @@ module.exports = class bitstamp1 extends Exchange { } } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -192,12 +190,12 @@ module.exports = class bitstamp1 extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bittrex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bittrex.js index 1e11d600a..fb8f6fb09 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bittrex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bittrex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, DDoSProtection, PermissionDenied, AddressPending, OnMaintenance, BadRequest, InvalidAddress } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -280,7 +281,7 @@ module.exports = class bittrex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeSize'), + 'min': this.safeNumber (market, 'minTradeSize'), 'max': undefined, }, 'price': { @@ -308,11 +309,11 @@ module.exports = class bittrex extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); const balance = indexed[currencyId]; - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -372,7 +373,7 @@ module.exports = class bittrex extends Exchange { const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); const precision = 8; // default precision, todo: fix "magic constants" - const fee = this.safeFloat (currency, 'txFee'); // todo: redesign + const fee = this.safeNumber (currency, 'txFee'); // todo: redesign const isActive = this.safeString (currency, 'status'); result[code] = { 'id': id, @@ -433,17 +434,17 @@ module.exports = class bittrex extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'updatedAt')); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const percentage = this.safeFloat (ticker, 'percentChange'); - const last = this.safeFloat (ticker, 'lastTradeRate'); + const percentage = this.safeNumber (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'lastTradeRate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidRate'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidRate'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askRate'), + 'ask': this.safeNumber (ticker, 'askRate'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -453,8 +454,8 @@ module.exports = class bittrex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -567,21 +568,18 @@ module.exports = class bittrex extends Exchange { const order = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'marketSymbol'); market = this.safeMarket (marketId, market, '-'); - let cost = undefined; - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'quantity'); - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = undefined; const isTaker = this.safeValue (trade, 'isTaker'); if (isTaker !== undefined) { takerOrMaker = isTaker ? 'taker' : 'maker'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -651,11 +649,11 @@ module.exports = class bittrex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'startsAt')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -762,9 +760,9 @@ module.exports = class bittrex extends Exchange { let cost = undefined; if (isCeilingLimit) { request['limit'] = this.priceToPrecision (symbol, price); - cost = this.safeFloat2 (params, 'ceiling', 'cost', amount); + cost = this.safeNumber2 (params, 'ceiling', 'cost', amount); } else if (isCeilingMarket) { - cost = this.safeFloat2 (params, 'ceiling', 'cost'); + cost = this.safeNumber2 (params, 'ceiling', 'cost'); if (cost === undefined) { if (price === undefined) { cost = amount; @@ -923,7 +921,7 @@ module.exports = class bittrex extends Exchange { // } // const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const address = this.safeString (transaction, 'cryptoAddress'); const txid = this.safeString (transaction, 'txId'); const updated = this.parse8601 (this.safeString (transaction, 'updatedAt')); @@ -959,7 +957,7 @@ module.exports = class bittrex extends Exchange { status = 'ok'; } } - let feeCost = this.safeFloat (transaction, 'txCost'); + let feeCost = this.safeNumber (transaction, 'txCost'); if (feeCost === undefined) { if (type === 'deposit') { // according to https://support.bittrex.com/hc/en-us/articles/115000199651-What-fees-does-Bittrex-charge- @@ -1016,15 +1014,9 @@ module.exports = class bittrex extends Exchange { // } // const marketSymbol = this.safeString (order, 'marketSymbol'); - let symbol = undefined; - let feeCurrency = undefined; - if (marketSymbol !== undefined) { - const [ baseId, quoteId ] = marketSymbol.split ('-'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - feeCurrency = quote; - } + market = this.safeMarket (marketSymbol, market, '-'); + const symbol = market['symbol']; + const feeCurrency = market['quote']; const direction = this.safeStringLower (order, 'direction'); const createdAt = this.safeString (order, 'createdAt'); const updatedAt = this.safeString (order, 'updatedAt'); @@ -1037,32 +1029,15 @@ module.exports = class bittrex extends Exchange { } const timestamp = this.parse8601 (createdAt); const type = this.safeStringLower (order, 'type'); - const quantity = this.safeFloat (order, 'quantity'); - const limit = this.safeFloat (order, 'limit'); - const fillQuantity = this.safeFloat (order, 'fillQuantity'); - const commission = this.safeFloat (order, 'commission'); - const proceeds = this.safeFloat (order, 'proceeds'); - let average = undefined; - let remaining = undefined; - if (fillQuantity !== undefined) { - if (proceeds !== undefined) { - if (fillQuantity > 0) { - average = proceeds / fillQuantity; - } else if (proceeds === 0) { - average = 0; - } - } - if (quantity !== undefined) { - remaining = quantity - fillQuantity; - } - } - let status = this.safeStringLower (order, 'status'); - if ((status === 'closed') && (remaining !== undefined) && (remaining > 0)) { - status = 'canceled'; - } + const quantity = this.safeNumber (order, 'quantity'); + const limit = this.safeNumber (order, 'limit'); + const fillQuantity = this.safeNumber (order, 'fillQuantity'); + const commission = this.safeNumber (order, 'commission'); + const proceeds = this.safeNumber (order, 'proceeds'); + const status = this.safeStringLower (order, 'status'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'timestamp': timestamp, @@ -1076,10 +1051,10 @@ module.exports = class bittrex extends Exchange { 'price': limit, 'stopPrice': undefined, 'cost': proceeds, - 'average': average, + 'average': undefined, 'amount': quantity, 'filled': fillQuantity, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': { 'cost': commission, @@ -1087,7 +1062,7 @@ module.exports = class bittrex extends Exchange { }, 'info': order, 'trades': undefined, - }; + }); } parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { @@ -1136,9 +1111,9 @@ module.exports = class bittrex extends Exchange { 'side': this.safeString (order, 'side'), 'order': this.safeString (order, 'id'), 'type': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'average'), - 'amount': this.safeFloat (order, 'filled'), - 'cost': this.safeFloat (order, 'cost'), + 'price': this.safeNumber (order, 'average'), + 'amount': this.safeNumber (order, 'filled'), + 'cost': this.safeNumber (order, 'cost'), 'symbol': this.safeString (order, 'symbol'), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitvavo.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitvavo.js index e6633b568..ef66620ca 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitvavo.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitvavo.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadSymbol, AuthenticationError, InsufficientFunds, InvalidOrder, ArgumentsRequired, OrderNotFound, InvalidAddress, BadRequest, RateLimitExceeded, PermissionDenied, ExchangeNotAvailable, AccountSuspended, OnMaintenance } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -306,7 +307,7 @@ module.exports = class bitvavo extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minOrderInBaseAsset'), + 'min': this.safeNumber (market, 'minOrderInBaseAsset'), 'max': undefined, }, 'price': { @@ -314,7 +315,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderInQuoteAsset'), + 'min': this.safeNumber (market, 'minOrderInQuoteAsset'), 'max': undefined, }, }, @@ -377,7 +378,7 @@ module.exports = class bitvavo extends Exchange { 'code': code, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -393,7 +394,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMinAmount'), + 'min': this.safeNumber (currency, 'withdrawalMinAmount'), 'max': undefined, }, }, @@ -450,14 +451,14 @@ module.exports = class bitvavo extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); + const last = this.safeNumber (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -469,12 +470,12 @@ module.exports = class bitvavo extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': vwap, 'open': open, 'close': last, @@ -490,14 +491,6 @@ module.exports = class bitvavo extends Exchange { return result; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24h (params); @@ -611,12 +604,11 @@ module.exports = class bitvavo extends Exchange { // feeCurrency: 'EUR' // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'side'); const id = this.safeString2 (trade, 'id', 'fillId'); @@ -627,7 +619,7 @@ module.exports = class bitvavo extends Exchange { if (taker !== undefined) { takerOrMaker = taker ? 'taker' : 'maker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); @@ -698,11 +690,11 @@ module.exports = class bitvavo extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -750,13 +742,12 @@ module.exports = class bitvavo extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'inOrder'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'inOrder'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDepositAddress (code, params = {}) { @@ -806,7 +797,7 @@ module.exports = class bitvavo extends Exchange { if (price !== undefined) { cost = amount * price; } else { - cost = this.safeFloat2 (params, 'cost', 'amountQuote'); + cost = this.safeNumber2 (params, 'cost', 'amountQuote'); } if (cost !== undefined) { const precision = market['precision']['price']; @@ -819,7 +810,7 @@ module.exports = class bitvavo extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['amount'] = this.amountToPrecision (symbol, amount); } else if (isStopMarket || isStopLimit) { - let stopPrice = this.safeFloat2 (params, 'stopPrice', 'triggerAmount'); + let stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerAmount'); if (stopPrice === undefined) { if (isStopLimit) { throw new ArgumentsRequired (this.id + ' createOrder requires a stopPrice parameter for a ' + type + ' order'); @@ -881,7 +872,7 @@ module.exports = class bitvavo extends Exchange { await this.loadMarkets (); const market = this.market (symbol); let request = {}; - const amountRemaining = this.safeFloat (params, 'amountRemaining'); + const amountRemaining = this.safeNumber (params, 'amountRemaining'); params = this.omit (params, 'amountRemaining'); if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); @@ -946,7 +937,6 @@ module.exports = class bitvavo extends Exchange { throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument'); } await this.loadMarkets (); - await this.loadMarkets (); const market = this.market (symbol); const request = { 'orderId': id, @@ -1172,26 +1162,13 @@ module.exports = class bitvavo extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let remaining = this.safeFloat (order, 'amountRemaining'); - let filled = this.safeFloat (order, 'filledAmount'); - const remainingCost = this.safeFloat (order, 'remainingCost'); - if ((remainingCost !== undefined) && (remainingCost === 0.0)) { - remaining = 0; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - const cost = this.safeFloat (order, 'filledAmountQuote'); - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amountRemaining'); + const filled = this.safeNumber (order, 'filledAmount'); + const cost = this.safeNumber (order, 'filledAmountQuote'); let fee = undefined; - const feeCost = this.safeFloat (order, 'feePaid'); + const feeCost = this.safeNumber (order, 'feePaid'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1200,32 +1177,24 @@ module.exports = class bitvavo extends Exchange { 'currency': feeCurrencyCode, }; } - let lastTradeTimestamp = undefined; - const rawTrades = this.safeValue (order, 'fills'); - let trades = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'symbol': symbol, - 'order': id, - 'side': side, - }); - const numTrades = trades.length; - if (numTrades > 0) { - const lastTrade = this.safeValue (trades, numTrades - 1); - lastTradeTimestamp = lastTrade['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'symbol': symbol, + 'order': id, + 'side': side, + 'type': type, + }); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = this.safeValue (order, 'postOnly'); // https://github.com/ccxt/ccxt/issues/8489 - const stopPrice = this.safeFloat (order, 'triggerPrice'); - return { + const stopPrice = this.safeNumber (order, 'triggerPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -1235,13 +1204,13 @@ module.exports = class bitvavo extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1436,11 +1405,11 @@ module.exports = class bitvavo extends Exchange { const currencyId = this.safeString (transaction, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitz.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitz.js index 816bb15a4..d78900841 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitz.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitz.js @@ -59,7 +59,7 @@ module.exports = class bitz extends Exchange { 'assets': 'https://{hostname}', }, 'www': 'https://www.bitz.com', - 'doc': 'https://apidoc.bitz.com/en/', + 'doc': 'https://apidocv2.bitz.plus/en/', 'fees': 'https://www.bitz.com/fee?type=1', 'referral': 'https://u.bitz.com/register?invite_code=1429193', }, @@ -76,6 +76,11 @@ module.exports = class bitz extends Exchange { 'currencyRate', 'currencyCoinRate', 'coinRate', + 'getContractCoin', + 'getContractKline', + 'getContractOrderBook', + 'getContractTradesHistory', + 'getContractTickers', ], }, 'trade': { @@ -88,6 +93,10 @@ module.exports = class bitz extends Exchange { 'getUserNowEntrustSheet', // open orders 'getEntrustSheetInfo', // order 'depositOrWithdraw', // transactions + 'getCoinAddress', + 'getCoinAddressList', + 'marketTrade', + 'addEntrustSheetBatch', ], }, 'assets': { @@ -95,6 +104,20 @@ module.exports = class bitz extends Exchange { 'getUserAssets', ], }, + 'contract': { + 'post': [ + 'addContractTrade', + 'cancelContractTrade', + 'getContractActivePositions', + 'getContractAccountInfo', + 'getContractMyPositions', + 'getContractOrderResult', + 'getContractTradeResult', + 'getContractOrder', + 'getContractMyHistoryTrade', + 'getContractMyTrades', + ], + }, }, 'fees': { 'trading': { @@ -281,8 +304,8 @@ module.exports = class bitz extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTrade'), - 'max': this.safeFloat (market, 'maxTrade'), + 'min': this.safeNumber (market, 'minTrade'), + 'max': this.safeNumber (market, 'maxTrade'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -331,12 +354,12 @@ module.exports = class bitz extends Exchange { const currencyId = this.safeString (balance, 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lock'); - account['total'] = this.safeFloat (balance, 'num'); - account['free'] = this.safeFloat (balance, 'over'); + account['used'] = this.safeString (balance, 'lock'); + account['total'] = this.safeString (balance, 'num'); + account['free'] = this.safeString (balance, 'over'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTicker (ticker, market = undefined) { @@ -366,8 +389,8 @@ module.exports = class bitz extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'now'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'now'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -378,22 +401,22 @@ module.exports = class bitz extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': undefined, 'open': open, 'close': last, 'last': last, 'previousClose': undefined, 'change': change, - 'percentage': this.safeFloat (ticker, 'priceChange24h'), + 'percentage': this.safeNumber (ticker, 'priceChange24h'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -583,8 +606,8 @@ module.exports = class bitz extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'p'); - const amount = this.safeFloat (trade, 'n'); + const price = this.safeNumber (trade, 'p'); + const amount = this.safeNumber (trade, 'n'); let cost = undefined; if (price !== undefined) { if (amount !== undefined) { @@ -652,11 +675,11 @@ module.exports = class bitz extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -754,22 +777,17 @@ module.exports = class bitz extends Exchange { if (side !== undefined) { side = (side === 'sale') ? 'sell' : 'buy'; } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'number'); - const remaining = this.safeFloat (order, 'numberOver'); - const filled = this.safeFloat (order, 'numberDeal'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'number'); + const remaining = this.safeNumber (order, 'numberOver'); + const filled = this.safeNumber (order, 'numberDeal'); let timestamp = this.safeInteger (order, 'timestamp'); if (timestamp === undefined) { timestamp = this.safeTimestamp (order, 'created'); } - let cost = this.safeFloat (order, 'orderTotalPrice'); - if (price !== undefined) { - if (filled !== undefined) { - cost = filled * price; - } - } + const cost = this.safeNumber (order, 'orderTotalPrice'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -791,7 +809,7 @@ module.exports = class bitz extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1118,7 +1136,7 @@ module.exports = class bitz extends Exchange { const type = this.safeStringLower (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'network_fee'); + const feeCost = this.safeNumber (transaction, 'network_fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1133,7 +1151,7 @@ module.exports = class bitz extends Exchange { 'address': this.safeString (transaction, 'wallet'), 'tag': this.safeString (transaction, 'memo'), 'type': type, - 'amount': this.safeFloat (transaction, 'number'), + 'amount': this.safeNumber (transaction, 'number'), 'currency': code, 'status': status, 'updated': timestamp, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bl3p.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bl3p.js index bb84442ec..832b5dc6f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bl3p.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bl3p.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -81,17 +82,19 @@ module.exports = class bl3p extends Exchange { const available = this.safeValue (wallet, 'available', {}); const balance = this.safeValue (wallet, 'balance', {}); const account = this.account (); - account['free'] = this.safeFloat (available, 'value'); - account['total'] = this.safeFloat (balance, 'value'); + account['free'] = this.safeString (available, 'value'); + account['total'] = this.safeString (balance, 'value'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { + const price = this.safeNumber (bidask, priceKey); + const size = this.safeNumber (bidask, amountKey); return [ - bidask[priceKey] / 100000.0, - bidask[amountKey] / 100000000.0, + price / 100000.0, + size / 100000000.0, ]; } @@ -111,16 +114,16 @@ module.exports = class bl3p extends Exchange { }; const ticker = await this.publicGetMarketTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -130,7 +133,7 @@ module.exports = class bl3p extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker['volume'], '24h'), + 'baseVolume': this.safeNumber (ticker['volume'], '24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -139,20 +142,13 @@ module.exports = class bl3p extends Exchange { parseTrade (trade, market = undefined) { const id = this.safeString (trade, 'trade_id'); const timestamp = this.safeInteger (trade, 'date'); - let price = this.safeFloat (trade, 'price_int'); - if (price !== undefined) { - price /= 100000.0; - } - let amount = this.safeFloat (trade, 'amount_int'); - if (amount !== undefined) { - amount /= 100000000.0; - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + let priceString = this.safeString (trade, 'price_int'); + priceString = Precise.stringDiv (priceString, '100000'); + let amountString = this.safeString (trade, 'amount_int'); + amountString = Precise.stringDiv (amountString, '100000000'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bleutrade.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bleutrade.js index 67262da33..01e7d30ce 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bleutrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bleutrade.js @@ -163,8 +163,8 @@ module.exports = class bleutrade extends Exchange { 'code': code, 'name': this.safeString (item, 'AssetLong'), 'active': this.safeValue (item, 'IsActive') && !this.safeValue (item, 'MaintenanceMode'), - 'fee': this.safeFloat (item, 'WithdrawTxFee'), - 'precision': this.safeFloat (item, 'DecimalPlaces'), + 'fee': this.safeNumber (item, 'WithdrawTxFee'), + 'precision': this.safeNumber (item, 'DecimalPlaces'), 'info': item, 'limits': this.limits, }; @@ -216,7 +216,7 @@ module.exports = class bleutrade extends Exchange { 'taker': this.fees['trading']['taker'], 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinTradeSize'), + 'min': this.safeNumber (market, 'MinTradeSize'), 'max': undefined, }, 'price': { @@ -292,8 +292,8 @@ module.exports = class bleutrade extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'TimeStamp')); const marketId = this.safeString (ticker, 'MarketName'); const symbol = this.safeSymbol (marketId, market, '_'); - const previous = this.safeFloat (ticker, 'PrevDay'); - const last = this.safeFloat (ticker, 'Last'); + const previous = this.safeNumber (ticker, 'PrevDay'); + const last = this.safeNumber (ticker, 'Last'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -308,11 +308,11 @@ module.exports = class bleutrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'High'), - 'low': this.safeFloat (ticker, 'Low'), - 'bid': this.safeFloat (ticker, 'Bid'), + 'high': this.safeNumber (ticker, 'High'), + 'low': this.safeNumber (ticker, 'Low'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': previous, @@ -322,8 +322,8 @@ module.exports = class bleutrade extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume'), - 'quoteVolume': this.safeFloat (ticker, 'BaseVolume'), + 'baseVolume': this.safeNumber (ticker, 'Volume'), + 'quoteVolume': this.safeNumber (ticker, 'BaseVolume'), 'info': ticker, }; } @@ -331,11 +331,11 @@ module.exports = class bleutrade extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (ohlcv['TimeStamp'] + '+00:00'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -411,11 +411,11 @@ module.exports = class bleutrade extends Exchange { const currencyId = this.safeString (item, 'Asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (item, 'Available'); - account['total'] = this.safeFloat (item, 'Balance'); + account['free'] = this.safeString (item, 'Available'); + account['total'] = this.safeString (item, 'Balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -558,7 +558,7 @@ module.exports = class bleutrade extends Exchange { // } const timestamp = this.parse8601 (this.safeString (item, 'TimeStamp')); - let amount = this.safeFloat (item, 'Amount'); + let amount = this.safeNumber (item, 'Amount'); let direction = undefined; if (amount !== undefined) { direction = 'in'; @@ -632,27 +632,12 @@ module.exports = class bleutrade extends Exchange { if ('Created' in order) { timestamp = this.parse8601 (order['Created'] + '+00:00'); } - let price = this.safeFloat (order, 'Price'); - let cost = undefined; - const amount = this.safeFloat (order, 'Quantity'); - const remaining = this.safeFloat (order, 'QuantityRemaining'); - let filled = undefined; - if (amount !== undefined && remaining !== undefined) { - filled = amount - remaining; - } - if (!cost) { - if (price && filled) { - cost = price * filled; - } - } - if (!price) { - if (cost && filled) { - price = cost / filled; - } - } - const average = this.safeFloat (order, 'PricePerUnit'); + const price = this.safeNumber (order, 'Price'); + const amount = this.safeNumber (order, 'Quantity'); + const remaining = this.safeNumber (order, 'QuantityRemaining'); + const average = this.safeNumber (order, 'PricePerUnit'); const id = this.safeString (order, 'OrderID'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -666,15 +651,15 @@ module.exports = class bleutrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -711,7 +696,7 @@ module.exports = class bleutrade extends Exchange { // Symbol: 'BTC' } // const id = this.safeString (transaction, 'ID'); - let amount = this.safeFloat (transaction, 'Amount'); + let amount = this.safeNumber (transaction, 'Amount'); let type = 'deposit'; if (amount < 0) { amount = Math.abs (amount); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/braziliex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/braziliex.js index 0c54e4840..31a519468 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/braziliex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/braziliex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -184,11 +185,11 @@ module.exports = class braziliex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': this.safeFloat (currency, 'txWithdrawalFee'), + 'fee': this.safeNumber (currency, 'txWithdrawalFee'), }, 'deposit': { 'active': canDeposit, - 'fee': this.safeFloat (currency, 'txDepositFee'), + 'fee': this.safeNumber (currency, 'txDepositFee'), }, }, 'limits': { @@ -205,11 +206,11 @@ module.exports = class braziliex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'MinWithdrawal'), + 'min': this.safeNumber (currency, 'MinWithdrawal'), 'max': Math.pow (10, precision), }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, }, @@ -257,9 +258,9 @@ module.exports = class braziliex extends Exchange { const quoteIsFiat = this.safeInteger (quoteCurrency, 'is_fiat', 0); let minCost = undefined; if (quoteIsFiat) { - minCost = this.safeFloat (baseCurrency, 'minAmountTradeFIAT'); + minCost = this.safeNumber (baseCurrency, 'minAmountTradeFIAT'); } else { - minCost = this.safeFloat (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); + minCost = this.safeNumber (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); } const isActive = this.safeInteger (market, 'active'); const active = (isActive === 1); @@ -302,27 +303,27 @@ module.exports = class braziliex extends Exchange { symbol = market['symbol']; } const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highestBid24'), - 'low': this.safeFloat (ticker, 'lowestAsk24'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'highestBid24'), + 'low': this.safeNumber (ticker, 'lowestAsk24'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'percentChange'), + 'change': this.safeNumber (ticker, 'percentChange'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume24'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume24'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24'), 'info': ticker, }; } @@ -362,13 +363,18 @@ module.exports = class braziliex extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString2 (trade, 'date_exec', 'date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } - const cost = this.safeFloat (trade, 'total'); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_number'); const type = 'limit'; const side = this.safeString (trade, 'type'); @@ -410,11 +416,11 @@ module.exports = class braziliex extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -436,21 +442,16 @@ module.exports = class braziliex extends Exchange { if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'date')); } - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'total', 0.0); - const amount = this.safeFloat (order, 'amount'); - const filledPercentage = this.safeFloat (order, 'progress'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'total'); + const amount = this.safeNumber (order, 'amount'); + const filledPercentage = this.safeNumber (order, 'progress'); const filled = amount * filledPercentage; - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); - let info = order; - if ('info' in info) { - info = order['info']; - } const id = this.safeString (order, 'order_number'); const fee = this.safeValue (order, 'fee'); // propagated from createOrder const status = (filledPercentage === 1.0) ? 'closed' : 'open'; const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -467,12 +468,12 @@ module.exports = class braziliex extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, - 'info': info, + 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -524,7 +525,7 @@ module.exports = class braziliex extends Exchange { 'price': this.safeString (priceParts, 1), 'total': this.safeString (totalParts, 1), 'fee': { - 'cost': this.safeFloat (feeParts, 1), + 'cost': this.safeNumber (feeParts, 1), 'currency': this.safeString (feeParts, 2), }, 'progress': '0.0', diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcalpha.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcalpha.js index 820234604..f7a890dfb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcalpha.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcalpha.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -145,8 +146,8 @@ module.exports = class btcalpha extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -198,14 +199,11 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'id', 'tid'); const side = this.safeString2 (trade, 'my_side', 'side'); const orderId = this.safeString (trade, 'o_id'); @@ -254,11 +252,11 @@ module.exports = class btcalpha extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -295,11 +293,11 @@ module.exports = class btcalpha extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'reserve'); - account['total'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserve'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -320,8 +318,8 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (order, 'date'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString2 (order, 'oid', 'id'); let trades = this.safeValue (order, 'trades', []); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcbox.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcbox.js index 1a5f82456..48a455625 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcbox.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcbox.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, InvalidOrder, AuthenticationError, PermissionDenied, InvalidNonce, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -88,12 +89,12 @@ module.exports = class btcbox extends Exchange { if (free in response) { const account = this.account (); const used = currencyId + '_lock'; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -114,16 +115,16 @@ module.exports = class btcbox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -133,8 +134,8 @@ module.exports = class btcbox extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -158,14 +159,11 @@ module.exports = class btcbox extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeString (trade, 'type'); return { @@ -265,15 +263,15 @@ module.exports = class btcbox extends Exchange { if (datetimeString !== undefined) { timestamp = this.parse8601 (order['datetime'] + '+09:00'); // Tokyo time } - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let cost = undefined; if (price !== undefined) { if (filled !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcmarkets.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcmarkets.js index 2340d1960..44cdd0f78 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcmarkets.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcmarkets.js @@ -246,11 +246,11 @@ module.exports = class btcmarkets extends Exchange { const tagTo = tag; const addressFrom = undefined; const tagFrom = undefined; - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const currencyId = this.safeString (transaction, 'assetName'); const code = this.safeCurrencyCode (currencyId); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (fee) { amount -= fee; } @@ -303,10 +303,10 @@ module.exports = class btcmarkets extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const fees = this.safeValue (this.safeValue (this.options, 'fees', {}), quote, this.fees); - const pricePrecision = this.safeFloat (market, 'priceDecimals'); - const amountPrecision = this.safeFloat (market, 'amountDecimals'); - const minAmount = this.safeFloat (market, 'minOrderAmount'); - const maxAmount = this.safeFloat (market, 'maxOrderAmount'); + const pricePrecision = this.safeNumber (market, 'priceDecimals'); + const amountPrecision = this.safeNumber (market, 'amountDecimals'); + const minAmount = this.safeNumber (market, 'minOrderAmount'); + const maxAmount = this.safeNumber (market, 'maxOrderAmount'); let minPrice = undefined; if (quote === 'AUD') { minPrice = Math.pow (10, -pricePrecision); @@ -365,14 +365,12 @@ module.exports = class btcmarkets extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetName'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance, 'balance'); - const used = this.safeFloat (balance, 'locked'); const account = this.account (); - account['used'] = used; - account['total'] = total; + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -388,11 +386,11 @@ module.exports = class btcmarkets extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 0)), - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 2), // high - this.safeFloat (ohlcv, 3), // low - this.safeFloat (ohlcv, 4), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 2), // high + this.safeNumber (ohlcv, 3), // low + this.safeNumber (ohlcv, 4), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -488,21 +486,21 @@ module.exports = class btcmarkets extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'lastPrice'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); - const quoteVolume = this.safeFloat (ticker, 'volumeQte24h'); + const last = this.safeNumber (ticker, 'lastPrice'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); + const quoteVolume = this.safeNumber (ticker, 'volumeQte24h'); const vwap = this.vwap (baseVolume, quoteVolume); - const change = this.safeFloat (ticker, 'price24h'); - const percentage = this.safeFloat (ticker, 'pricePct24h'); + const change = this.safeNumber (ticker, 'price24h'); + const percentage = this.safeNumber (ticker, 'pricePct24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bestBid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'bestAsk'), + 'ask': this.safeNumber (ticker, 'bestAsk'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -613,8 +611,8 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -623,7 +621,7 @@ module.exports = class btcmarkets extends Exchange { } const orderId = this.safeString (trade, 'orderId'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -714,7 +712,7 @@ module.exports = class btcmarkets extends Exchange { } } if (triggerPriceIsRequired) { - const triggerPrice = this.safeFloat (params, 'triggerPrice'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); params = this.omit (params, 'triggerPrice'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a triggerPrice parameter for a ' + type + 'order'); @@ -847,9 +845,9 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const type = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'openAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'openAmount'); let filled = undefined; if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); @@ -864,7 +862,7 @@ module.exports = class btcmarkets extends Exchange { const id = this.safeString (order, 'orderId'); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btctradeua.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btctradeua.js index 011bc33b6..32527f881 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btctradeua.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btctradeua.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -106,10 +107,10 @@ module.exports = class btctradeua extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -249,14 +250,11 @@ module.exports = class btctradeua extends Exchange { const id = this.safeString (trade, 'id'); const type = 'limit'; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amnt_trade'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amnt_trade'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -337,11 +335,11 @@ module.exports = class btctradeua extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'amnt_trade'), + 'amount': this.safeNumber (order, 'amnt_trade'), 'filled': 0, - 'remaining': this.safeFloat (order, 'amnt_trade'), + 'remaining': this.safeNumber (order, 'amnt_trade'), 'trades': undefined, 'info': order, 'cost': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcturk.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcturk.js index 32ea74550..2ef97bc99 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcturk.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/btcturk.js @@ -125,13 +125,13 @@ module.exports = class btcturk extends Exchange { const used = currency['id'] + '_reserved'; if (free in response) { const account = this.account (); - account['free'] = this.safeFloat (response, free); - account['total'] = this.safeFloat (response, total); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['total'] = this.safeString (response, total); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -151,26 +151,26 @@ module.exports = class btcturk extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'average'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -204,8 +204,8 @@ module.exports = class btcturk extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -247,11 +247,11 @@ module.exports = class btcturk extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (this.safeString (ohlcv, 'Time')), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/buda.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/buda.js index e78c228ea..ac71ec42b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/buda.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/buda.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { AddressPending, AuthenticationError, ExchangeError, NotSupported, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -220,7 +221,7 @@ module.exports = class buda extends Exchange { } const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); - const precision = this.safeFloat (currency, 'input_decimals'); + const precision = this.safeNumber (currency, 'input_decimals'); const minimum = Math.pow (10, -precision); result[code] = { 'id': id, @@ -381,24 +382,25 @@ module.exports = class buda extends Exchange { let timestamp = undefined; let side = undefined; const type = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; const order = undefined; const fee = undefined; let symbol = undefined; - let cost = undefined; if (market) { symbol = market['symbol']; } if (Array.isArray (trade)) { - timestamp = parseInt (trade[0]); - price = parseFloat (trade[1]); - amount = parseFloat (trade[2]); - cost = price * amount; - side = trade[3]; - id = trade[4].toString (); + timestamp = this.safeInteger (trade, 0); + priceString = this.safeString (trade, 1); + amountString = this.safeString (trade, 2); + side = this.safeString (trade, 3); + id = this.safeString (trade, 4); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': order, @@ -453,11 +455,11 @@ module.exports = class buda extends Exchange { const currencyId = this.safeString (balance, 'id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = parseFloat (balance['available_amount'][0]); - account['total'] = parseFloat (balance['amount'][0]); + account['free'] = this.safeString (balance['available_amount'], 0); + account['total'] = this.safeString (balance['amount'], 0); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -565,15 +567,15 @@ module.exports = class buda extends Exchange { const side = this.safeStringLower (order, 'type'); const status = this.parseOrderStatus (this.safeString (order, 'state')); const originalAmount = this.safeValue (order, 'original_amount', []); - const amount = this.safeFloat (originalAmount, 0); + const amount = this.safeNumber (originalAmount, 0); const remainingAmount = this.safeValue (order, 'amount', []); - const remaining = this.safeFloat (remainingAmount, 0); + const remaining = this.safeNumber (remainingAmount, 0); const tradedAmount = this.safeValue (order, 'traded_amount', []); - const filled = this.safeFloat (tradedAmount, 0); + const filled = this.safeNumber (tradedAmount, 0); const totalExchanged = this.safeValue (order, 'totalExchanged', []); - const cost = this.safeFloat (totalExchanged, 0); + const cost = this.safeNumber (totalExchanged, 0); const limitPrice = this.safeValue (order, 'limit', []); - let price = this.safeFloat (limitPrice, 0); + let price = this.safeNumber (limitPrice, 0); if (price === undefined) { if (limitPrice !== undefined) { price = limitPrice; @@ -584,7 +586,7 @@ module.exports = class buda extends Exchange { average = this.priceToPrecision (symbol, cost / filled); } const paidFee = this.safeValue (order, 'paid_fee', []); - const feeCost = this.safeFloat (paidFee, 0); + const feeCost = this.safeNumber (paidFee, 0); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (paidFee, 1); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bw.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bw.js index 388946b39..4fb3b4192 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bw.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bw.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { RateLimitExceeded, BadSymbol, OrderNotFound, ExchangeError, AuthenticationError, ArgumentsRequired, ExchangeNotAvailable } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -185,7 +186,7 @@ module.exports = class bw extends Exchange { const symbol = base + '/' + quote; const state = this.safeInteger (market, 'state'); const active = (state === 1); - const fee = this.safeFloat (market, 'defaultFee'); + const fee = this.safeNumber (market, 'defaultFee'); result.push ({ 'id': id, 'active': active, @@ -206,7 +207,7 @@ module.exports = class bw extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -292,11 +293,11 @@ module.exports = class bw extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'drawFee'), + 'fee': this.safeNumber (currency, 'drawFee'), 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'limitAmount', 0), + 'min': this.safeNumber (currency, 'limitAmount', 0), 'max': undefined, }, 'price': { @@ -309,7 +310,7 @@ module.exports = class bw extends Exchange { }, 'withdraw': { 'min': undefined, - 'max': this.safeFloat (currency, 'onceDrawLimit'), + 'max': this.safeNumber (currency, 'onceDrawLimit'), }, }, }; @@ -346,9 +347,9 @@ module.exports = class bw extends Exchange { 'high': parseFloat (this.safeValue (ticker, 2)), 'low': parseFloat (this.safeValue (ticker, 3)), 'bid': parseFloat (this.safeValue (ticker, 7)), - 'bidVolume': this.safeFloat (bid, 'quantity'), + 'bidVolume': this.safeNumber (bid, 'quantity'), 'ask': parseFloat (this.safeValue (ticker, 8)), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, 'open': undefined, 'close': close, @@ -477,8 +478,11 @@ module.exports = class bw extends Exchange { // ... // const timestamp = this.safeTimestamp (trade, 2); - const price = this.safeFloat (trade, 5); - const amount = this.safeFloat (trade, 6); + const priceString = this.safeString (trade, 5); + const amountString = this.safeString (trade, 6); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 1); let symbol = undefined; if (marketId !== undefined) { @@ -495,12 +499,6 @@ module.exports = class bw extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const sideString = this.safeString (trade, 4); const side = (sideString === 'ask') ? 'sell' : 'buy'; return { @@ -514,7 +512,7 @@ module.exports = class bw extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': parseFloat (cost), + 'cost': cost, 'fee': undefined, 'info': trade, }; @@ -571,11 +569,11 @@ module.exports = class bw extends Exchange { // return [ this.safeTimestamp (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - this.safeFloat (ohlcv, 6), - this.safeFloat (ohlcv, 7), - this.safeFloat (ohlcv, 8), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + this.safeNumber (ohlcv, 6), + this.safeNumber (ohlcv, 7), + this.safeNumber (ohlcv, 8), ]; } @@ -633,11 +631,11 @@ module.exports = class bw extends Exchange { const currencyId = this.safeString (balance, 'currencyTypeId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'amount'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'amount'); + account['used'] = this.safeString (balance, 'freeze'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -733,25 +731,13 @@ module.exports = class bw extends Exchange { } else if (side === '1') { side = 'buy'; } - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'completeAmount'); - let remaining = this.safeFloat2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available - let cost = this.safeFloat (order, 'totalMoney'); - if (filled !== undefined) { - if (amount !== undefined) { - if (remaining === undefined) { - remaining = amount - filled; - } - } - if (cost === undefined) { - if (price !== undefined) { - cost = filled * cost; - } - } - } + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'completeAmount'); + const remaining = this.safeNumber2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available + const cost = this.safeNumber (order, 'totalMoney'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'entrustId'), 'clientOrderId': undefined, @@ -773,7 +759,7 @@ module.exports = class bw extends Exchange { 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1069,12 +1055,12 @@ module.exports = class bw extends Exchange { code = currency['code']; } const type = ('depositId' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat2 (transaction, 'actuallyAmount', 'amount'); + const amount = this.safeNumber2 (transaction, 'actuallyAmount', 'amount'); const status = this.parseTransactionStatus (this.safeString2 (transaction, 'verifyStatus', 'state')); const timestamp = this.safeInteger (transaction, 'createTime'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bybit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bybit.js index f74d0db18..7f818c6e3 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bybit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bybit.js @@ -42,6 +42,7 @@ module.exports = class bybit extends Exchange { 'fetchTrades': true, 'fetchTransactions': false, 'fetchWithdrawals': true, + 'fetchPositions': true, }, 'timeframes': { '1m': '1', @@ -73,6 +74,34 @@ module.exports = class bybit extends Exchange { 'referral': 'https://www.bybit.com/app/register?ref=X7Prm', }, 'api': { + 'futures': { + 'private': { + 'get': [ + 'position/list', + 'order/list', + 'order', + 'stop-order/list', + 'stop-order', + 'execution/list', + 'trade/closed-pnl/list', + ], + 'post': [ + 'order/create', + 'order/cancel', + 'order/cancelAll', + 'order/replace', + 'stop-order/create', + 'stop-order/cancel', + 'stop-order/cancelAll', + 'stop-order/replace', + 'position/change-position-margin', + 'position/trading-stop', + 'position/leverage/save', + 'position/switch-mode', + 'position/switch-isolated', + ], + }, + }, 'v2': { 'public': { 'get': [ @@ -286,7 +315,11 @@ module.exports = class bybit extends Exchange { 'LTC/USDT': 'linear', 'XTZ/USDT': 'linear', 'LINK/USDT': 'linear', + 'ADA/USDT': 'linear', + 'DOT/USDT': 'linear', + 'UNI/USDT': 'linear', }, + 'defaultType': 'linear', // may also be inverse or inverseFuture 'code': 'BTC', 'cancelAllOrders': { // 'method': 'v2PrivatePostOrderCancelAll', // v2PrivatePostStopOrderCancelAll @@ -401,8 +434,8 @@ module.exports = class bybit extends Exchange { const lotSizeFilter = this.safeValue (market, 'lot_size_filter', {}); const priceFilter = this.safeValue (market, 'price_filter', {}); const precision = { - 'amount': this.safeFloat (lotSizeFilter, 'qty_step'), - 'price': this.safeFloat (priceFilter, 'tick_size'), + 'amount': this.safeNumber (lotSizeFilter, 'qty_step'), + 'price': this.safeNumber (priceFilter, 'tick_size'), }; const status = this.safeString (market, 'status'); let active = undefined; @@ -416,8 +449,8 @@ module.exports = class bybit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'type': 'future', 'spot': false, 'future': true, @@ -426,12 +459,12 @@ module.exports = class bybit extends Exchange { 'inverse': inverse, 'limits': { 'amount': { - 'min': this.safeFloat (lotSizeFilter, 'min_trading_qty'), - 'max': this.safeFloat (lotSizeFilter, 'max_trading_qty'), + 'min': this.safeNumber (lotSizeFilter, 'min_trading_qty'), + 'max': this.safeNumber (lotSizeFilter, 'max_trading_qty'), }, 'price': { - 'min': this.safeFloat (priceFilter, 'min_price'), - 'max': this.safeFloat (priceFilter, 'max_price'), + 'min': this.safeNumber (priceFilter, 'min_price'), + 'max': this.safeNumber (priceFilter, 'max_price'), }, 'cost': { 'min': undefined, @@ -477,9 +510,9 @@ module.exports = class bybit extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const open = this.safeFloat (ticker, 'prev_price_24h'); - let percentage = this.safeFloat (ticker, 'price_24h_pcnt'); + const last = this.safeNumber (ticker, 'last_price'); + const open = this.safeNumber (ticker, 'prev_price_24h'); + let percentage = this.safeNumber (ticker, 'price_24h_pcnt'); if (percentage !== undefined) { percentage *= 100; } @@ -489,18 +522,18 @@ module.exports = class bybit extends Exchange { change = last - open; average = this.sum (open, last) / 2; } - const baseVolume = this.safeFloat (ticker, 'turnover_24h'); - const quoteVolume = this.safeFloat (ticker, 'volume_24h'); + const baseVolume = this.safeNumber (ticker, 'turnover_24h'); + const quoteVolume = this.safeNumber (ticker, 'volume_24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price_24h'), - 'low': this.safeFloat (ticker, 'low_price_24h'), - 'bid': this.safeFloat (ticker, 'bid_price'), + 'high': this.safeNumber (ticker, 'high_price_24h'), + 'low': this.safeNumber (ticker, 'low_price_24h'), + 'bid': this.safeNumber (ticker, 'bid_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask_price'), + 'ask': this.safeNumber (ticker, 'ask_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -649,11 +682,11 @@ module.exports = class bybit extends Exchange { // return [ this.safeTimestamp2 (ohlcv, 'open_time', 'start_at'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat2 (ohlcv, 'turnover', 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber2 (ohlcv, 'turnover', 'volume'), ]; } @@ -779,9 +812,9 @@ module.exports = class bybit extends Exchange { const marketId = this.safeString (trade, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat2 (trade, 'qty', 'exec_qty'); - let cost = this.safeFloat (trade, 'exec_value'); - const price = this.safeFloat2 (trade, 'exec_price', 'price'); + const amount = this.safeNumber2 (trade, 'qty', 'exec_qty'); + let cost = this.safeNumber (trade, 'exec_value'); + const price = this.safeNumber2 (trade, 'exec_price', 'price'); if (cost === undefined) { if (amount !== undefined) { if (price !== undefined) { @@ -796,14 +829,14 @@ module.exports = class bybit extends Exchange { const side = this.safeStringLower (trade, 'side'); const lastLiquidityInd = this.safeString (trade, 'last_liquidity_ind'); const takerOrMaker = (lastLiquidityInd === 'AddedLiquidity') ? 'maker' : 'taker'; - const feeCost = this.safeFloat (trade, 'exec_fee'); + const feeCost = this.safeNumber (trade, 'exec_fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyCode = market['inverse'] ? market['base'] : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'fee_rate'), + 'rate': this.safeNumber (trade, 'fee_rate'), }; } return { @@ -963,12 +996,12 @@ module.exports = class bybit extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['used'] = this.safeFloat (balance, 'used_margin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'used_margin'); + account['total'] = this.safeString (balance, 'equity'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -1095,56 +1128,42 @@ module.exports = class bybit extends Exchange { // const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); - let symbol = undefined; - let base = undefined; + const symbol = market['symbol']; + let feeCurrency = undefined; const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const id = this.safeString2 (order, 'order_id', 'stop_order_id'); const type = this.safeStringLower (order, 'order_type'); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - let average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'qty'); - let cost = this.safeFloat (order, 'cum_exec_value'); - let filled = this.safeFloat (order, 'cum_exec_qty'); - let remaining = this.safeFloat (order, 'leaves_qty'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'qty'); + const cost = this.safeNumber (order, 'cum_exec_value'); + const filled = this.safeNumber (order, 'cum_exec_qty'); + const remaining = this.safeNumber (order, 'leaves_qty'); + const marketTypes = this.safeValue (this.options, 'marketTypes', {}); + const marketType = this.safeString (marketTypes, symbol); if (market !== undefined) { - symbol = market['symbol']; - base = market['base']; + if (marketType === 'linear') { + feeCurrency = market['quote']; + } else { + feeCurrency = market['base']; + } } let lastTradeTimestamp = this.safeTimestamp (order, 'last_exec_time'); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = amount - remaining; - } - if (filled !== undefined) { - if ((remaining === undefined) && (amount !== undefined)) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if ((type === 'market') && (cost !== undefined) && (cost > 0)) { - price = undefined; - if (average === undefined) { - average = filled / cost; - } - } - } const status = this.parseOrderStatus (this.safeString2 (order, 'order_status', 'stop_order_status')); const side = this.safeStringLower (order, 'side'); - let feeCost = this.safeFloat (order, 'cum_exec_fee'); + let feeCost = this.safeNumber (order, 'cum_exec_fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); fee = { 'cost': feeCost, - 'currency': base, + 'currency': feeCurrency, }; } let clientOrderId = this.safeString (order, 'order_link_id'); @@ -1152,9 +1171,9 @@ module.exports = class bybit extends Exchange { clientOrderId = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'stop_px'); + const stopPrice = this.safeNumber (order, 'stop_px'); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1176,7 +1195,7 @@ module.exports = class bybit extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -2027,7 +2046,8 @@ module.exports = class bybit extends Exchange { const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); + const type = this.safeStringLower (transaction, 'type'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -2047,8 +2067,8 @@ module.exports = class bybit extends Exchange { 'tag': undefined, 'tagTo': undefined, 'tagFrom': undefined, - 'type': 'withdrawal', - 'amount': this.safeFloat (transaction, 'amount'), + 'type': type, + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -2131,8 +2151,8 @@ module.exports = class bybit extends Exchange { // const currencyId = this.safeString (item, 'coin'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'wallet_balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'wallet_balance'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -2198,7 +2218,8 @@ module.exports = class bybit extends Exchange { 'recv_window': this.options['recvWindow'], 'timestamp': timestamp, }); - const auth = this.rawencode (this.keysort (query)); + const sortedQuery = this.keysort (query); + const auth = this.rawencode (sortedQuery); const signature = this.hmac (this.encode (auth), this.encode (this.secret)); if (method === 'POST') { body = this.json (this.extend (query, { @@ -2208,7 +2229,7 @@ module.exports = class bybit extends Exchange { 'Content-Type': 'application/json', }; } else { - request += '?' + auth + '&sign=' + signature; + request += '?' + this.urlencode (sortedQuery) + '&sign=' + signature; } } url += request; @@ -2231,12 +2252,43 @@ module.exports = class bybit extends Exchange { // time_now: '1583934106.590436' // } // - const errorCode = this.safeValue (response, 'ret_code'); - if (errorCode !== 0) { + const errorCode = this.safeString (response, 'ret_code'); + if (errorCode !== '0') { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback); this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback); throw new ExchangeError (feedback); // unknown message } } + + async fetchPositions (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (Array.isArray (symbols)) { + const length = symbols.length; + if (length !== 1) { + throw new ArgumentsRequired (this.id + ' fetchPositions takes exactly one symbol'); + } + request['symbol'] = this.marketId (symbols[0]); + } + const defaultType = this.safeString (this.options, 'defaultType', 'linear'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + let response = undefined; + if (type === 'linear') { + response = await this.privateLinearGetPositionList (this.extend (request, params)); + } else if (type === 'inverse') { + response = await this.v2PrivateGetPositionList (this.extend (request, params)); + } else if (type === 'inverseFuture') { + response = await this.futuresPrivateGetPositionList (this.extend (request, params)); + } + // { + // ret_code: 0, + // ret_msg: 'OK', + // ext_code: '', + // ext_info: '', + // result: [] or {} depending on the request + // } + return this.safeValue (response, 'result'); + } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bytetrade.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bytetrade.js index 25953b6f7..ad0c929d8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bytetrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bytetrade.js @@ -186,12 +186,12 @@ module.exports = class bytetrade extends Exchange { const limits = this.safeValue (currency, 'limits'); const deposit = this.safeValue (limits, 'deposit'); const amountPrecision = this.safeInteger (currency, 'basePrecision'); - let maxDeposit = this.safeFloat (deposit, 'max'); + let maxDeposit = this.safeNumber (deposit, 'max'); if (maxDeposit === -1.0) { maxDeposit = undefined; } const withdraw = this.safeValue (limits, 'withdraw'); - let maxWithdraw = this.safeFloat (withdraw, 'max'); + let maxWithdraw = this.safeNumber (withdraw, 'max'); if (maxWithdraw === -1.0) { maxWithdraw = undefined; } @@ -207,11 +207,11 @@ module.exports = class bytetrade extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (deposit, 'min'), + 'min': this.safeNumber (deposit, 'min'), 'max': maxDeposit, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'min'), + 'min': this.safeNumber (withdraw, 'min'), 'max': maxWithdraw, }, }, @@ -265,12 +265,12 @@ module.exports = class bytetrade extends Exchange { 'normalSymbol': normalSymbol, 'limits': { 'amount': { - 'min': this.safeFloat (amount, 'min'), - 'max': this.safeFloat (amount, 'max'), + 'min': this.safeNumber (amount, 'min'), + 'max': this.safeNumber (amount, 'max'), }, 'price': { - 'min': this.safeFloat (price, 'min'), - 'max': this.safeFloat (price, 'max'), + 'min': this.safeNumber (price, 'min'), + 'max': this.safeNumber (price, 'max'), }, 'cost': { 'min': undefined, @@ -298,11 +298,11 @@ module.exports = class bytetrade extends Exchange { const currencyId = this.safeString (balance, 'code'); const code = this.safeCurrencyCode (currencyId, undefined); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'used'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'used'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -363,22 +363,22 @@ module.exports = class bytetrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'open'), - 'close': this.safeFloat (ticker, 'close'), - 'last': this.safeFloat (ticker, 'last'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'open'), + 'close': this.safeNumber (ticker, 'close'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, // previous day close - 'change': this.safeFloat (ticker, 'change'), - 'percentage': this.safeFloat (ticker, 'percentage'), + 'change': this.safeNumber (ticker, 'change'), + 'percentage': this.safeNumber (ticker, 'percentage'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -421,24 +421,16 @@ module.exports = class bytetrade extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetDepth (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetDepth (params); + return this.parseTickers (response, symbols); } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetTickers (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetTickers (params); + return this.parseTickers (response, symbols); } parseOHLCV (ohlcv, market = undefined) { @@ -454,11 +446,11 @@ module.exports = class bytetrade extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -488,9 +480,9 @@ module.exports = class bytetrade extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeInteger (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - const cost = this.safeFloat (trade, 'cost'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + const cost = this.safeNumber (trade, 'cost'); const id = this.safeString (trade, 'id'); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'takerOrMaker'); @@ -560,12 +552,12 @@ module.exports = class bytetrade extends Exchange { const timestamp = this.safeInteger (order, 'timestamp'); const datetime = this.safeString (order, 'datetime'); const lastTradeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled'); - const remaining = this.safeFloat (order, 'remaining'); - const cost = this.safeFloat (order, 'cost'); - const average = this.safeFloat (order, 'average'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled'); + const remaining = this.safeNumber (order, 'remaining'); + const cost = this.safeNumber (order, 'cost'); + const average = this.safeNumber (order, 'average'); const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); @@ -958,7 +950,7 @@ module.exports = class bytetrade extends Exchange { }; } - async transfer (code, amount, address, message = '', params = {}) { + async transfer (code, amount, fromAccount, toAccount, params = {}) { this.checkRequiredDependencies (); if (this.apiKey === undefined) { throw new ArgumentsRequired ('transfer() requires this.apiKey'); @@ -976,6 +968,7 @@ module.exports = class bytetrade extends Exchange { expirationDatetime = expirationDatetime.split ('.')[0]; const feeAmount = '300000000000000'; const defaultDappId = 'Sagittarius'; + const message = this.safeString (params, 'message', ''); const dappId = this.safeString (params, 'dappId', defaultDappId); const eightBytes = this.integerPow ('2', '64'); const byteStringArray = [ @@ -989,8 +982,8 @@ module.exports = class bytetrade extends Exchange { this.numberToLE (feeAmount, 8), // string for 32 bit php this.numberToLE (this.apiKey.length, 1), this.stringToBinary (this.encode (this.apiKey)), - this.numberToLE (address.length, 1), - this.stringToBinary (this.encode (address)), + this.numberToLE (toAccount.length, 1), + this.stringToBinary (this.encode (toAccount)), this.numberToLE (assetType, 4), this.numberToLE (this.integerDivide (amountChain, eightBytes), 8), this.numberToLE (this.integerModulo (amountChain, eightBytes), 8), @@ -1011,7 +1004,7 @@ module.exports = class bytetrade extends Exchange { const operation = { 'fee': '300000000000000', 'from': this.apiKey, - 'to': address, + 'to': toAccount, 'asset_type': parseInt (currency['id']), 'amount': amountChain.toString (), 'message': message, @@ -1165,9 +1158,9 @@ module.exports = class bytetrade extends Exchange { const datetime = this.safeString (transaction, 'datetime'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const feeInfo = this.safeValue (transaction, 'fee'); - const feeCost = this.safeFloat (feeInfo, 'cost'); + const feeCost = this.safeNumber (feeInfo, 'cost'); const feeCurrencyId = this.safeString (feeInfo, 'code'); const feeCode = this.safeCurrencyCode (feeCurrencyId, currency); const fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/cex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/cex.js index 77473d391..876830762 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/cex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/cex.js @@ -256,7 +256,7 @@ module.exports = class cex extends Exchange { 'fee': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimumCurrencyAmount'), + 'min': this.safeNumber (currency, 'minimumCurrencyAmount'), 'max': undefined, }, 'price': { @@ -268,7 +268,7 @@ module.exports = class cex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimalWithdrawalAmount'), + 'min': this.safeNumber (currency, 'minimalWithdrawalAmount'), 'max': undefined, }, }, @@ -351,15 +351,15 @@ module.exports = class cex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minLotSize'), - 'max': this.safeFloat (market, 'maxLotSize'), + 'min': this.safeNumber (market, 'minLotSize'), + 'max': this.safeNumber (market, 'maxLotSize'), }, 'price': { - 'min': this.safeFloat (market, 'minPrice'), - 'max': this.safeFloat (market, 'maxPrice'), + 'min': this.safeNumber (market, 'minPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { - 'min': this.safeFloat (market, 'minLotSizeS2'), + 'min': this.safeNumber (market, 'minLotSizeS2'), 'max': undefined, }, }, @@ -380,13 +380,13 @@ module.exports = class cex extends Exchange { const currencyId = currencyIds[i]; const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); + account['free'] = this.safeString (balance, 'available'); // https://github.com/ccxt/ccxt/issues/5484 - account['used'] = this.safeFloat (balance, 'orders', 0.0); + account['used'] = this.safeString (balance, 'orders', '0'); const code = this.safeCurrencyCode (currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -415,11 +415,11 @@ module.exports = class cex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -461,12 +461,12 @@ module.exports = class cex extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const volume = this.safeFloat (ticker, 'volume'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'last'); + const volume = this.safeNumber (ticker, 'volume'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'last'); let symbol = undefined; if (market) { symbol = market['symbol']; @@ -528,8 +528,8 @@ module.exports = class cex extends Exchange { const id = this.safeString (trade, 'tid'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -601,8 +601,8 @@ module.exports = class cex extends Exchange { // "complete": false // } // - const placedAmount = this.safeFloat (response, 'amount'); - const remaining = this.safeFloat (response, 'pending'); + const placedAmount = this.safeNumber (response, 'amount'); + const remaining = this.safeNumber (response, 'pending'); const timestamp = this.safeValue (response, 'time'); const complete = this.safeValue (response, 'complete'); const status = complete ? 'closed' : 'open'; @@ -621,7 +621,7 @@ module.exports = class cex extends Exchange { 'side': this.safeString (response, 'type'), 'symbol': symbol, 'status': status, - 'price': this.safeFloat (response, 'price'), + 'price': this.safeNumber (response, 'price'), 'amount': placedAmount, 'cost': undefined, 'average': undefined, @@ -663,42 +663,42 @@ module.exports = class cex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - let amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + let amount = this.safeNumber (order, 'amount'); // sell orders can have a negative amount // https://github.com/ccxt/ccxt/issues/5338 if (amount !== undefined) { amount = Math.abs (amount); } - const remaining = this.safeFloat2 (order, 'pending', 'remains'); + const remaining = this.safeNumber2 (order, 'pending', 'remains'); const filled = amount - remaining; let fee = undefined; let cost = undefined; if (market !== undefined) { symbol = market['symbol']; - const taCost = this.safeFloat (order, 'ta:' + market['quote']); - const ttaCost = this.safeFloat (order, 'tta:' + market['quote']); + const taCost = this.safeNumber (order, 'ta:' + market['quote']); + const ttaCost = this.safeNumber (order, 'tta:' + market['quote']); cost = this.sum (taCost, ttaCost); const baseFee = 'fa:' + market['base']; const baseTakerFee = 'tfa:' + market['base']; const quoteFee = 'fa:' + market['quote']; const quoteTakerFee = 'tfa:' + market['quote']; - let feeRate = this.safeFloat (order, 'tradingFeeMaker'); + let feeRate = this.safeNumber (order, 'tradingFeeMaker'); if (!feeRate) { - feeRate = this.safeFloat (order, 'tradingFeeTaker', feeRate); + feeRate = this.safeNumber (order, 'tradingFeeTaker', feeRate); } if (feeRate) { feeRate /= 100.0; // convert to mathematically-correct percentage coefficients: 1.0 = 100% } if ((baseFee in order) || (baseTakerFee in order)) { - const baseFeeCost = this.safeFloat2 (order, baseFee, baseTakerFee); + const baseFeeCost = this.safeNumber2 (order, baseFee, baseTakerFee); fee = { 'currency': market['base'], 'rate': feeRate, 'cost': baseFeeCost, }; } else if ((quoteFee in order) || (quoteTakerFee in order)) { - const quoteFeeCost = this.safeFloat2 (order, quoteFee, quoteTakerFee); + const quoteFeeCost = this.safeNumber2 (order, quoteFee, quoteTakerFee); fee = { 'currency': market['quote'], 'rate': feeRate, @@ -738,7 +738,7 @@ module.exports = class cex extends Exchange { // ds: 0 } continue; } - const tradePrice = this.safeFloat (item, 'price'); + const tradePrice = this.safeNumber (item, 'price'); if (tradePrice === undefined) { // this represents the order // { @@ -842,8 +842,8 @@ module.exports = class cex extends Exchange { // "fee_amount": "0.03" // } const tradeTimestamp = this.parse8601 (this.safeString (item, 'time')); - const tradeAmount = this.safeFloat (item, 'amount'); - const feeCost = this.safeFloat (item, 'fee_amount'); + const tradeAmount = this.safeNumber (item, 'amount'); + const feeCost = this.safeNumber (item, 'fee_amount'); let absTradeAmount = (tradeAmount < 0) ? -tradeAmount : tradeAmount; let tradeCost = undefined; if (tradeSide === 'sell') { @@ -1188,12 +1188,12 @@ module.exports = class cex extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const side = this.safeString (order, 'type'); - const baseAmount = this.safeFloat (order, 'a:' + baseId + ':cds'); - const quoteAmount = this.safeFloat (order, 'a:' + quoteId + ':cds'); - const fee = this.safeFloat (order, 'f:' + quoteId + ':cds'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const remaining = this.safeFloat (order, 'remains'); + const baseAmount = this.safeNumber (order, 'a:' + baseId + ':cds'); + const quoteAmount = this.safeNumber (order, 'a:' + quoteId + ':cds'); + const fee = this.safeNumber (order, 'f:' + quoteId + ':cds'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const remaining = this.safeNumber (order, 'remains'); const filled = amount - remaining; let orderAmount = undefined; let cost = undefined; @@ -1205,10 +1205,10 @@ module.exports = class cex extends Exchange { cost = quoteAmount; average = orderAmount / cost; } else { - const ta = this.safeFloat (order, 'ta:' + quoteId, 0); - const tta = this.safeFloat (order, 'tta:' + quoteId, 0); - const fa = this.safeFloat (order, 'fa:' + quoteId, 0); - const tfa = this.safeFloat (order, 'tfa:' + quoteId, 0); + const ta = this.safeNumber (order, 'ta:' + quoteId, 0); + const tta = this.safeNumber (order, 'tta:' + quoteId, 0); + const fa = this.safeNumber (order, 'fa:' + quoteId, 0); + const tfa = this.safeNumber (order, 'tfa:' + quoteId, 0); if (side === 'sell') { cost = this.sum (this.sum (ta, tta), this.sum (fa, tfa)); } else { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/chilebit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/chilebit.js deleted file mode 100644 index 4aeeb9ec3..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/chilebit.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const foxbit = require ('./foxbit.js'); - -// --------------------------------------------------------------------------- - -module.exports = class chilebit extends foxbit { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'chilebit', - 'name': 'ChileBit', - 'countries': [ 'CL' ], - 'has': { - 'CORS': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg', - 'api': { - 'public': 'https://api.blinktrade.com/api', - 'private': 'https://api.blinktrade.com/tapi', - }, - 'www': 'https://chilebit.net', - 'doc': 'https://blinktrade.com/docs', - }, - 'options': { - 'brokerId': '9', // https://blinktrade.com/docs/#brokers - }, - }); - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbase.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbase.js index cfceba2a4..1413a7064 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbase.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbase.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, RateLimitExceeded, InvalidNonce } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -411,10 +412,10 @@ module.exports = class coinbase extends Exchange { const timestamp = this.parse8601 (this.safeValue (transaction, 'created_at')); const updated = this.parse8601 (this.safeValue (transaction, 'updated_at')); const type = this.safeString (transaction, 'resource'); - const amount = this.safeFloat (subtotalObject, 'amount'); + const amount = this.safeNumber (subtotalObject, 'amount'); const currencyId = this.safeString (subtotalObject, 'currency'); const currency = this.safeCurrencyCode (currencyId); - const feeCost = this.safeFloat (feeObject, 'amount'); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -490,15 +491,12 @@ module.exports = class coinbase extends Exchange { const orderId = undefined; const side = this.safeString (trade, 'resource'); const type = undefined; - const cost = this.safeFloat (subtotalObject, 'amount'); - const amount = this.safeFloat (amountObject, 'amount'); - let price = undefined; - if (cost !== undefined) { - if ((amount !== undefined) && (amount > 0)) { - price = cost / amount; - } - } - const feeCost = this.safeFloat (feeObject, 'amount'); + const costString = this.safeString (subtotalObject, 'amount'); + const amountString = this.safeString (amountObject, 'amount'); + const cost = this.parseNumber (costString); + const amount = this.parseNumber (amountString); + const price = this.parseNumber (Precise.stringDiv (costString, amountString)); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -566,7 +564,7 @@ module.exports = class coinbase extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (quoteCurrency, 'min_size'), + 'min': this.safeNumber (quoteCurrency, 'min_size'), 'max': undefined, }, }, @@ -648,7 +646,7 @@ module.exports = class coinbase extends Exchange { 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min_size'), + 'min': this.safeNumber (currency, 'min_size'), 'max': undefined, }, 'price': { @@ -679,9 +677,9 @@ module.exports = class coinbase extends Exchange { const buy = await this.publicGetPricesSymbolBuy (request); const sell = await this.publicGetPricesSymbolSell (request); const spot = await this.publicGetPricesSymbolSpot (request); - const ask = this.safeFloat (buy['data'], 'amount'); - const bid = this.safeFloat (sell['data'], 'amount'); - const last = this.safeFloat (spot['data'], 'amount'); + const ask = this.safeNumber (buy['data'], 'amount'); + const bid = this.safeNumber (sell['data'], 'amount'); + const last = this.safeNumber (spot['data'], 'amount'); return { 'symbol': symbol, 'timestamp': timestamp, @@ -724,7 +722,7 @@ module.exports = class coinbase extends Exchange { if (this.inArray (balance['type'], accounts)) { const currencyId = this.safeString (balance['balance'], 'currency'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance['balance'], 'amount'); + const total = this.safeNumber (balance['balance'], 'amount'); const free = total; const used = undefined; if (code in result) { @@ -1025,7 +1023,7 @@ module.exports = class coinbase extends Exchange { // } // const amountInfo = this.safeValue (item, 'amount', {}); - let amount = this.safeFloat (amountInfo, 'amount'); + let amount = this.safeNumber (amountInfo, 'amount'); let direction = undefined; if (amount < 0) { direction = 'out'; @@ -1051,7 +1049,7 @@ module.exports = class coinbase extends Exchange { if (feeInfo !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId, currency); - const feeAmount = this.safeFloat (feeInfo, 'amount'); + const feeAmount = this.safeNumber (feeInfo, 'amount'); fee = { 'cost': feeAmount, 'currency': feeCurrencyCode, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbasepro.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbasepro.js index 582c03a61..6d8c48454 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbasepro.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinbasepro.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ArgumentsRequired, ExchangeError, InvalidOrder, InvalidAddress, AuthenticationError, NotSupported, OrderNotFound, OnMaintenance, PermissionDenied, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -239,7 +240,7 @@ module.exports = class coinbasepro extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const details = this.safeValue (currency, 'details', {}); - const precision = this.safeFloat (currency, 'max_precision'); + const precision = this.safeNumber (currency, 'max_precision'); const status = this.safeString (currency, 'status'); const active = (status === 'online'); result[code] = { @@ -253,7 +254,7 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (details, 'min_size'), + 'min': this.safeNumber (details, 'min_size'), 'max': undefined, }, 'price': { @@ -265,7 +266,7 @@ module.exports = class coinbasepro extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (details, 'min_withdrawal_amount'), + 'min': this.safeNumber (details, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -309,12 +310,12 @@ module.exports = class coinbasepro extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const priceLimits = { - 'min': this.safeFloat (market, 'quote_increment'), + 'min': this.safeNumber (market, 'quote_increment'), 'max': undefined, }; const precision = { - 'amount': this.safeFloat (market, 'base_increment'), - 'price': this.safeFloat (market, 'quote_increment'), + 'amount': this.safeNumber (market, 'base_increment'), + 'price': this.safeNumber (market, 'quote_increment'), }; const status = this.safeString (market, 'status'); const active = (status === 'online'); @@ -328,13 +329,13 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': priceLimits, 'cost': { - 'min': this.safeFloat (market, 'min_market_funds'), - 'max': this.safeFloat (market, 'max_market_funds'), + 'min': this.safeNumber (market, 'min_market_funds'), + 'max': this.safeNumber (market, 'max_market_funds'), }, }, 'active': active, @@ -391,14 +392,13 @@ module.exports = class coinbasepro extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'hold'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'hold'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -455,29 +455,29 @@ module.exports = class coinbasepro extends Exchange { // } // const timestamp = this.parse8601 (this.safeValue (ticker, 'time')); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'price'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'price'); const symbol = (market === undefined) ? undefined : market['symbol']; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': undefined, 'ask': ask, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -550,7 +550,7 @@ module.exports = class coinbasepro extends Exchange { if (market !== undefined) { const feeCurrencyId = this.safeStringLower (market, 'quoteId'); const costField = feeCurrencyId + '_value'; - cost = this.safeFloat (trade, costField); + cost = this.safeNumber (trade, costField); feeCurrency = market['quote']; const liquidity = this.safeString (trade, 'liquidity'); if (liquidity !== undefined) { @@ -558,7 +558,7 @@ module.exports = class coinbasepro extends Exchange { feeRate = market[takerOrMaker]; } } - const feeCost = this.safeFloat2 (trade, 'fill_fees', 'fee'); + const feeCost = this.safeNumber2 (trade, 'fill_fees', 'fee'); const fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -572,10 +572,12 @@ module.exports = class coinbasepro extends Exchange { if (orderId !== undefined) { side = (trade['side'] === 'buy') ? 'buy' : 'sell'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - cost = amount * price; + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -637,11 +639,11 @@ module.exports = class coinbasepro extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -721,17 +723,11 @@ module.exports = class coinbasepro extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'filled_size'); - const amount = this.safeFloat (order, 'size', filled); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'executed_value'); - const feeCost = this.safeFloat (order, 'fill_fees'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'filled_size'); + const amount = this.safeNumber (order, 'size', filled); + const cost = this.safeNumber (order, 'executed_value'); + const feeCost = this.safeNumber (order, 'fill_fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -749,9 +745,9 @@ module.exports = class coinbasepro extends Exchange { const side = this.safeString (order, 'side'); const timeInForce = this.safeString (order, 'time_in_force'); const postOnly = this.safeValue (order, 'post_only'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -769,11 +765,11 @@ module.exports = class coinbasepro extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -863,7 +859,7 @@ module.exports = class coinbasepro extends Exchange { request['client_oid'] = clientOrderId; params = this.omit (params, [ 'clientOrderId', 'client_oid' ]); } - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop_price'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stop_price'); if (stopPrice !== undefined) { request['stop_price'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, [ 'stopPrice', 'stop_price' ]); @@ -877,7 +873,7 @@ module.exports = class coinbasepro extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['size'] = this.amountToPrecision (symbol, amount); } else if (type === 'market') { - let cost = this.safeFloat2 (params, 'cost', 'funds'); + let cost = this.safeNumber2 (params, 'cost', 'funds'); if (cost === undefined) { if (price !== undefined) { cost = amount * price; @@ -948,19 +944,6 @@ module.exports = class coinbasepro extends Exchange { return await this.privateDeleteOrders (this.extend (request, params)); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - const cost = amount * price; - const currency = market['quote']; - return { - 'type': takerOrMaker, - 'currency': currency, - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (currency, rate * cost)), - }; - } - async fetchPaymentMethods (params = {}) { return await this.privateGetPaymentMethods (params); } @@ -1099,7 +1082,7 @@ module.exports = class coinbasepro extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (transaction); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let type = this.safeString (transaction, 'type'); let address = this.safeString (details, 'crypto_address'); const tag = this.safeString (details, 'destination_tag'); @@ -1108,7 +1091,7 @@ module.exports = class coinbasepro extends Exchange { if (type === 'withdraw') { type = 'withdrawal'; address = this.safeString (details, 'sent_to_address', address); - const feeCost = this.safeFloat (details, 'fee'); + const feeCost = this.safeNumber (details, 'fee'); if (feeCost !== undefined) { if (amount !== undefined) { amount -= feeCost; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coincheck.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coincheck.js index 807882d02..e7a3db265 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coincheck.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coincheck.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -127,12 +128,12 @@ module.exports = class coincheck extends Exchange { if (currencyId in balances) { const account = this.account (); const reserved = currencyId + '_reserved'; - account['free'] = this.safeFloat (balances, currencyId); - account['used'] = this.safeFloat (balances, reserved); + account['free'] = this.safeString (balances, currencyId); + account['used'] = this.safeString (balances, reserved); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -170,23 +171,13 @@ module.exports = class coincheck extends Exchange { const id = this.safeString (order, 'id'); const side = this.safeString (order, 'order_type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const amount = this.safeFloat (order, 'pending_amount'); - const remaining = this.safeFloat (order, 'pending_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = Math.max (amount - remaining, 0); - if (price !== undefined) { - cost = filled * price; - } - } - } + const amount = this.safeNumber (order, 'pending_amount'); + const remaining = this.safeNumber (order, 'pending_amount'); + const price = this.safeNumber (order, 'rate'); const status = undefined; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -194,7 +185,7 @@ module.exports = class coincheck extends Exchange { 'lastTradeTimestamp': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'side': side, 'type': undefined, 'timeInForce': undefined, @@ -203,12 +194,12 @@ module.exports = class coincheck extends Exchange { 'symbol': symbol, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'info': order, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -232,16 +223,16 @@ module.exports = class coincheck extends Exchange { }; const ticker = await this.publicGetTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -251,7 +242,7 @@ module.exports = class coincheck extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -260,7 +251,7 @@ module.exports = class coincheck extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'rate'); + const priceString = this.safeString (trade, 'rate'); const marketId = this.safeString (trade, 'pair'); market = this.safeValue (this.markets_by_id, marketId, market); let symbol = undefined; @@ -287,7 +278,7 @@ module.exports = class coincheck extends Exchange { } } let takerOrMaker = undefined; - let amount = undefined; + let amountString = undefined; let cost = undefined; let side = undefined; let fee = undefined; @@ -299,24 +290,22 @@ module.exports = class coincheck extends Exchange { takerOrMaker = 'maker'; } const funds = this.safeValue (trade, 'funds', {}); - amount = this.safeFloat (funds, baseId); - cost = this.safeFloat (funds, quoteId); + amountString = this.safeString (funds, baseId); + cost = this.safeNumber (funds, quoteId); fee = { 'currency': this.safeString (trade, 'fee_currency'), - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), }; side = this.safeString (trade, 'side'); orderId = this.safeString (trade, 'order_id'); } else { - amount = this.safeFloat (trade, 'amount'); + amountString = this.safeString (trade, 'amount'); side = this.safeString (trade, 'order_type'); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -387,6 +376,10 @@ module.exports = class coincheck extends Exchange { return await this.privateDeleteExchangeOrdersId (this.extend (request, params)); } + nonce () { + return this.milliseconds (); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let url = this.urls['api'] + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinegg.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinegg.js index e270e3bf7..0b2e2ef89 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinegg.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinegg.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -214,8 +215,8 @@ module.exports = class coinegg extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; let change = undefined; let average = undefined; @@ -229,11 +230,11 @@ module.exports = class coinegg extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -243,8 +244,8 @@ module.exports = class coinegg extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVol'), 'info': ticker, }; } @@ -273,15 +274,12 @@ module.exports = class coinegg extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const type = 'limit'; const side = this.safeString (trade, 'type'); const id = this.safeString (trade, 'tid'); @@ -328,9 +326,9 @@ module.exports = class coinegg extends Exchange { result[code] = this.account (); } const type = (accountType === 'lock') ? 'used' : 'free'; - result[code][type] = this.safeFloat (balances, key); + result[code][type] = this.safeString (balances, key); } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -339,15 +337,9 @@ module.exports = class coinegg extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let status = this.safeString (order, 'status'); if (status === 'cancelled') { status = 'canceled'; @@ -358,7 +350,7 @@ module.exports = class coinegg extends Exchange { const type = 'limit'; const side = this.safeString (order, 'type'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -374,13 +366,13 @@ module.exports = class coinegg extends Exchange { 'stopPrice': undefined, 'cost': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'trades': undefined, 'fee': undefined, 'info': info, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinex.js index cc344ee72..575d0f239 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -196,13 +197,13 @@ module.exports = class coinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': this.safeFloat (market, 'taker_fee_rate'), - 'maker': this.safeFloat (market, 'maker_fee_rate'), + 'taker': this.safeNumber (market, 'taker_fee_rate'), + 'maker': this.safeNumber (market, 'maker_fee_rate'), 'info': market, 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -222,16 +223,16 @@ module.exports = class coinex extends Exchange { symbol = market['symbol']; } ticker = this.safeValue (ticker, 'ticker', {}); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -241,7 +242,7 @@ module.exports = class coinex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat2 (ticker, 'vol', 'volume'), + 'baseVolume': this.safeNumber2 (ticker, 'vol', 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -301,16 +302,18 @@ module.exports = class coinex extends Exchange { } const tradeId = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market); - let cost = this.safeFloat (trade, 'deal_money'); - if (!cost) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); + let cost = this.safeNumber (trade, 'deal_money'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_asset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -363,11 +366,11 @@ module.exports = class coinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -428,11 +431,11 @@ module.exports = class coinex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -471,11 +474,11 @@ module.exports = class coinex extends Exchange { // } // const timestamp = this.safeTimestamp (order, 'create_time'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'deal_money'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'deal_amount'); - const average = this.safeFloat (order, 'avg_price'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'deal_money'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'deal_amount'); + const average = this.safeNumber (order, 'avg_price'); let symbol = undefined; const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); @@ -487,11 +490,11 @@ module.exports = class coinex extends Exchange { feeCurrency = market['quote']; } } - const remaining = this.safeFloat (order, 'left'); + const remaining = this.safeNumber (order, 'left'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -513,10 +516,10 @@ module.exports = class coinex extends Exchange { 'trades': undefined, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'deal_fee'), + 'cost': this.safeNumber (order, 'deal_fee'), }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -762,8 +765,8 @@ module.exports = class coinex extends Exchange { const timestamp = this.safeTimestamp (transaction, 'create_time'); const type = ('coin_withdraw_id' in transaction) ? 'withdraw' : 'deposit'; const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'tx_fee'); + let amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'tx_fee'); if (type === 'deposit') { feeCost = 0; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfalcon.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfalcon.js index 6c264b4ec..8d3077293 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfalcon.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfalcon.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, RateLimitExceeded, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -136,11 +137,11 @@ module.exports = class coinfalcon extends Exchange { 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'change_in_24h'), + 'change': this.safeNumber (ticker, 'change_in_24h'), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -177,20 +178,17 @@ module.exports = class coinfalcon extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } const tradeId = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'order_id'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = this.safeString (trade, 'fee_currency_code'); fee = { @@ -258,14 +256,13 @@ module.exports = class coinfalcon extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available_balance'), - 'used': this.safeFloat (balance, 'hold_balance'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'hold_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -300,19 +297,9 @@ module.exports = class coinfalcon extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'size_filled'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (price !== undefined) { - cost = filled * price; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'size_filled'); const status = this.parseOrderStatus (this.safeString (order, 'status')); let type = this.safeString (order, 'operation_type'); if (type !== undefined) { @@ -321,7 +308,7 @@ module.exports = class coinfalcon extends Exchange { } const side = this.safeString (order, 'order_type'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -334,16 +321,16 @@ module.exports = class coinfalcon extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'lastTradeTimestamp': undefined, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfloor.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfloor.js index 7fff650de..790ac8c50 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfloor.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinfloor.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ExchangeError, InvalidNonce, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -105,14 +106,14 @@ module.exports = class coinfloor extends Exchange { const baseIdLower = this.safeStringLower (market, 'baseId'); const quoteIdLower = this.safeStringLower (market, 'quoteId'); result[base] = { - 'free': this.safeFloat (response, baseIdLower + '_available'), - 'used': this.safeFloat (response, baseIdLower + '_reserved'), - 'total': this.safeFloat (response, baseIdLower + '_balance'), + 'free': this.safeNumber (response, baseIdLower + '_available'), + 'used': this.safeNumber (response, baseIdLower + '_reserved'), + 'total': this.safeNumber (response, baseIdLower + '_balance'), }; result[quote] = { - 'free': this.safeFloat (response, quoteIdLower + '_available'), - 'used': this.safeFloat (response, quoteIdLower + '_reserved'), - 'total': this.safeFloat (response, quoteIdLower + '_balance'), + 'free': this.safeNumber (response, quoteIdLower + '_available'), + 'used': this.safeNumber (response, quoteIdLower + '_reserved'), + 'total': this.safeNumber (response, quoteIdLower + '_balance'), }; return this.parseBalance (result); } @@ -133,22 +134,22 @@ module.exports = class coinfloor extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -177,14 +178,11 @@ module.exports = class coinfloor extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -302,8 +300,8 @@ module.exports = class coinfloor extends Exchange { const parts = key.split ('_'); const numParts = parts.length; if (numParts === 2) { - const tmpBaseAmount = this.safeFloat (item, parts[0]); - const tmpQuoteAmount = this.safeFloat (item, parts[1]); + const tmpBaseAmount = this.safeNumber (item, parts[0]); + const tmpQuoteAmount = this.safeNumber (item, parts[1]); if (tmpBaseAmount !== undefined && tmpQuoteAmount !== undefined) { baseId = parts[0]; quoteId = parts[1]; @@ -319,7 +317,7 @@ module.exports = class coinfloor extends Exchange { const referenceId = this.safeString (item, 'id'); const timestamp = this.parse8601 (this.safeString (item, 'datetime')); let fee = undefined; - const feeCost = this.safeFloat (item, 'fee'); + const feeCost = this.safeNumber (item, 'fee'); const result = { 'id': undefined, 'timestamp': timestamp, @@ -423,8 +421,8 @@ module.exports = class coinfloor extends Exchange { 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, 'type': type, - 'price': this.safeFloat (response, 'price'), - 'remaining': this.safeFloat (response, 'amount'), + 'price': this.safeNumber (response, 'price'), + 'remaining': this.safeNumber (response, 'amount'), 'info': response, }; } @@ -449,19 +447,14 @@ module.exports = class coinfloor extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let side = undefined; const status = this.safeString (order, 'status'); - if (order['type'] === 0) { + const rawType = this.safeString (order, 'type'); + if (rawType === '0') { side = 'buy'; - } else if (order['type'] === 1) { + } else if (rawType === '1') { side = 'sell'; } let symbol = undefined; @@ -469,7 +462,7 @@ module.exports = class coinfloor extends Exchange { symbol = market['symbol']; } const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -487,11 +480,11 @@ module.exports = class coinfloor extends Exchange { 'amount': undefined, 'filled': undefined, 'remaining': amount, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coingi.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coingi.js index 650d80885..931325ea6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coingi.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coingi.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -165,14 +166,14 @@ module.exports = class coingi extends Exchange { const currencyId = this.safeString (balance['currency'], 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - const blocked = this.safeFloat (balance, 'blocked'); - const inOrders = this.safeFloat (balance, 'inOrders'); - const withdrawing = this.safeFloat (balance, 'withdrawing'); - account['used'] = this.sum (blocked, inOrders, withdrawing); + account['free'] = this.safeString (balance, 'available'); + const blocked = this.safeString (balance, 'blocked'); + const inOrders = this.safeString (balance, 'inOrders'); + const withdrawing = this.safeString (balance, 'withdrawing'); + account['used'] = Precise.stringAdd (Precise.stringAdd (blocked, inOrders), withdrawing); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = 512, params = {}) { @@ -198,11 +199,11 @@ module.exports = class coingi extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -212,8 +213,8 @@ module.exports = class coingi extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'counterVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'counterVolume'), 'info': ticker, }; } @@ -246,14 +247,11 @@ module.exports = class coingi extends Exchange { } parseTrade (trade, market = undefined) { - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const id = this.safeString (trade, 'id'); const marketId = this.safeString (trade, 'currencyPair'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmarketcap.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmarketcap.js index 171a65889..85edd4882 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmarketcap.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmarketcap.js @@ -208,16 +208,16 @@ module.exports = class coinmarketcap extends Exchange { if (timestamp === undefined) { timestamp = this.milliseconds (); } - const change = this.safeFloat (ticker, 'percent_change_24h'); + const change = this.safeNumber (ticker, 'percent_change_24h'); let last = undefined; let symbol = undefined; let volume = undefined; if (market !== undefined) { symbol = market['symbol']; const priceKey = 'price_' + market['quoteId']; - last = this.safeFloat (ticker, priceKey); + last = this.safeNumber (ticker, priceKey); const volumeKey = '24h_volume_' + market['quoteId']; - volume = this.safeFloat (ticker, volumeKey); + volume = this.safeNumber (ticker, volumeKey); } return { 'symbol': symbol, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmate.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmate.js index b03ce8783..821e5d7e8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmate.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinmate.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder, OrderNotFound, RateLimitExceeded, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -230,7 +231,7 @@ module.exports = class coinmate extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -258,12 +259,12 @@ module.exports = class coinmate extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -286,16 +287,16 @@ module.exports = class coinmate extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'data'); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'vwap': undefined, 'askVolume': undefined, 'open': undefined, @@ -305,7 +306,7 @@ module.exports = class coinmate extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'amount'), + 'baseVolume': this.safeNumber (ticker, 'amount'), 'quoteVolume': undefined, 'info': ticker, }; @@ -374,8 +375,8 @@ module.exports = class coinmate extends Exchange { // } // const timestamp = this.safeInteger (item, 'timestamp'); - const amount = this.safeFloat (item, 'amount'); - const fee = this.safeFloat (item, 'fee'); + const amount = this.safeNumber (item, 'amount'); + const fee = this.safeNumber (item, 'fee'); const txid = this.safeString (item, 'txid'); const address = this.safeString (item, 'destination'); const tag = this.safeString (item, 'destinationTag'); @@ -453,21 +454,18 @@ module.exports = class coinmate extends Exchange { // const marketId = this.safeString (trade, 'currencyPair'); market = this.safeMarket (marketId, market, '_'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeStringLower2 (trade, 'type', 'tradeType'); const type = this.safeStringLower (trade, 'orderType'); const orderId = this.safeString (trade, 'orderId'); const id = this.safeString (trade, 'transactionId'); const timestamp = this.safeInteger2 (trade, 'timestamp', 'createdTimestamp'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -608,11 +606,11 @@ module.exports = class coinmate extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.safeInteger (order, 'timestamp'); const side = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'originalAmount'); - let remaining = this.safeFloat (order, 'remainingAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'originalAmount'); + let remaining = this.safeNumber (order, 'remainingAmount'); if (remaining === undefined) { - remaining = this.safeFloat (order, 'amount'); + remaining = this.safeNumber (order, 'amount'); } let status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.parseOrderType (this.safeString (order, 'orderTradeType')); @@ -627,11 +625,11 @@ module.exports = class coinmate extends Exchange { cost = filled * price; } } - const average = this.safeFloat (order, 'avgPrice'); + const average = this.safeNumber (order, 'avgPrice'); const marketId = this.safeString (order, 'currencyPair'); const symbol = this.safeSymbol (marketId, market, '_'); const clientOrderId = this.safeString (order, 'clientOrderId'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); return { 'id': id, 'clientOrderId': clientOrderId, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinone.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinone.js index 0c86365b6..cd0f3585c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinone.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinone.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, BadRequest, ExchangeError, ArgumentsRequired, OrderNotFound, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -142,11 +143,11 @@ module.exports = class coinone extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'avail'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -199,13 +200,13 @@ module.exports = class coinone extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const first = this.safeFloat (ticker, 'first'); - const last = this.safeFloat (ticker, 'last'); + const first = this.safeNumber (ticker, 'first'); + const last = this.safeNumber (ticker, 'last'); let average = undefined; if (first !== undefined && last !== undefined) { average = this.sum (first, last) / 2; } - const previousClose = this.safeFloat (ticker, 'yesterday_last'); + const previousClose = this.safeNumber (ticker, 'yesterday_last'); let change = undefined; let percentage = undefined; if (last !== undefined && previousClose !== undefined) { @@ -219,8 +220,8 @@ module.exports = class coinone extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -233,7 +234,7 @@ module.exports = class coinone extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -279,20 +280,17 @@ module.exports = class coinone extends Exchange { side = 'buy'; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'fee'); + let feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); - let feeRate = this.safeFloat (trade, 'feeRate'); + let feeRate = this.safeNumber (trade, 'feeRate'); feeRate = Math.abs (feeRate); let feeCurrencyCode = undefined; if (market !== undefined) { @@ -452,7 +450,7 @@ module.exports = class coinone extends Exchange { // } // const id = this.safeString (order, 'orderId'); - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); const timestamp = this.safeTimestamp (order, 'timestamp'); let side = this.safeString (order, 'type'); if (side === 'ask') { @@ -460,9 +458,8 @@ module.exports = class coinone extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const remaining = this.safeFloat (order, 'remainQty'); - let filled = undefined; - const amount = this.safeFloat (order, 'qty'); + const remaining = this.safeNumber (order, 'remainQty'); + const amount = this.safeNumber (order, 'qty'); let status = this.safeString (order, 'status'); // https://github.com/ccxt/ccxt/pull/7067 if (status === 'live') { @@ -472,14 +469,7 @@ module.exports = class coinone extends Exchange { } } } - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (amount - remaining); - } status = this.parseOrderStatus (status); - let cost = undefined; - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } let symbol = undefined; let base = undefined; let quote = undefined; @@ -499,16 +489,16 @@ module.exports = class coinone extends Exchange { quote = market['quote']; } let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = (side === 'sell') ? quote : base; fee = { 'cost': feeCost, - 'rate': this.safeFloat (order, 'feeRate'), + 'rate': this.safeNumber (order, 'feeRate'), 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -522,15 +512,15 @@ module.exports = class coinone extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': amount, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -605,8 +595,8 @@ module.exports = class coinone extends Exchange { // eslint-disable-next-line quotes throw new ArgumentsRequired (this.id + " cancelOrder() requires a symbol argument. To cancel the order, pass a symbol argument and {'price': 12345, 'qty': 1.2345, 'is_ask': 0} in the params argument of cancelOrder."); } - const price = this.safeFloat (params, 'price'); - const qty = this.safeFloat (params, 'qty'); + const price = this.safeNumber (params, 'price'); + const qty = this.safeNumber (params, 'qty'); const isAsk = this.safeInteger (params, 'is_ask'); if ((price === undefined) || (qty === undefined) || (isAsk === undefined)) { // eslint-disable-next-line quotes diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinspot.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinspot.js index e04c42b5d..63c9b3fd2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinspot.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/coinspot.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -123,7 +124,7 @@ module.exports = class coinspot extends Exchange { const balance = currencies[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } } @@ -133,11 +134,11 @@ module.exports = class coinspot extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -157,16 +158,16 @@ module.exports = class coinspot extends Exchange { id = id.toLowerCase (); const ticker = response['prices'][id]; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -214,11 +215,13 @@ module.exports = class coinspot extends Exchange { // "market":"BTC/AUD" // } // - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'total'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger (trade, 'solddate'); const marketId = this.safeString (trade, 'market'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/crex24.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/crex24.js index 7c1298090..5c3a3ccde 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/crex24.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/crex24.js @@ -4,6 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, InvalidNonce, RequestTimeout, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, AuthenticationError, BadSymbol } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110,6 +112,7 @@ module.exports = class crex24 extends Exchange { ], }, }, + 'precisionMode': TICK_SIZE, 'fees': { 'trading': { 'tierBased': true, @@ -130,6 +133,7 @@ module.exports = class crex24 extends Exchange { 'BIT': 'BitMoney', 'BULL': 'BuySell', 'CREDIT': 'TerraCredit', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'GHOST': 'GHOSTPRISM', 'IQ': 'IQ.Cash', 'PUT': 'PutinCoin', @@ -163,6 +167,7 @@ module.exports = class crex24 extends Exchange { 'API Key': AuthenticationError, // "API Key '9edc48de-d5b0-4248-8e7e-f59ffcd1c7f1' doesn't exist." 'Insufficient funds': InsufficientFunds, // "Insufficient funds: new order requires 10 ETH which is more than the available balance." 'has been delisted.': BadSymbol, // {"errorDescription":"Instrument '$PAC-BTC' has been delisted."} + 'is currently suspended.': BadSymbol, // {"errorDescription":"Trading in BITG-BTC is currently suspended."} 'Mandatory parameter': BadRequest, // {"errorDescription":"Mandatory parameter 'feeCurrency' is missing."} }, }, @@ -204,12 +209,12 @@ module.exports = class crex24 extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const tickSize = this.safeValue (market, 'tickSize'); - const minPrice = this.safeValue (market, 'minPrice'); - const minAmount = this.safeFloat (market, 'minVolume'); + const tickSize = this.safeNumber (market, 'tickSize'); + const minPrice = this.safeNumber (market, 'minPrice'); + const minAmount = this.safeNumber (market, 'minVolume'); const precision = { - 'amount': this.precisionFromString (this.numberToString (minAmount)), - 'price': this.precisionFromString (this.numberToString (tickSize)), + 'amount': minAmount, + 'price': tickSize, }; const active = (market['state'] === 'active'); result.push ({ @@ -274,7 +279,8 @@ module.exports = class crex24 extends Exchange { const currency = response[i]; const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); - const precision = this.safeInteger (currency, 'withdrawalPrecision'); + const withdrawalPrecision = this.safeInteger (currency, 'withdrawalPrecision'); + const precision = Math.pow (10, -withdrawalPrecision); const address = this.safeValue (currency, 'BaseAddress'); const active = (currency['depositsAllowed'] && currency['withdrawalsAllowed'] && !currency['isDelisted']); const type = currency['isFiat'] ? 'fiat' : 'crypto'; @@ -286,7 +292,7 @@ module.exports = class crex24 extends Exchange { 'type': type, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'flatWithdrawalFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'flatWithdrawalFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -302,12 +308,12 @@ module.exports = class crex24 extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -337,11 +343,11 @@ module.exports = class crex24 extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -393,16 +399,16 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); const marketId = this.safeString (ticker, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -410,10 +416,10 @@ module.exports = class crex24 extends Exchange { 'last': last, 'previousClose': undefined, // previous day close 'change': undefined, - 'percentage': this.safeFloat (ticker, 'percentChange'), + 'percentage': this.safeNumber (ticker, 'percentChange'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -483,14 +489,6 @@ module.exports = class crex24 extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - parseTrade (trade, market = undefined) { // // public fetchTrades @@ -515,14 +513,11 @@ module.exports = class crex24 extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'orderId'); @@ -531,7 +526,7 @@ module.exports = class crex24 extends Exchange { let fee = undefined; const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCode = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -592,11 +587,11 @@ module.exports = class crex24 extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -665,50 +660,19 @@ module.exports = class crex24 extends Exchange { const marketId = this.safeString (order, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remainingVolume'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remainingVolume'); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'lastUpdate')); - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = amount - remaining; - if (this.options['parseOrderToPrecision']) { - filled = parseFloat (this.amountToPrecision (symbol, filled)); - } - filled = Math.max (filled, 0.0); - if (price !== undefined) { - cost = price * filled; - } - } - } const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeString (order, 'side'); const fee = undefined; const trades = undefined; - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const average = undefined; const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -722,14 +686,14 @@ module.exports = class crex24 extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -764,7 +728,7 @@ module.exports = class crex24 extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -1183,8 +1147,8 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'createdAt')); const updated = this.parse8601 (this.safeString (transaction, 'processedAt')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); const fee = { 'cost': feeCost, 'currency': code, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/currencycom.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/currencycom.js index c8570f1d4..17aa6bfa5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/currencycom.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/currencycom.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -92,6 +93,7 @@ module.exports = class currencycom extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.002, @@ -250,7 +252,7 @@ module.exports = class currencycom extends Exchange { const filtersByType = this.indexBy (filters, 'filterType'); const precision = { 'amount': 1 / Math.pow (1, this.safeInteger (market, 'baseAssetPrecision')), - 'price': this.safeFloat (market, 'tickSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'TRADING'); @@ -283,14 +285,14 @@ module.exports = class currencycom extends Exchange { 'max': undefined, }, 'cost': { - 'min': -1 * Math.log10 (precision['amount']), + 'min': -Math.log10 (precision['amount']), 'max': undefined, }, }, }; - const exchangeFee = this.safeFloat2 (market, 'exchangeFee', 'tradingFee'); - const makerFee = this.safeFloat (market, 'makerFee', exchangeFee); - const takerFee = this.safeFloat (market, 'takerFee', exchangeFee); + const exchangeFee = this.safeNumber2 (market, 'exchangeFee', 'tradingFee'); + const makerFee = this.safeNumber (market, 'makerFee', exchangeFee); + const takerFee = this.safeNumber (market, 'takerFee', exchangeFee); if (makerFee !== undefined) { entry['maker'] = makerFee / 100; } @@ -299,65 +301,44 @@ module.exports = class currencycom extends Exchange { } if ('PRICE_FILTER' in filtersByType) { const filter = this.safeValue (filtersByType, 'PRICE_FILTER', {}); - entry['precision']['price'] = this.safeFloat (filter, 'tickSize'); + entry['precision']['price'] = this.safeNumber (filter, 'tickSize'); // PRICE_FILTER reports zero values for maxPrice // since they updated filter types in November 2018 // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } } if ('LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'LOT_SIZE', {}); - entry['precision']['amount'] = this.safeFloat (filter, 'stepSize'); + entry['precision']['amount'] = this.safeNumber (filter, 'stepSize'); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat (filter, 'minNotional'); + entry['limits']['cost']['min'] = this.safeNumber (filter, 'minNotional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { const response = await this.privateGetAccount (params); // @@ -404,8 +385,8 @@ module.exports = class currencycom extends Exchange { const response = await this.privateGetAccount (params); return { 'info': response, - 'maker': this.safeFloat (response, 'makerCommission'), - 'taker': this.safeFloat (response, 'takerCommission'), + 'maker': this.safeNumber (response, 'makerCommission'), + 'taker': this.safeNumber (response, 'takerCommission'), }; } @@ -439,11 +420,11 @@ module.exports = class currencycom extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -542,8 +523,8 @@ module.exports = class currencycom extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); - const open = this.safeFloat (ticker, 'openPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); let average = undefined; if ((open !== undefined) && (last !== undefined)) { average = this.sum (open, last) / 2; @@ -552,22 +533,22 @@ module.exports = class currencycom extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), 'open': open, 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -602,14 +583,6 @@ module.exports = class currencycom extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24hr (params); @@ -642,11 +615,11 @@ module.exports = class currencycom extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -712,8 +685,11 @@ module.exports = class currencycom extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -729,7 +705,7 @@ module.exports = class currencycom extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -751,7 +727,7 @@ module.exports = class currencycom extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': fee, }; } @@ -827,66 +803,21 @@ module.exports = class currencycom extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); + const remaining = undefined; + const cost = this.safeNumber (order, 'cummulativeQuoteQty'); const id = this.safeString (order, 'orderId'); const type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeStringLower (order, 'side'); - let fee = undefined; let trades = undefined; const fills = this.safeValue (order, 'fills'); if (fills !== undefined) { trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'timestamp': timestamp, @@ -900,13 +831,13 @@ module.exports = class currencycom extends Exchange { 'stopPrice': undefined, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/delta.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/delta.js index 9b3c559bf..028cdf3ac 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/delta.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/delta.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, BadRequest, BadSymbol, InvalidOrder, AuthenticationError, ArgumentsRequired, OrderNotFound, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -258,14 +259,14 @@ module.exports = class delta extends Exchange { 'name': this.safeString (currency, 'name'), 'info': currency, // the original payload 'active': active, - 'fee': this.safeFloat (currency, 'base_withdrawal_fee'), + 'fee': this.safeNumber (currency, 'base_withdrawal_fee'), 'precision': 1 / Math.pow (10, precision), 'limits': { 'amount': { 'min': undefined, 'max': undefined }, 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal_amount'), + 'min': this.safeNumber (currency, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -399,26 +400,26 @@ module.exports = class delta extends Exchange { } const precision = { 'amount': 1.0, // number of contracts - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; const limits = { 'amount': { 'min': 1.0, - 'max': this.safeFloat (market, 'position_size_limit'), + 'max': this.safeNumber (market, 'position_size_limit'), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; const state = this.safeString (market, 'state'); const active = (state === 'live'); - const maker = this.safeFloat (market, 'maker_commission_rate'); - const taker = this.safeFloat (market, 'taker_commission_rate'); + const maker = this.safeNumber (market, 'maker_commission_rate'); + const taker = this.safeNumber (market, 'taker_commission_rate'); result.push ({ 'id': id, 'numericId': numericId, @@ -466,8 +467,8 @@ module.exports = class delta extends Exchange { const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.001); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; let percentage = undefined; @@ -478,15 +479,15 @@ module.exports = class delta extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'turnover'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'turnover'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -656,12 +657,11 @@ module.exports = class delta extends Exchange { const orderId = this.safeString (trade, 'order_id'); let timestamp = this.parse8601 (this.safeString (trade, 'created_at')); timestamp = this.safeIntegerProduct (trade, 'timestamp', 0.001, timestamp); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const product = this.safeValue (trade, 'product', {}); const marketId = this.safeString (product, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -680,7 +680,7 @@ module.exports = class delta extends Exchange { if (type !== undefined) { type = type.replace ('_order', ''); } - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { const settlingAsset = this.safeValue (product, 'settling_asset', {}); @@ -747,11 +747,11 @@ module.exports = class delta extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -821,11 +821,11 @@ module.exports = class delta extends Exchange { const currency = this.safeValue (currenciesByNumericId, currencyId); const code = (currency === undefined) ? currencyId : currency['code']; const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchPosition (symbol, params = undefined) { @@ -849,7 +849,7 @@ module.exports = class delta extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPositionsMargined (params); // @@ -930,20 +930,12 @@ module.exports = class delta extends Exchange { const side = this.safeString (order, 'side'); let type = this.safeString (order, 'order_type'); type = type.replace ('_order', ''); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'unfilled_size'); - let filled = undefined; - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let cost = undefined; - const average = this.safeFloat (order, 'average_fill_price'); - if ((average !== undefined) && filled) { - cost = average * filled; - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'unfilled_size'); + const average = this.safeNumber (order, 'average_fill_price'); let fee = undefined; - const feeCost = this.safeFloat (order, 'paid_commission'); + const feeCost = this.safeNumber (order, 'paid_commission'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -956,7 +948,7 @@ module.exports = class delta extends Exchange { 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -968,14 +960,14 @@ module.exports = class delta extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1374,9 +1366,9 @@ module.exports = class delta extends Exchange { const currenciesByNumericId = this.safeValue (this.options, 'currenciesByNumericId'); currency = this.safeValue (currenciesByNumericId, currencyId, currency); const code = (currency === undefined) ? undefined : currency['code']; - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'created_at')); - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const before = Math.max (0, after - amount); const status = 'ok'; return { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/deribit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/deribit.js index f277c3975..1a7c91bec 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/deribit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/deribit.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, ExchangeError, ArgumentsRequired, PermissionDenied, InvalidOrder, OrderNotFound, DDoSProtection, NotSupported, ExchangeNotAvailable, InsufficientFunds, BadRequest, InvalidAddress, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -435,8 +436,8 @@ module.exports = class deribit extends Exchange { const future = (type === 'future'); const option = (type === 'option'); const active = this.safeValue (market, 'is_active'); - const minTradeAmount = this.safeFloat (market, 'min_trade_amount'); - const tickSize = this.safeFloat (market, 'tick_size'); + const minTradeAmount = this.safeNumber (market, 'min_trade_amount'); + const tickSize = this.safeNumber (market, 'tick_size'); const precision = { 'amount': minTradeAmount, 'price': tickSize, @@ -448,8 +449,8 @@ module.exports = class deribit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_commission'), - 'maker': this.safeFloat (market, 'maker_commission'), + 'taker': this.safeNumber (market, 'taker_commission'), + 'maker': this.safeNumber (market, 'maker_commission'), 'limits': { 'amount': { 'min': minTradeAmount, @@ -532,11 +533,11 @@ module.exports = class deribit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const currencyCode = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableFunds'); - account['used'] = this.safeFloat (balance, 'maintenanceMargin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'maintenanceMargin'); + account['total'] = this.safeString (balance, 'equity'); result[currencyCode] = account; - return this.parseBalance (result); + return this.parseBalance (result, false); } async createDepositAddress (code, params = {}) { @@ -654,18 +655,18 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger2 (ticker, 'timestamp', 'creation_timestamp'); const marketId = this.safeString (ticker, 'instrument_name'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat2 (ticker, 'last_price', 'last'); + const last = this.safeNumber2 (ticker, 'last_price', 'last'); const stats = this.safeValue (ticker, 'stats', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (stats, 'high', 'max_price'), - 'low': this.safeFloat2 (stats, 'low', 'min_price'), - 'bid': this.safeFloat2 (ticker, 'best_bid_price', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_amount'), - 'ask': this.safeFloat2 (ticker, 'best_ask_price', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_amount'), + 'high': this.safeNumber2 (stats, 'high', 'max_price'), + 'low': this.safeNumber2 (stats, 'low', 'min_price'), + 'bid': this.safeNumber2 (ticker, 'best_bid_price', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_amount'), + 'ask': this.safeNumber2 (ticker, 'best_ask_price', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_amount'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -675,7 +676,7 @@ module.exports = class deribit extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (stats, 'volume'), + 'quoteVolume': this.safeNumber (stats, 'volume'), 'info': ticker, }; } @@ -862,21 +863,18 @@ module.exports = class deribit extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const liquidity = this.safeString (trade, 'liquidity'); let takerOrMaker = undefined; if (liquidity !== undefined) { // M = maker, T = taker, MT = both takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -1056,31 +1054,21 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger (order, 'creation_timestamp'); const lastUpdate = this.safeInteger (order, 'last_update_timestamp'); const id = this.safeString (order, 'order_id'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); let lastTradeTimestamp = undefined; if (filled !== undefined) { if (filled > 0) { lastTradeTimestamp = lastUpdate; } } - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = price * filled; - } - } const status = this.parseOrderStatus (this.safeString (order, 'order_state')); const marketId = this.safeString (order, 'instrument_name'); market = this.safeMarket (marketId, market); const side = this.safeStringLower (order, 'direction'); - let feeCost = this.safeFloat (order, 'commission'); + let feeCost = this.safeNumber (order, 'commission'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); @@ -1098,7 +1086,7 @@ module.exports = class deribit extends Exchange { const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); const stopPrice = this.safeValue (order, 'stop_price'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1113,14 +1101,14 @@ module.exports = class deribit extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1197,7 +1185,7 @@ module.exports = class deribit extends Exchange { } } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price or stopPrice param for a ' + type + ' order'); } else { @@ -1596,7 +1584,7 @@ module.exports = class deribit extends Exchange { const updated = this.safeInteger (transaction, 'updated_timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let type = 'deposit'; let fee = undefined; if (feeCost !== undefined) { @@ -1619,7 +1607,7 @@ module.exports = class deribit extends Exchange { 'tagTo': undefined, 'tagFrom': undefined, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -1665,7 +1653,7 @@ module.exports = class deribit extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.codeFromOptions ('fetchPositions'); const currency = this.currency (code); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/digifinex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/digifinex.js index 6584b919c..528126688 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/digifinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/digifinex.js @@ -3,7 +3,8 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); -const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -61,11 +62,6 @@ module.exports = class digifinex extends Exchange { 'referral': 'https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp', }, 'api': { - 'v2': { - 'get': [ - 'ticker', - ], - }, 'public': { 'get': [ '{market}/symbols', @@ -191,6 +187,7 @@ module.exports = class digifinex extends Exchange { }, 'commonCurrencies': { 'BHT': 'Black House Test', + 'EPS': 'Epanus', 'MBN': 'Mobilian Coin', 'TEL': 'TEL666', }, @@ -245,7 +242,7 @@ module.exports = class digifinex extends Exchange { const depositStatus = this.safeValue (currency, 'deposit_status', 1); const withdrawStatus = this.safeValue (currency, 'withdraw_status', 1); const active = depositStatus && withdrawStatus; - const fee = this.safeFloat (currency, 'withdraw_fee_rate'); + const fee = this.safeNumber (currency, 'withdraw_fee_rate'); if (code in result) { if (Array.isArray (result[code]['info'])) { result[code]['info'].push (currency); @@ -276,7 +273,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw_amount'), + 'min': this.safeNumber (currency, 'min_withdraw_amount'), 'max': undefined, }, }, @@ -330,7 +327,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), 'max': undefined, }, 'price': { @@ -338,7 +335,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), + 'min': this.safeNumber (market, 'minimum_value'), 'max': undefined, }, }; @@ -352,7 +349,7 @@ module.exports = class digifinex extends Exchange { // const status = this.safeString (market, 'status'); // const active = (status === 'TRADING'); // - const isAllowed = this.safeValue (market, 'is_allow', 1); + const isAllowed = this.safeInteger (market, 'is_allow', 1); const active = isAllowed ? true : false; const type = 'spot'; const spot = (type === 'spot'); @@ -408,7 +405,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), + 'min': this.safeNumber (market, 'min_volume'), 'max': undefined, }, 'price': { @@ -416,7 +413,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, }; @@ -461,12 +458,12 @@ module.exports = class digifinex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -500,87 +497,67 @@ module.exports = class digifinex extends Exchange { } async fetchTickers (symbols = undefined, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTickers() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); - const request = { - 'apiKey': apiKey, - }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (params); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const result = {}; - const tickers = this.safeValue (response, 'ticker', {}); + const tickers = this.safeValue (response, 'ticker', []); const date = this.safeInteger (response, 'date'); - const reversedMarketIds = Object.keys (tickers); - for (let i = 0; i < reversedMarketIds.length; i++) { - const reversedMarketId = reversedMarketIds[i]; - const ticker = this.extend ({ + for (let i = 0; i < tickers.length; i++) { + const rawTicker = this.extend ({ 'date': date, - }, tickers[reversedMarketId]); - const [ quoteId, baseId ] = reversedMarketId.split ('_'); - const marketId = baseId.toUpperCase () + '_' + quoteId.toUpperCase (); - const market = this.safeMarket (marketId, undefined, '_'); - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); + }, tickers[i]); + const ticker = this.parseTicker (rawTicker); + const symbol = ticker['symbol']; + result[symbol] = ticker; } return this.filterByArray (result, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTicker() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); const market = this.market (symbol); - // reversed base/quote in v2 - const marketId = market['quoteId'].toLowerCase () + '_' + market['baseId'].toLowerCase (); const request = { - 'symbol': marketId, - 'apiKey': apiKey, + 'symbol': market['id'], }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (this.extend (request, params)); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const date = this.safeInteger (response, 'date'); - const ticker = this.safeValue (response, 'ticker', {}); - let result = this.safeValue (ticker, marketId, {}); - result = this.extend ({ 'date': date }, result); + const tickers = this.safeValue (response, 'ticker', []); + const firstTicker = this.safeValue (tickers, 0, {}); + const result = this.extend ({ 'date': date }, firstTicker); return this.parseTicker (result, market); } @@ -590,6 +567,7 @@ module.exports = class digifinex extends Exchange { // // { // "last":0.021957, + // "symbol": "btc_usdt", // "base_vol":2249.3521732227, // "change":-0.6, // "vol":102443.5111, @@ -600,22 +578,20 @@ module.exports = class digifinex extends Exchange { // "date"1564518452, // injected from fetchTicker/fetchTickers // } // - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeStringUpper (ticker, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -625,8 +601,8 @@ module.exports = class digifinex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'base_vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'base_vol'), 'info': ticker, }; } @@ -662,18 +638,15 @@ module.exports = class digifinex extends Exchange { const orderId = this.safeString (trade, 'order_id'); const timestamp = this.safeTimestamp2 (trade, 'date', 'timestamp'); const side = this.safeString2 (trade, 'type', 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); const takerOrMaker = this.safeValue (trade, 'is_maker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -775,11 +748,11 @@ module.exports = class digifinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 5), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 1), // volume + this.safeNumber (ohlcv, 5), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 1), // volume ]; } @@ -970,21 +943,11 @@ module.exports = class digifinex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_price'); - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - return { + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1000,13 +963,13 @@ module.exports = class digifinex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'average': average, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1200,7 +1163,7 @@ module.exports = class digifinex extends Exchange { const code = this.safeCurrencyCode (this.safeString (item, 'currency_mark'), currency); const timestamp = this.safeTimestamp (item, 'time'); const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -1263,16 +1226,6 @@ module.exports = class digifinex extends Exchange { return this.parseLedger (items, currency, since, limit); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -1425,8 +1378,8 @@ module.exports = class digifinex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_date')); const updated = this.parse8601 (this.safeString (transaction, 'finished_date')); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -1476,7 +1429,7 @@ module.exports = class digifinex extends Exchange { } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const version = (api === 'v2') ? api : this.version; + const version = this.version; let url = this.urls['api'] + '/' + version + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); const urlencoded = this.urlencode (this.keysort (query)); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/dsx.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/dsx.js deleted file mode 100644 index 349fc2489..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/dsx.js +++ /dev/null @@ -1,1274 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, BadRequest, InsufficientFunds, PermissionDenied, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class dsx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'dsx', - 'name': 'DSX', - 'countries': [ 'UK' ], - 'rateLimit': 1500, - 'version': 'v3', - 'has': { - 'cancelOrder': true, - 'CORS': false, - 'createDepositAddress': true, - 'createMarketOrder': false, - 'createOrder': true, - 'fetchBalance': true, - 'fetchClosedOrders': false, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOHLCV': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchOrderBooks': true, - 'fetchOrders': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTransactions': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg', - 'api': { - 'public': 'https://dsxglobal.com/mapi', // market data - 'private': 'https://dsxglobal.com/tapi', // trading - 'dwapi': 'https://dsxglobal.com/dwapi', // deposit/withdraw - }, - 'www': 'https://dsxglobal.com', - 'doc': [ - 'https://dsxglobal.com/developers/publicApi', - ], - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'maker': 0.15 / 100, - 'taker': 0.25 / 100, - }, - }, - 'timeframes': { - '1m': 'm', - '1h': 'h', - '1d': 'd', - }, - 'api': { - // market data (public) - 'public': { - 'get': [ - 'barsFromMoment/{pair}/{period}/{start}', - 'depth/{pair}', - 'info', - 'lastBars/{pair}/{period}/{amount}', // period is 'm', 'h' or 'd' - 'periodBars/{pair}/{period}/{start}/{end}', - 'ticker/{pair}', - 'trades/{pair}', - ], - }, - // trading (private) - 'private': { - 'post': [ - 'info/account', - 'history/transactions', - 'history/trades', - 'history/orders', - 'orders', - 'order/cancel', - // 'order/cancel/all', - 'order/status', - 'order/new', - 'volume', - 'fees', // trading fee schedule - ], - }, - // deposit / withdraw (private) - 'dwapi': { - 'post': [ - 'deposit/cryptoaddress', - 'withdraw/crypto', - 'withdraw/fiat', - 'withdraw/submit', - // 'withdraw/cancel', - 'transaction/status', // see 'history/transactions' in private tapi above - ], - }, - }, - 'exceptions': { - 'exact': { - 'Sign is invalid': AuthenticationError, // {"success":0,"error":"Sign is invalid"} - 'Order was rejected. Incorrect price.': InvalidOrder, // {"success":0,"error":"Order was rejected. Incorrect price."} - "Order was rejected. You don't have enough money.": InsufficientFunds, // {"success":0,"error":"Order was rejected. You don't have enough money."} - 'This method is blocked for your pair of keys': PermissionDenied, // {"success":0,"error":"This method is blocked for your pair of keys"} - }, - 'broad': { - 'INVALID_PARAMETER': BadRequest, - 'Invalid pair name': ExchangeError, // {"success":0,"error":"Invalid pair name: btc_eth"} - 'invalid api key': AuthenticationError, - 'invalid sign': AuthenticationError, - 'api key dont have trade permission': AuthenticationError, - 'invalid parameter': InvalidOrder, - 'invalid order': InvalidOrder, - 'Requests too often': DDoSProtection, - 'not available': ExchangeNotAvailable, - 'data unavailable': ExchangeNotAvailable, - 'external service unavailable': ExchangeNotAvailable, - 'nonce is invalid': InvalidNonce, // {"success":0,"error":"Parameter: nonce is invalid"} - 'Incorrect volume': InvalidOrder, // {"success": 0,"error":"Order was rejected. Incorrect volume."} - }, - }, - 'options': { - 'fetchTickersMaxLength': 250, - }, - 'commonCurrencies': { - 'DSH': 'DASH', - }, - }); - } - - async fetchMarkets (params = {}) { - const response = await this.publicGetInfo (params); - // - // { - // "server_time": 1522057909, - // "pairs": { - // "ethusd": { - // "decimal_places": 5, - // "min_price": 100, - // "max_price": 1500, - // "min_amount": 0.01, - // "hidden": 0, - // "fee": 0, - // "amount_decimal_places": 4, - // "quoted_currency": "USD", - // "base_currency": "ETH" - // } - // } - // } - // - const markets = this.safeValue (response, 'pairs'); - const keys = Object.keys (markets); - const result = []; - for (let i = 0; i < keys.length; i++) { - const id = keys[i]; - const market = markets[id]; - const baseId = this.safeString (market, 'base_currency'); - const quoteId = this.safeString (market, 'quoted_currency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const precision = { - 'amount': this.safeInteger (market, 'decimal_places'), - 'price': this.safeInteger (market, 'decimal_places'), - }; - const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), - }; - const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), - }; - const costLimits = { - 'min': this.safeFloat (market, 'min_total'), - }; - const limits = { - 'amount': amountLimits, - 'price': priceLimits, - 'cost': costLimits, - }; - const hidden = this.safeInteger (market, 'hidden'); - const active = (hidden === 0); - // see parseMarket below - // https://github.com/ccxt/ccxt/pull/5786 - const otherId = base.toLowerCase () + quote.toLowerCase (); - result.push ({ - 'id': id, - 'otherId': otherId, // https://github.com/ccxt/ccxt/pull/5786 - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': active, - 'precision': precision, - 'limits': limits, - 'info': market, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostInfoAccount (); - // - // { - // "success" : 1, - // "return" : { - // "funds" : { - // "BTC" : { - // "total" : 0, - // "available" : 0 - // }, - // "USD" : { - // "total" : 0, - // "available" : 0 - // }, - // "USDT" : { - // "total" : 0, - // "available" : 0 - // } - // }, - // "rights" : { - // "info" : 1, - // "trade" : 1 - // }, - // "transactionCount" : 0, - // "openOrders" : 0, - // "serverTime" : 1537451465 - // } - // } - // - const balances = this.safeValue (response, 'return'); - const result = { 'info': response }; - const funds = this.safeValue (balances, 'funds'); - const currencyIds = Object.keys (funds); - for (let i = 0; i < currencyIds.length; i++) { - const currencyId = currencyIds[i]; - const code = this.safeCurrencyCode (currencyId); - const balance = this.safeValue (funds, currencyId, {}); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseTicker (ticker, market = undefined) { - // - // { high: 0.03492, - // low: 0.03245, - // avg: 29.46133, - // vol: 500.8661, - // vol_cur: 17.000797104, - // last: 0.03364, - // buy: 0.03362, - // sell: 0.03381, - // updated: 1537521993, - // pair: "ethbtc" } - // - const timestamp = this.safeTimestamp (ticker, 'updated'); - let symbol = undefined; - const marketId = this.safeString (ticker, 'pair'); - market = this.parseMarket (marketId); - if (market !== undefined) { - symbol = market['symbol']; - } - // dsx average is inverted, liqui average is not - let average = this.safeFloat (ticker, 'avg'); - if (average !== undefined) { - if (average > 0) { - average = 1 / average; - } - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_cur'), - 'info': ticker, - }; - } - - parseTrade (trade, market = undefined) { - // - // fetchTrades (public) - // - // { - // "amount" : 0.0128, - // "price" : 6483.99000, - // "timestamp" : 1540334614, - // "tid" : 35684364, - // "type" : "ask" - // } - // - // fetchMyTrades (private) - // - // { - // "number": "36635882", // <-- this is present if the trade has come from the '/order/status' call - // "id": "36635882", // <-- this may have been artifically added by the parseTrades method - // "pair": "btcusd", - // "type": "buy", - // "volume": 0.0595, - // "rate": 9750, - // "orderId": 77149299, - // "timestamp": 1519612317, - // "commission": 0.00020825, - // "commissionCurrency": "btc" - // } - // - const timestamp = this.safeTimestamp (trade, 'timestamp'); - let side = this.safeString (trade, 'type'); - if (side === 'ask') { - side = 'sell'; - } else if (side === 'bid') { - side = 'buy'; - } - const price = this.safeFloat2 (trade, 'rate', 'price'); - const id = this.safeString2 (trade, 'number', 'id'); - const orderId = this.safeString (trade, 'orderId'); - const marketId = this.safeString (trade, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const amount = this.safeFloat2 (trade, 'amount', 'volume'); - const type = 'limit'; // all trades are still limit trades - let takerOrMaker = undefined; - let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const isYourOrder = this.safeValue (trade, 'is_your_order'); - if (isYourOrder !== undefined) { - takerOrMaker = 'taker'; - if (isYourOrder) { - takerOrMaker = 'maker'; - } - if (fee === undefined) { - fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); - } - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - return { - 'id': id, - 'order': orderId, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': type, - 'side': side, - 'takerOrMaker': takerOrMaker, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - 'info': trade, - }; - } - - parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - let result = []; - if (Array.isArray (trades)) { - for (let i = 0; i < trades.length; i++) { - result.push (this.parseTrade (trades[i], market)); - } - } else { - const ids = Object.keys (trades); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const trade = this.parseTrade (trades[id], market); - result.push (this.extend (trade, { 'id': id }, params)); - } - } - result = this.sortBy (result, 'timestamp'); - const symbol = (market !== undefined) ? market['symbol'] : undefined; - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const market_id_in_reponse = (market['id'] in response); - if (!market_id_in_reponse) { - throw new ExchangeError (this.id + ' ' + market['symbol'] + ' order book is empty or not available'); - } - const orderbook = response[market['id']]; - return this.parseOrderBook (orderbook); - } - - async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let ids = undefined; - if (symbols === undefined) { - ids = this.ids.join ('-'); - // max URL length is 2083 symbols, including http schema, hostname, tld, etc... - if (ids.length > 2048) { - const numIds = this.ids.length; - throw new ExchangeError (this.id + ' has ' + numIds.toString () + ' symbols exceeding max URL length, you are required to specify a list of symbols in the first argument to fetchOrderBooks'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const result = {}; - ids = Object.keys (response); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let symbol = id; - if (id in this.markets_by_id) { - const market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseOrderBook (response[id]); - } - return result; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - let ids = this.ids; - if (symbols === undefined) { - const numIds = ids.length; - ids = ids.join ('-'); - const maxLength = this.safeInteger (this.options, 'fetchTickersMaxLength', 2048); - // max URL length is 2048 symbols, including http schema, hostname, tld, etc... - if (ids.length > this.options['fetchTickersMaxLength']) { - throw new ArgumentsRequired (this.id + ' has ' + numIds.toString () + ' markets exceeding max URL length for this endpoint (' + maxLength.toString () + ' characters), please, specify a list of symbols of interest in the first argument to fetchTickers'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - const tickers = await this.publicGetTickerPair (this.extend (request, params)); - // - // { - // "bchbtc" : { - // "high" : 0.02989, - // "low" : 0.02736, - // "avg" : 33.90585, - // "vol" : 0.65982205, - // "vol_cur" : 0.0194604180960, - // "last" : 0.03000, - // "buy" : 0.02980, - // "sell" : 0.03001, - // "updated" : 1568104614, - // "pair" : "bchbtc" - // }, - // "ethbtc" : { - // "high" : 0.01772, - // "low" : 0.01742, - // "avg" : 56.89082, - // "vol" : 229.247115044, - // "vol_cur" : 4.02959737298943, - // "last" : 0.01769, - // "buy" : 0.01768, - // "sell" : 0.01776, - // "updated" : 1568104614, - // "pair" : "ethbtc" - // } - // } - // - const result = {}; - const keys = Object.keys (tickers); - for (let k = 0; k < keys.length; k++) { - const id = keys[k]; - const ticker = tickers[id]; - let symbol = id; - let market = undefined; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseTicker (ticker, market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - const tickers = await this.fetchTickers ([ symbol ], params); - return tickers[symbol]; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; - } - const response = await this.publicGetTradesPair (this.extend (request, params)); - if (Array.isArray (response)) { - const numElements = response.length; - if (numElements === 0) { - return []; - } - } - return this.parseTrades (response[market['id']], market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // } - // - return [ - this.safeInteger (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - 'period': this.timeframes[timeframe], - }; - let method = 'publicGetLastBarsPairPeriodAmount'; - if (since === undefined) { - if (limit === undefined) { - limit = 100; // required, max 2000 - } - request['amount'] = limit; - } else { - method = 'publicGetPeriodBarsPairPeriodStartEnd'; - // in their docs they expect milliseconds - // but it returns empty arrays with milliseconds - // however, it does work properly with seconds - request['start'] = parseInt (since / 1000); - if (limit === undefined) { - request['end'] = this.seconds (); - } else { - const duration = this.parseTimeframe (timeframe) * 1000; - const end = this.sum (since, duration * limit); - request['end'] = parseInt (end / 1000); - } - } - const response = await this[method] (this.extend (request, params)); - // - // { - // "ethbtc": [ - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // }, - // { - // "high" : 0.01967, - // "open" : 0.01967, - // "low" : 0.01967, - // "close" : 0.01967, - // "amount" : 0, - // "timestamp" : 1565155680000 - // } - // ] - // } - // - const candles = this.safeValue (response, market['id'], []); - return this.parseOHLCVs (candles, market, timeframe, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (type === 'market' && price === undefined) { - throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument even for market orders, that is the worst price that you agree to fill your order for'); - } - const request = { - 'pair': market['id'], - 'type': side, - 'volume': this.amountToPrecision (symbol, amount), - 'rate': this.priceToPrecision (symbol, price), - 'orderType': type, - }; - price = parseFloat (price); - amount = parseFloat (amount); - const response = await this.privatePostOrderNew (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "received": 0, - // "remains": 10, - // "funds": { - // "BTC": { - // "total": 100, - // "available": 95 - // }, - // "USD": { - // "total": 10000, - // "available": 9995 - // }, - // "EUR": { - // "total": 1000, - // "available": 995 - // }, - // "LTC": { - // "total": 1000, - // "available": 995 - // } - // }, - // "orderId": 0, // https://github.com/ccxt/ccxt/issues/3677 - // } - // } - // - let status = 'open'; - let filled = 0.0; - let remaining = amount; - const responseReturn = this.safeValue (response, 'return'); - let id = this.safeString2 (responseReturn, 'orderId', 'order_id'); - if (id === '0') { - id = this.safeString (responseReturn, 'initOrderId', 'init_order_id'); - status = 'closed'; - } - filled = this.safeFloat (responseReturn, 'received', 0.0); - remaining = this.safeFloat (responseReturn, 'remains', amount); - const timestamp = this.milliseconds (); - return { - 'info': response, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'side': side, - 'price': price, - 'cost': price * filled, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'fee': undefined, - // 'trades': this.parseTrades (order['trades'], market), - }; - } - - parseOrderStatus (status) { - const statuses = { - '0': 'open', // Active - '1': 'closed', // Filled - '2': 'canceled', // Killed - '3': 'canceling', // Killing - '7': 'canceled', // Rejected - }; - return this.safeString (statuses, status, status); - } - - parseMarket (id) { - if (id in this.markets_by_id) { - return this.markets_by_id[id]; - } else { - // the following is a fix for - // https://github.com/ccxt/ccxt/pull/5786 - // https://github.com/ccxt/ccxt/issues/5770 - let markets_by_other_id = this.safeValue (this.options, 'markets_by_other_id'); - if (markets_by_other_id === undefined) { - this.options['markets_by_other_id'] = this.indexBy (this.markets, 'otherId'); - markets_by_other_id = this.options['markets_by_other_id']; - } - if (id in markets_by_other_id) { - return markets_by_other_id[id]; - } - } - return undefined; - } - - parseOrder (order, market = undefined) { - // - // fetchOrder - // - // { - // "number": 36635882, - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // - const id = this.safeString (order, 'id'); - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const timestamp = this.safeTimestamp (order, 'timestampCreated'); - const marketId = this.safeString (order, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const remaining = this.safeFloat (order, 'remainingVolume'); - const amount = this.safeFloat (order, 'volume'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } - } - const orderType = this.safeString (order, 'orderType'); - const side = this.safeString (order, 'type'); - let fee = undefined; - const deals = this.safeValue (order, 'deals', []); - const numDeals = deals.length; - let trades = undefined; - let lastTradeTimestamp = undefined; - if (numDeals > 0) { - trades = this.parseTrades (deals); - let feeCost = undefined; - let feeCurrency = undefined; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - if (feeCost === undefined) { - feeCost = 0; - } - feeCost = this.sum (feeCost, trade['fee']['cost']); - feeCurrency = trade['fee']['currency']; - lastTradeTimestamp = trade['timestamp']; - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'type': orderType, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': undefined, - 'cost': cost, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'status': status, - 'fee': fee, - 'trades': trades, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': parseInt (id), - }; - const response = await this.privatePostOrderStatus (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // } - // - return this.parseOrder (this.extend ({ - 'id': id, - }, response['return'])); - } - - parseOrdersById (orders, symbol = undefined, since = undefined, limit = undefined) { - const ids = Object.keys (orders); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.parseOrder (this.extend ({ - 'id': id.toString (), - }, orders[id])); - result.push (order); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - const response = await this.privatePostOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': id, - }; - const response = await this.privatePostOrderCancel (this.extend (request, params)); - return response; - } - - parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { - const result = []; - const ids = Object.keys (orders); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.extend ({ 'id': id }, orders[id]); - result.push (this.extend (this.parseOrder (order, market), params)); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - const orders = await this.fetchOrders (symbol, since, limit, params); - return this.filterBy (orders, 'status', 'closed'); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let market = undefined; - // some derived classes use camelcase notation for request fields - const request = { - // 'from': 123456789, // trade ID, from which the display starts numerical 0 (test result: liqui ignores this field) - // 'count': 1000, // the number of trades for display numerical, default = 1000 - // 'from_id': trade ID, from which the display starts numerical 0 - // 'end_id': trade ID on which the display ends numerical ∞ - // 'order': 'ASC', // sorting, default = DESC (test result: liqui ignores this field, most recent trade always goes last) - // 'since': 1234567890, // UTC start time, default = 0 (test result: liqui ignores this field) - // 'end': 1234567890, // UTC end time, default = ∞ (test result: liqui ignores this field) - // 'pair': 'eth_btc', // default = all markets - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['pair'] = market['id']; - } - if (limit !== undefined) { - request['count'] = parseInt (limit); - } - if (since !== undefined) { - request['since'] = parseInt (since / 1000); - } - const response = await this.privatePostHistoryTrades (this.extend (request, params)); - let trades = []; - if ('return' in response) { - trades = response['return']; - } - return this.parseTrades (trades, market, since, limit); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let currency = undefined; - const request = {}; - if (code !== undefined) { - currency = this.currency (code); - request['currency'] = currency['id']; - } - if (since !== undefined) { - request['since'] = since; - } - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryTransactions (this.extend (request, params)); - // - // { - // "success": 1, - // "return": [ - // { - // "id": 1, - // "timestamp": 11, - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // ] - // } - // - const transactions = this.safeValue (response, 'return', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - '1': 'failed', - '2': 'ok', - '3': 'pending', - '4': 'failed', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // "id": 1, - // "timestamp": 11, // 11 in their docs ( - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // - const timestamp = this.safeTimestamp (transaction, 'timestamp'); - let type = this.safeString (transaction, 'type'); - if (type !== undefined) { - if (type === 'Incoming') { - type = 'deposit'; - } else if (type === 'Withdraw') { - type = 'withdrawal'; - } - } - const currencyId = this.safeString (transaction, 'currency'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - return { - 'id': this.safeString (transaction, 'id'), - 'txid': this.safeString (transaction, 'txid'), - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'address': this.safeString (transaction, 'address'), - 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), - 'currency': code, - 'status': status, - 'fee': { - 'currency': code, - 'cost': this.safeFloat (transaction, 'commission'), - 'rate': undefined, - }, - 'info': transaction, - }; - } - - async createDepositAddress (code, params = {}) { - const request = { - 'new': 1, - }; - const response = await this.fetchDepositAddress (code, this.extend (request, params)); - return response; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency': currency['id'], - }; - const response = await this.dwapiPostDepositCryptoaddress (this.extend (request, params)); - const result = this.safeValue (response, 'return', {}); - const address = this.safeString (result, 'address'); - this.checkAddress (address); - return { - 'currency': code, - 'address': address, - 'tag': undefined, // not documented in DSX API - 'info': response, - }; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - const commission = this.safeValue (params, 'commission'); - if (commission === undefined) { - throw new ArgumentsRequired (this.id + ' withdraw() requires a `commission` (withdrawal fee) parameter (string)'); - } - params = this.omit (params, commission); - const request = { - 'currency': currency['id'], - 'amount': parseFloat (amount), - 'address': address, - 'commission': commission, - }; - if (tag !== undefined) { - request['address'] += ':' + tag; - } - const response = await this.dwapiPostWithdrawCrypto (this.extend (request, params)); - // - // [ - // { - // "success": 1, - // "return": { - // "transactionId": 2863073 - // } - // } - // ] - // - const data = this.safeValue (response, 'return', {}); - const id = this.safeString (data, 'transactionId'); - return { - 'info': response, - 'id': id, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'][api]; - const query = this.omit (params, this.extractParams (path)); - if (api === 'private' || api === 'dwapi') { - url += '/' + this.version + '/' + this.implodeParams (path, params); - this.checkRequiredCredentials (); - const nonce = this.nonce (); - body = this.urlencode (this.extend ({ - 'nonce': nonce, - }, query)); - const signature = this.hmac (this.encode (body), this.encode (this.secret), 'sha512', 'base64'); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': signature, - }; - } else if (api === 'public') { - url += '/' + this.implodeParams (path, params); - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - url += '/' + this.implodeParams (path, params); - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - if (Object.keys (query).length) { - body = this.json (query); - headers = { - 'Content-Type': 'application/json', - }; - } - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - if ('success' in response) { - // - // 1 - Liqui only returns the integer 'success' key from their private API - // - // { "success": 1, ... } httpCode === 200 - // { "success": 0, ... } httpCode === 200 - // - // 2 - However, exchanges derived from Liqui, can return non-integers - // - // It can be a numeric string - // { "sucesss": "1", ... } - // { "sucesss": "0", ... }, httpCode >= 200 (can be 403, 502, etc) - // - // Or just a string - // { "success": "true", ... } - // { "success": "false", ... }, httpCode >= 200 - // - // Or a boolean - // { "success": true, ... } - // { "success": false, ... }, httpCode >= 200 - // - // 3 - Oversimplified, Python PEP8 forbids comparison operator (===) of different types - // - // 4 - We do not want to copy-paste and duplicate the code of this handler to other exchanges derived from Liqui - // - // To cover points 1, 2, 3 and 4 combined this handler should work like this: - // - let success = this.safeValue (response, 'success', false); - if (typeof success === 'string') { - if ((success === 'true') || (success === '1')) { - success = true; - } else { - success = false; - } - } - if (!success) { - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'error'); - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/equos.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/equos.js index 5dc44a2ac..0b90d79ed 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/equos.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/equos.js @@ -221,7 +221,7 @@ module.exports = class equos extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeVol'), + 'min': this.safeNumber (market, 'minTradeVol'), 'max': undefined, }, 'price': { @@ -287,7 +287,7 @@ module.exports = class equos extends Exchange { const name = this.safeString (currency, 6); const status = this.safeInteger (currency, 4); const active = (status === 1); - const fee = this.safeFloat (currency, 5); // withdraw_fee + const fee = this.safeNumber (currency, 5); // withdraw_fee return { 'id': id, 'info': currency, @@ -379,8 +379,8 @@ module.exports = class equos extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); return [ this.convertFromScale (price, market['precision']['price']), this.convertFromScale (amount, market['precision']['amount']), @@ -526,9 +526,9 @@ module.exports = class equos extends Exchange { orderId = this.safeString (trade, 'orderId'); side = this.safeStringLower (trade, 'side'); type = this.parseOrderType (this.safeString (trade, 'ordType')); - price = this.safeFloat (trade, 'lastPx'); - amount = this.safeFloat (trade, 'quoteQty'); - let feeCost = this.safeFloat (trade, 'commission'); + price = this.safeNumber (trade, 'lastPx'); + amount = this.safeNumber (trade, 'quoteQty'); + let feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { feeCost = -feeCost; const feeCurrencyId = this.safeString (trade, 'commCurrency'); @@ -599,8 +599,8 @@ module.exports = class equos extends Exchange { if (assetType === 'ASSET') { const currencyId = this.safeString (position, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const quantity = this.safeFloat (position, 'quantity'); - const availableQuantity = this.safeFloat (position, 'availableQuantity'); + const quantity = this.safeNumber (position, 'quantity'); + const availableQuantity = this.safeNumber (position, 'availableQuantity'); const scale = this.safeInteger (position, 'quantity_scale'); const account = this.account (); account['free'] = this.convertFromScale (availableQuantity, scale); @@ -646,7 +646,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -743,7 +743,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -1116,7 +1116,7 @@ module.exports = class equos extends Exchange { address = undefined; } const type = this.safeString (transaction, 'type'); - let amount = this.safeFloat (transaction, 'balance_change'); + let amount = this.safeNumber (transaction, 'balance_change'); if (amount === undefined) { amount = this.safeInteger (transaction, 'quantity'); const amountScale = this.safeInteger (transaction, 'quantity_scale'); @@ -1199,8 +1199,8 @@ module.exports = class equos extends Exchange { for (let i = 0; i < tradingFees.length; i++) { const tradingFee = tradingFees[i]; if (this.safeString (tradingFee, 'tier') !== undefined) { - taker[tradingFee['tier']] = this.safeFloat (tradingFee, 'taker'); - maker[tradingFee['tier']] = this.safeFloat (tradingFee, 'maker'); + taker[tradingFee['tier']] = this.safeNumber (tradingFee, 'taker'); + maker[tradingFee['tier']] = this.safeNumber (tradingFee, 'maker'); } } return { @@ -1331,28 +1331,6 @@ module.exports = class equos extends Exchange { let remaining = this.safeInteger (order, 'leavesQty'); const remainingScale = this.safeInteger (order, 'leavesQty_scale'); remaining = this.convertFromScale (remaining, remainingScale); - if (remaining <= 0) { - if ((filled !== undefined) && (amount !== undefined) && (filled < amount)) { - remaining = undefined; - } - } - if ((remaining === undefined) && (amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0); - } - let average = this.safeInteger (order, 'price', 0); - if (average === 0) { - average = undefined; - } - const averageScale = this.safeInteger (order, 'price_scale'); - average = this.convertFromScale (average, averageScale); - let cost = undefined; - if (filled !== 0) { - if (average > 0) { - cost = average * filled; - } else if (price > 0) { - cost = price * filled; - } - } let fee = undefined; const currencyId = this.safeInteger (order, 'feeInstrumentId'); const feeCurrencyCode = this.safeCurrencyCode (currencyId); @@ -1375,7 +1353,7 @@ module.exports = class equos extends Exchange { } const stopPriceScale = this.safeInteger (order, 'stopPx_scale', 0); const stopPrice = this.convertFromScale (this.safeInteger (order, 'stopPx'), stopPriceScale); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1390,14 +1368,14 @@ module.exports = class equos extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/eterbase.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/eterbase.js index 40d2893d3..531327d1d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/eterbase.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/eterbase.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, InvalidOrder, ExchangeError, BadRequest, BadSymbol } = require ('./base/errors'); const { TRUNCATE, SIGNIFICANT_DIGITS } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -217,7 +218,7 @@ module.exports = class eterbase extends Exchange { const rule = rules[i]; const attribute = this.safeString (rule, 'attribute'); const condition = this.safeString (rule, 'condition'); - const value = this.safeFloat (rule, 'value'); + const value = this.safeNumber (rule, 'value'); if ((attribute === 'Qty') && (condition === 'Min')) { minAmount = value; } else if ((attribute === 'Qty') && (condition === 'Max')) { @@ -307,7 +308,7 @@ module.exports = class eterbase extends Exchange { 'type': type, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -323,8 +324,8 @@ module.exports = class eterbase extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMin'), - 'max': this.safeFloat (currency, 'withdrawalMax'), + 'min': this.safeNumber (currency, 'withdrawalMin'), + 'max': this.safeNumber (currency, 'withdrawalMax'), }, }, }; @@ -351,17 +352,17 @@ module.exports = class eterbase extends Exchange { const marketId = this.safeString (ticker, 'marketId'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const last = this.safeFloat (ticker, 'price'); - const baseVolume = this.safeFloat (ticker, 'volumeBase'); - const quoteVolume = this.safeFloat (ticker, 'volume'); + const last = this.safeNumber (ticker, 'price'); + const baseVolume = this.safeNumber (ticker, 'volumeBase'); + const quoteVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const percentage = this.safeFloat (ticker, 'change'); + const percentage = this.safeNumber (ticker, 'change'); const result = { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -403,14 +404,6 @@ module.exports = class eterbase extends Exchange { return this.parseTicker (response, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { @@ -465,10 +458,12 @@ module.exports = class eterbase extends Exchange { // "filledAt": 1556355722341 // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -477,9 +472,9 @@ module.exports = class eterbase extends Exchange { 'currency': feeCurrencyCode, }; } - let cost = this.safeFloat (trade, 'qty'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + let cost = this.safeNumber (trade, 'qty'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger2 (trade, 'executedAt', 'filledAt'); const tradeSide = this.safeString (trade, 'side'); @@ -577,11 +572,11 @@ module.exports = class eterbase extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -644,14 +639,13 @@ module.exports = class eterbase extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetId'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'reserved'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -778,18 +772,18 @@ module.exports = class eterbase extends Exchange { } else { type = 'stoplimit'; } - let price = this.safeFloat (order, 'limitPrice'); - const amount = this.safeFloat (order, 'qty'); - let remaining = this.safeFloat (order, 'remainingQty'); + let price = this.safeNumber (order, 'limitPrice'); + const amount = this.safeNumber (order, 'qty'); + let remaining = this.safeNumber (order, 'remainingQty'); let filled = undefined; - const remainingCost = this.safeFloat (order, 'remainingCost'); + const remainingCost = this.safeNumber (order, 'remainingCost'); if ((remainingCost !== undefined) && (remainingCost === 0.0)) { remaining = 0; } if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); } - const cost = this.safeFloat (order, 'cost'); + const cost = this.safeNumber (order, 'cost'); if (type === 'market') { if (price === 0.0) { if ((cost !== undefined) && (filled !== undefined)) { @@ -806,7 +800,7 @@ module.exports = class eterbase extends Exchange { } } const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -979,7 +973,7 @@ module.exports = class eterbase extends Exchange { } if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) { // for market buy it requires the amount of quote currency to spend - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); if (this.options['createMarketBuyOrderRequiresPrice']) { if (cost === undefined) { if (price !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exmo.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exmo.js index c9e19479d..d79e42079 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exmo.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exmo.js @@ -112,6 +112,7 @@ module.exports = class exmo extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.2 / 100, @@ -581,18 +582,18 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = marketId.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const maxAmount = this.safeFloat (limit, 'max_q'); - const maxPrice = this.safeFloat (limit, 'max_p'); - const maxCost = this.safeFloat (limit, 'max_a'); - const minAmount = this.safeFloat (limit, 'min_q'); - const minPrice = this.safeFloat (limit, 'min_p'); - const minCost = this.safeFloat (limit, 'min_a'); - minAmounts[base] = Math.min (this.safeFloat (minAmounts, base, minAmount), minAmount); - maxAmounts[base] = Math.max (this.safeFloat (maxAmounts, base, maxAmount), maxAmount); - minPrices[quote] = Math.min (this.safeFloat (minPrices, quote, minPrice), minPrice); - minCosts[quote] = Math.min (this.safeFloat (minCosts, quote, minCost), minCost); - maxPrices[quote] = Math.max (this.safeFloat (maxPrices, quote, maxPrice), maxPrice); - maxCosts[quote] = Math.max (this.safeFloat (maxCosts, quote, maxCost), maxCost); + const maxAmount = this.safeNumber (limit, 'max_q'); + const maxPrice = this.safeNumber (limit, 'max_p'); + const maxCost = this.safeNumber (limit, 'max_a'); + const minAmount = this.safeNumber (limit, 'min_q'); + const minPrice = this.safeNumber (limit, 'min_p'); + const minCost = this.safeNumber (limit, 'min_a'); + minAmounts[base] = Math.min (this.safeNumber (minAmounts, base, minAmount), minAmount); + maxAmounts[base] = Math.max (this.safeNumber (maxAmounts, base, maxAmount), maxAmount); + minPrices[quote] = Math.min (this.safeNumber (minPrices, quote, minPrice), minPrice); + minCosts[quote] = Math.min (this.safeNumber (minCosts, quote, minCost), minCost); + maxPrices[quote] = Math.max (this.safeNumber (maxPrices, quote, maxPrice), maxPrice); + maxCosts[quote] = Math.max (this.safeNumber (maxCosts, quote, maxCost), maxCost); } const result = {}; for (let i = 0; i < ids.length; i++) { @@ -609,16 +610,16 @@ module.exports = class exmo extends Exchange { 'precision': 8, 'limits': { 'amount': { - 'min': this.safeFloat (minAmounts, code), - 'max': this.safeFloat (maxAmounts, code), + 'min': this.safeNumber (minAmounts, code), + 'max': this.safeNumber (maxAmounts, code), }, 'price': { - 'min': this.safeFloat (minPrices, code), - 'max': this.safeFloat (maxPrices, code), + 'min': this.safeNumber (minPrices, code), + 'max': this.safeNumber (maxPrices, code), }, 'cost': { - 'min': this.safeFloat (minCosts, code), - 'max': this.safeFloat (maxCosts, code), + 'min': this.safeNumber (minCosts, code), + 'max': this.safeNumber (maxCosts, code), }, }, 'info': id, @@ -653,8 +654,8 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = symbol.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const taker = this.safeFloat (market, 'commission_taker_percent'); - const maker = this.safeFloat (market, 'commission_maker_percent'); + const taker = this.safeNumber (market, 'commission_taker_percent'); + const maker = this.safeNumber (market, 'commission_maker_percent'); result.push ({ 'id': id, 'symbol': symbol, @@ -667,16 +668,16 @@ module.exports = class exmo extends Exchange { 'maker': maker / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, }, 'precision': { @@ -749,11 +750,11 @@ module.exports = class exmo extends Exchange { // return [ this.safeInteger (ohlcv, 't'), - this.safeFloat (ohlcv, 'o'), - this.safeFloat (ohlcv, 'h'), - this.safeFloat (ohlcv, 'l'), - this.safeFloat (ohlcv, 'c'), - this.safeFloat (ohlcv, 'v'), + this.safeNumber (ohlcv, 'o'), + this.safeNumber (ohlcv, 'h'), + this.safeNumber (ohlcv, 'l'), + this.safeNumber (ohlcv, 'c'), + this.safeNumber (ohlcv, 'v'), ]; } @@ -769,14 +770,14 @@ module.exports = class exmo extends Exchange { const currencyId = this.currencyId (code); const account = this.account (); if (currencyId in free) { - account['free'] = this.safeFloat (free, currencyId); + account['free'] = this.safeString (free, currencyId); } if (currencyId in used) { - account['used'] = this.safeFloat (used, currencyId); + account['used'] = this.safeString (used, currencyId); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -834,16 +835,16 @@ module.exports = class exmo extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -852,9 +853,9 @@ module.exports = class exmo extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_curr'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'vol_curr'), 'info': ticker, }; } @@ -915,9 +916,9 @@ module.exports = class exmo extends Exchange { let symbol = undefined; const id = this.safeString (trade, 'trade_id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'quantity'); + const cost = this.safeNumber (trade, 'amount'); const side = this.safeString (trade, 'type'); const type = undefined; const marketId = this.safeString (trade, 'pair'); @@ -936,11 +937,11 @@ module.exports = class exmo extends Exchange { } const takerOrMaker = this.safeString (trade, 'exec_type'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission_amount'); + const feeCost = this.safeNumber (trade, 'commission_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commission_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (trade, 'commission_percent'); + let feeRate = this.safeNumber (trade, 'commission_percent'); if (feeRate !== undefined) { feeRate /= 1000; } @@ -1239,13 +1240,13 @@ module.exports = class exmo extends Exchange { market = this.markets_by_id[marketId]; } } - let amount = this.safeFloat (order, 'quantity'); + let amount = this.safeNumber (order, 'quantity'); if (amount === undefined) { const amountField = (side === 'buy') ? 'in_amount' : 'out_amount'; - amount = this.safeFloat (order, amountField); + amount = this.safeNumber (order, amountField); } - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'amount'); + let price = this.safeNumber (order, 'price'); + let cost = this.safeNumber (order, 'amount'); let filled = 0.0; const trades = []; const transactions = this.safeValue (order, 'trades', []); @@ -1366,24 +1367,6 @@ module.exports = class exmo extends Exchange { return undefined; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -1428,7 +1411,7 @@ module.exports = class exmo extends Exchange { // } // const timestamp = this.safeTimestamp (transaction, 'dt'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -1458,7 +1441,7 @@ module.exports = class exmo extends Exchange { // fixed funding fees only (for now) if (!this.fees['funding']['percentage']) { const key = (type === 'withdrawal') ? 'withdraw' : 'deposit'; - let feeCost = this.safeFloat (this.options['fundingFees'][key], code); + let feeCost = this.safeNumber (this.options['fundingFees'][key], code); // users don't pay for cashbacks, no fees for that const provider = this.safeString (transaction, 'provider'); if (provider === 'cashback') { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exx.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exx.js index c4c12d03f..72b59ef1b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exx.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/exx.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ExchangeNotAvailable, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -148,26 +149,26 @@ module.exports = class exx extends Exchange { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); ticker = ticker['ticker']; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'riseRate'), + 'change': this.safeNumber (ticker, 'riseRate'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -217,14 +218,11 @@ module.exports = class exx extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -269,14 +267,13 @@ module.exports = class exx extends Exchange { const currencyId = currencies[i]; const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'balance'), - 'used': this.safeFloat (balance, 'freeze'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -296,11 +293,10 @@ module.exports = class exx extends Exchange { // const symbol = market['symbol']; const timestamp = parseInt (order['trade_date']); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'trade_money'); - const amount = this.safeFloat (order, 'total_amount'); - const filled = this.safeFloat (order, 'trade_amount', 0.0); - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'trade_money'); + const amount = this.safeNumber (order, 'total_amount'); + const filled = this.safeNumber (order, 'trade_amount', 0.0); let status = this.safeInteger (order, 'status'); if (status === 1) { status = 'canceled'; @@ -312,11 +308,11 @@ module.exports = class exx extends Exchange { let fee = undefined; if ('fees' in order) { fee = { - 'cost': this.safeFloat (order, 'fees'), + 'cost': this.safeNumber (order, 'fees'), 'currency': market['quote'], }; } - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -333,12 +329,12 @@ module.exports = class exx extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/fcoin.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/fcoin.js index 2d1c845ab..2d90e7cce 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/fcoin.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/fcoin.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, ArgumentsRequired, InsufficientFunds, InvalidOrder, RateLimitExceeded, InvalidNonce, AuthenticationError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -223,8 +224,8 @@ module.exports = class fcoin extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'limit_amount_min'), - 'max': this.safeFloat (market, 'limit_amount_max'), + 'min': this.safeNumber (market, 'limit_amount_min'), + 'max': this.safeNumber (market, 'limit_amount_max'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -319,12 +320,12 @@ module.exports = class fcoin extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidsAsks (orders, priceKey = 0, amountKey = 1) { @@ -337,8 +338,8 @@ module.exports = class fcoin extends Exchange { const priceField = this.sum (index, priceKey); const amountField = this.sum (index, amountKey); result.push ([ - this.safeFloat (orders, priceField), - this.safeFloat (orders, amountField), + this.safeNumber (orders, priceField), + this.safeNumber (orders, amountField), ]); } return result; @@ -386,17 +387,17 @@ module.exports = class fcoin extends Exchange { } } const values = ticker['ticker']; - const last = this.safeFloat (values, 0); + const last = this.safeNumber (values, 0); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (values, 7), - 'low': this.safeFloat (values, 8), - 'bid': this.safeFloat (values, 2), - 'bidVolume': this.safeFloat (values, 3), - 'ask': this.safeFloat (values, 4), - 'askVolume': this.safeFloat (values, 5), + 'high': this.safeNumber (values, 7), + 'low': this.safeNumber (values, 8), + 'bid': this.safeNumber (values, 2), + 'bidVolume': this.safeNumber (values, 3), + 'ask': this.safeNumber (values, 4), + 'askVolume': this.safeNumber (values, 5), 'vwap': undefined, 'open': undefined, 'close': last, @@ -405,8 +406,8 @@ module.exports = class fcoin extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (values, 9), - 'quoteVolume': this.safeFloat (values, 10), + 'baseVolume': this.safeNumber (values, 9), + 'quoteVolume': this.safeNumber (values, 10), 'info': ticker, }; } @@ -419,14 +420,11 @@ module.exports = class fcoin extends Exchange { const timestamp = this.safeInteger (trade, 'ts'); const side = this.safeStringLower (trade, 'side'); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = undefined; return { 'id': id, @@ -551,38 +549,25 @@ module.exports = class fcoin extends Exchange { const symbol = market['symbol']; const orderType = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'created_at'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'executed_value'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'executed_value'); let feeCurrency = undefined; let feeCost = undefined; - const feeRebate = this.safeFloat (order, 'fees_income'); + const feeRebate = this.safeNumber (order, 'fees_income'); if ((feeRebate !== undefined) && (feeRebate > 0)) { if (market !== undefined) { feeCurrency = (side === 'buy') ? market['quote'] : market['base']; } feeCost = -feeRebate; } else { - feeCost = this.safeFloat (order, 'fill_fees'); + feeCost = this.safeNumber (order, 'fill_fees'); if (market !== undefined) { feeCurrency = (side === 'buy') ? market['base'] : market['quote']; } } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -598,7 +583,7 @@ module.exports = class fcoin extends Exchange { 'stopPrice': undefined, 'cost': cost, 'amount': amount, - 'remaining': remaining, + 'remaining': undefined, 'filled': filled, 'average': undefined, 'status': status, @@ -607,7 +592,7 @@ module.exports = class fcoin extends Exchange { 'currency': feeCurrency, }, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -649,11 +634,11 @@ module.exports = class fcoin extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_vol'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/flowbtc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/flowbtc.js index 12646489b..45d80935d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/flowbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/flowbtc.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -131,11 +132,11 @@ module.exports = class flowbtc extends Exchange { const currencyId = balance['name']; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['total'] = this.safeFloat (balance, 'hold'); + account['free'] = this.safeString (balance, 'balance'); + account['total'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -156,16 +157,16 @@ module.exports = class flowbtc extends Exchange { }; const ticker = await this.publicPostGetTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -175,8 +176,8 @@ module.exports = class flowbtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume24hr'), - 'quoteVolume': this.safeFloat (ticker, 'volume24hrProduct2'), + 'baseVolume': this.safeNumber (ticker, 'volume24hr'), + 'quoteVolume': this.safeNumber (ticker, 'volume24hrProduct2'), 'info': ticker, }; } @@ -185,14 +186,11 @@ module.exports = class flowbtc extends Exchange { const timestamp = this.safeTimestamp (trade, 'unixtime'); const side = (trade['incomingOrderSide'] === 0) ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'px'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'px'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'timestamp': timestamp, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/foxbit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/foxbit.js index 5830969a3..b1fb3032b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/foxbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/foxbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89,11 +90,11 @@ module.exports = class foxbit extends Exchange { // otherwise we will lose the info if the currency balance has been funded or traded or not if (currencyId in balances) { const account = this.account (); - let used = this.safeFloat (balances, currencyId + '_locked'); + let used = this.safeNumber (balances, currencyId + '_locked'); if (used !== undefined) { used *= 1e-8; } - let total = this.safeFloat (balances, currencyId); + let total = this.safeNumber (balances, currencyId); if (total !== undefined) { total *= 1e-8; } @@ -128,16 +129,16 @@ module.exports = class foxbit extends Exchange { const timestamp = this.milliseconds (); const lowercaseQuote = market['quote'].toLowerCase (); const quoteVolume = 'vol_' + lowercaseQuote; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -147,8 +148,8 @@ module.exports = class foxbit extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -161,14 +162,11 @@ module.exports = class foxbit extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ftx.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ftx.js index 18b572cc6..a0e42e8e4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ftx.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ftx.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending } = require ('./base/errors'); +const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending, ArgumentsRequired, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -243,6 +244,7 @@ module.exports = class ftx extends Exchange { 'An unexpected error occurred': ExchangeNotAvailable, // {"error":"An unexpected error occurred, please try again later (58BC21C795).","success":false} 'Please retry request': ExchangeNotAvailable, // {"error":"Please retry request","success":false} 'Please try again': ExchangeNotAvailable, // {"error":"Please try again","success":false} + 'Only have permissions for subaccount': PermissionDenied, // {"success":false,"error":"Only have permissions for subaccount *sub_name*"} }, }, 'precisionMode': TICK_SIZE, @@ -366,8 +368,8 @@ module.exports = class ftx extends Exchange { // check if a market is a spot or future market const symbol = (type === 'future') ? this.safeString (market, 'name') : (base + '/' + quote); const active = this.safeValue (market, 'enabled'); - const sizeIncrement = this.safeFloat (market, 'sizeIncrement'); - const priceIncrement = this.safeFloat (market, 'priceIncrement'); + const sizeIncrement = this.safeNumber (market, 'sizeIncrement'); + const priceIncrement = this.safeNumber (market, 'priceIncrement'); const precision = { 'amount': sizeIncrement, 'price': priceIncrement, @@ -445,28 +447,28 @@ module.exports = class ftx extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); const timestamp = this.safeTimestamp (ticker, 'time', this.milliseconds ()); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'change24h'), + 'percentage': this.safeNumber (ticker, 'change24h'), 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24h'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24h'), 'info': ticker, }; } @@ -506,14 +508,6 @@ module.exports = class ftx extends Exchange { return this.parseTicker (result, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetMarkets (params); @@ -592,11 +586,11 @@ module.exports = class ftx extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -717,6 +711,45 @@ module.exports = class ftx extends Exchange { // "type": "otc" // } // + // with -ve fee + // { + // "id": 1171258927, + // "fee": -0.0000713875, + // "side": "sell", + // "size": 1, + // "time": "2021-03-11T13:34:35.523627+00:00", + // "type": "order", + // "price": 14.2775, + // "future": null, + // "market": "SOL/USD", + // "feeRate": -0.000005, + // "orderId": 33182929044, + // "tradeId": 582936801, + // "liquidity": "maker", + // "feeCurrency": "USD", + // "baseCurrency": "SOL", + // "quoteCurrency": "USD" + // } + // + // // from OTC order + // { + // "id": 1172129651, + // "fee": 0, + // "side": "sell", + // "size": 1.47568846, + // "time": "2021-03-11T15:04:46.893383+00:00", + // "type": "otc", + // "price": 14.60932598, + // "future": null, + // "market": null, + // "feeRate": 0, + // "orderId": null, + // "tradeId": null, + // "liquidity": "taker", + // "feeCurrency": "USD", + // "baseCurrency": "BCHA", + // "quoteCurrency": "USD" + // } const id = this.safeString (trade, 'id'); const takerOrMaker = this.safeString (trade, 'liquidity'); const marketId = this.safeString (trade, 'market'); @@ -734,25 +767,24 @@ module.exports = class ftx extends Exchange { } } const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } const orderId = this.safeString (trade, 'orderId'); @@ -858,8 +890,8 @@ module.exports = class ftx extends Exchange { const result = this.safeValue (response, 'result', {}); return { 'info': response, - 'maker': this.safeFloat (result, 'makerFee'), - 'taker': this.safeFloat (result, 'takerFee'), + 'maker': this.safeNumber (result, 'makerFee'), + 'taker': this.safeNumber (result, 'takerFee'), }; } @@ -886,11 +918,11 @@ module.exports = class ftx extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'coin')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -1013,9 +1045,9 @@ module.exports = class ftx extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); let status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filledSize'); - let remaining = this.safeFloat (order, 'remainingSize'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filledSize'); + let remaining = this.safeNumber (order, 'remainingSize'); if ((remaining === 0.0) && (amount !== undefined) && (filled !== undefined)) { remaining = Math.max (amount - filled, 0); if (remaining > 0) { @@ -1039,15 +1071,15 @@ module.exports = class ftx extends Exchange { } const side = this.safeString (order, 'side'); const type = this.safeString (order, 'type'); - const average = this.safeFloat (order, 'avgFillPrice'); - const price = this.safeFloat2 (order, 'price', 'triggerPrice', average); + const average = this.safeNumber (order, 'avgFillPrice'); + const price = this.safeNumber2 (order, 'price', 'triggerPrice', average); let cost = undefined; if (filled !== undefined && price !== undefined) { cost = filled * price; } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'triggeredAt')); const clientOrderId = this.safeString (order, 'clientId'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -1093,22 +1125,28 @@ module.exports = class ftx extends Exchange { request['clientId'] = clientOrderId; params = this.omit (params, [ 'clientId', 'clientOrderId' ]); } - let priceToPrecision = undefined; - if (price !== undefined) { - priceToPrecision = parseFloat (this.priceToPrecision (symbol, price)); - } - let method = 'privatePostConditionalOrders'; + let method = undefined; if (type === 'limit') { method = 'privatePostOrders'; - request['price'] = priceToPrecision; + request['price'] = parseFloat (this.priceToPrecision (symbol, price)); } else if (type === 'market') { method = 'privatePostOrders'; request['price'] = null; } else if ((type === 'stop') || (type === 'takeProfit')) { - request['triggerPrice'] = priceToPrecision; - // request['orderPrice'] = number; // optional, order type is limit if this is specified, otherwise market + method = 'privatePostConditionalOrders'; + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerPrice'); + if (stopPrice === undefined) { + throw new ArgumentsRequired (this.id + ' createOrder () requires a stopPrice parameter or a triggerPrice parameter for ' + type + ' orders'); + } else { + params = this.omit (params, [ 'stopPrice', 'triggerPrice' ]); + request['triggerPrice'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + } + if (price !== undefined) { + request['orderPrice'] = parseFloat (this.priceToPrecision (symbol, price)); // optional, order type is limit if this is specified, otherwise market + } } else if (type === 'trailingStop') { - request['trailValue'] = priceToPrecision; // negative for "sell", positive for "buy" + method = 'privatePostConditionalOrders'; + request['trailValue'] = parseFloat (this.priceToPrecision (symbol, price)); // negative for "sell", positive for "buy" } else { throw new InvalidOrder (this.id + ' createOrder () does not support order type ' + type + ', only limit, market, stop, trailingStop, or takeProfit orders are supported'); } @@ -1174,9 +1212,9 @@ module.exports = class ftx extends Exchange { const request = {}; let method = undefined; const clientOrderId = this.safeString2 (params, 'client_order_id', 'clientOrderId'); - const triggerPrice = this.safeFloat (params, 'triggerPrice'); - const orderPrice = this.safeFloat (params, 'orderPrice'); - const trailValue = this.safeFloat (params, 'trailValue'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); + const orderPrice = this.safeNumber (params, 'orderPrice'); + const trailValue = this.safeNumber (params, 'trailValue'); params = this.omit (params, [ 'client_order_id', 'clientOrderId', 'triggerPrice', 'orderPrice', 'trailValue' ]); const triggerPriceIsDefined = (triggerPrice !== undefined); const orderPriceIsDefined = (orderPrice !== undefined); @@ -1539,7 +1577,7 @@ module.exports = class ftx extends Exchange { return this.parseTransaction (result, currency); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetAccount (params); // @@ -1672,7 +1710,7 @@ module.exports = class ftx extends Exchange { // const code = this.safeCurrencyCode (this.safeString (transaction, 'coin')); const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'size'); + const amount = this.safeNumber (transaction, 'size'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const txid = this.safeString (transaction, 'txid'); @@ -1689,7 +1727,7 @@ module.exports = class ftx extends Exchange { address = notes.slice (12); } } - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gateio.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gateio.js index f0835c774..eac7234c9 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gateio.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gateio.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, ArgumentsRequired, InvalidAddress, OrderNotFound, NotSupported, DDoSProtection, InsufficientFunds, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,9 +165,12 @@ module.exports = class gateio extends Exchange { }, }, 'commonCurrencies': { + '88MPH': 'MPH', + 'BIFI': 'Bitcoin File', 'BOX': 'DefiBox', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', + 'MPH': 'Morpher', // conflict with 88MPH 'SBTC': 'Super Bitcoin', 'TNC': 'Trinity Network Credit', }, @@ -213,9 +217,9 @@ module.exports = class gateio extends Exchange { const currency = coin[id]; const code = this.safeCurrencyCode (id); const delisted = this.safeValue (currency, 'delisted', 0); - const withdrawDisabled = this.safeValue (currency, 'withdraw_disabled', 0); - const depositDisabled = this.safeValue (currency, 'deposit_disabled', 0); - const tradeDisabled = this.safeValue (currency, 'trade_disabled', 0); + const withdrawDisabled = this.safeInteger2 (currency, 'withdraw_disabled', 0); + const depositDisabled = this.safeInteger2 (currency, 'deposit_disabled', 0); + const tradeDisabled = this.safeInteger2 (currency, 'trade_disabled', 0); const listed = (delisted === 0); const withdrawEnabled = (withdrawDisabled === 0); const depositEnabled = (depositDisabled === 0); @@ -304,7 +308,7 @@ module.exports = class gateio extends Exchange { 'price': this.safeInteger (details, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (details, 'min_amount'), + 'min': this.safeNumber (details, 'min_amount'), 'max': undefined, }; const priceLimits = { @@ -312,7 +316,7 @@ module.exports = class gateio extends Exchange { 'max': undefined, }; const defaultCost = amountLimits['min'] * priceLimits['min']; - const minCost = this.safeFloat (this.options['limits']['cost']['min'], quote, defaultCost); + const minCost = this.safeNumber (this.options['limits']['cost']['min'], quote, defaultCost); const costLimits = { 'min': minCost, 'max': undefined, @@ -322,10 +326,10 @@ module.exports = class gateio extends Exchange { 'price': priceLimits, 'cost': costLimits, }; - const disabled = this.safeValue (details, 'trade_disabled'); + const disabled = this.safeInteger (details, 'trade_disabled'); const active = !disabled; const uppercaseId = id.toUpperCase (); - const fee = this.safeFloat (details, 'fee'); + const fee = this.safeNumber (details, 'fee'); result.push ({ 'id': id, 'uppercaseId': uppercaseId, @@ -359,11 +363,11 @@ module.exports = class gateio extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (available, currencyId); - account['used'] = this.safeFloat (locked, currencyId); + account['free'] = this.safeString (available, currencyId); + account['used'] = this.safeString (locked, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -379,11 +383,11 @@ module.exports = class gateio extends Exchange { // they return [ Timestamp, Volume, Close, High, Low, Open ] return [ this.safeInteger (ohlcv, 0), // t - this.safeFloat (ohlcv, 5), // o - this.safeFloat (ohlcv, 3), // h - this.safeFloat (ohlcv, 4), // l - this.safeFloat (ohlcv, 2), // c - this.safeFloat (ohlcv, 1), // v + this.safeNumber (ohlcv, 5), // o + this.safeNumber (ohlcv, 3), // h + this.safeNumber (ohlcv, 4), // l + this.safeNumber (ohlcv, 2), // c + this.safeNumber (ohlcv, 1), // v ]; } @@ -395,11 +399,11 @@ module.exports = class gateio extends Exchange { 'group_sec': this.timeframes[timeframe], }; // max limit = 1001 - if (limit !== undefined) { - const periodDurationInSeconds = this.parseTimeframe (timeframe); - const hours = parseInt ((periodDurationInSeconds * limit) / 3600); - request['range_hour'] = Math.max (0, hours - 1); - } + // if (limit !== undefined) { + // const periodDurationInSeconds = this.parseTimeframe (timeframe); + // const hours = parseInt ((periodDurationInSeconds * limit) / 3600); + // request['range_hour'] = Math.max (1, hours - 1); + // } const response = await this.publicGetCandlestick2Id (this.extend (request, params)); // // { @@ -423,8 +427,8 @@ module.exports = class gateio extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'percentChange'); let open = undefined; let change = undefined; let average = undefined; @@ -434,17 +438,17 @@ module.exports = class gateio extends Exchange { change = last - open; average = this.sum (last, open) / 2; } - open = this.safeFloat (ticker, 'open', open); - change = this.safeFloat (ticker, 'change', change); + open = this.safeNumber (ticker, 'open', open); + change = this.safeNumber (ticker, 'change', change); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high24hr', 'high'), - 'low': this.safeFloat2 (ticker, 'low24hr', 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber2 (ticker, 'high24hr', 'high'), + 'low': this.safeNumber2 (ticker, 'low24hr', 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -454,8 +458,8 @@ module.exports = class gateio extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), // gateio has them reversed - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), // gateio has them reversed + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -501,27 +505,24 @@ module.exports = class gateio extends Exchange { const id = this.safeString2 (trade, 'tradeID', 'id'); // take either of orderid or orderId const orderId = this.safeString2 (trade, 'orderid', 'orderNumber'); - const price = this.safeFloat2 (trade, 'rate', 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString2 (trade, 'rate', 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'role'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } let fee = undefined; let feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee_coin')); - let feeCost = this.safeFloat (trade, 'point_fee'); + let feeCost = this.safeNumber (trade, 'point_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'gt_fee'); + feeCost = this.safeNumber (trade, 'gt_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'fee'); + feeCost = this.safeNumber (trade, 'fee'); } else { feeCurrency = this.safeCurrencyCode ('GT'); } @@ -665,23 +666,20 @@ module.exports = class gateio extends Exchange { } else if (side === '2') { side = 'buy'; } - const price = this.safeFloat2 (order, 'initialRate', 'rate'); - const average = this.safeFloat (order, 'filledRate'); - const amount = this.safeFloat2 (order, 'initialAmount', 'amount'); - const filled = this.safeFloat (order, 'filledAmount'); + const price = this.safeNumber2 (order, 'initialRate', 'rate'); + const average = this.safeNumber (order, 'filledRate'); + const amount = this.safeNumber2 (order, 'initialAmount', 'amount'); + const filled = this.safeNumber (order, 'filledAmount'); // In the order status response, this field has a different name. - let remaining = this.safeFloat2 (order, 'leftAmount', 'left'); - if (remaining === undefined) { - remaining = amount - filled; - } - const feeCost = this.safeFloat (order, 'feeValue'); + const remaining = this.safeNumber2 (order, 'leftAmount', 'left'); + const feeCost = this.safeNumber (order, 'feeValue'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (order, 'feePercentage'); + let feeRate = this.safeNumber (order, 'feePercentage'); if (feeRate !== undefined) { feeRate = feeRate / 100; } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -707,7 +705,7 @@ module.exports = class gateio extends Exchange { 'rate': feeRate, }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -898,7 +896,7 @@ module.exports = class gateio extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'txid'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); if (address === 'false') { address = undefined; @@ -906,7 +904,7 @@ module.exports = class gateio extends Exchange { const timestamp = this.safeTimestamp (transaction, 'timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.parseTransactionType (id[0]); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gemini.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gemini.js index 6f28ef220..36892fa47 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gemini.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gemini.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidOrder, InvalidNonce, InsufficientFunds, AuthenticationError, PermissionDenied, NotSupported, OnMaintenance, RateLimitExceeded, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -221,16 +222,16 @@ module.exports = class gemini extends Exchange { // const base = this.safeCurrencyCode (baseId); const minAmountString = cells[1].replace ('', ''); const minAmountParts = minAmountString.split (' '); - const minAmount = this.safeFloat (minAmountParts, 0); + const minAmount = this.safeNumber (minAmountParts, 0); const amountPrecisionString = cells[2].replace ('', ''); const amountPrecisionParts = amountPrecisionString.split (' '); - const amountPrecision = this.safeFloat (amountPrecisionParts, 0); + const amountPrecision = this.safeNumber (amountPrecisionParts, 0); const idLength = marketId.length - 0; const quoteId = marketId.slice (idLength - 3, idLength); const quote = this.safeCurrencyCode (quoteId); const pricePrecisionString = cells[3].replace ('', ''); const pricePrecisionParts = pricePrecisionString.split (' '); - const pricePrecision = this.safeFloat (pricePrecisionParts, 0); + const pricePrecision = this.safeNumber (pricePrecisionParts, 0); const baseId = marketId.replace (quoteId, ''); const base = this.safeCurrencyCode (baseId); const symbol = base + '/' + quote; @@ -458,11 +459,11 @@ module.exports = class gemini extends Exchange { base = market['base']; quote = market['quote']; } - const price = this.safeFloat (ticker, 'price'); - const last = this.safeFloat2 (ticker, 'last', 'close', price); - let percentage = this.safeFloat (ticker, 'percentChange24h'); + const price = this.safeNumber (ticker, 'price'); + const last = this.safeNumber2 (ticker, 'last', 'close', price); + let percentage = this.safeNumber (ticker, 'percentChange24h'); let change = undefined; - let open = this.safeFloat (ticker, 'open'); + let open = this.safeNumber (ticker, 'open'); let average = undefined; if (last !== undefined) { if (open !== undefined) { @@ -479,18 +480,18 @@ module.exports = class gemini extends Exchange { average = this.sum (last, open) / 2; } } - const baseVolume = this.safeFloat (volume, baseId); - const quoteVolume = this.safeFloat (volume, quoteId); + const baseVolume = this.safeNumber (volume, baseId); + const quoteVolume = this.safeNumber (volume, quoteId); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -506,14 +507,6 @@ module.exports = class gemini extends Exchange { }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetV1Pricefeed (params); @@ -554,17 +547,14 @@ module.exports = class gemini extends Exchange { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); const fee = { - 'cost': this.safeFloat (trade, 'fee_amount'), + 'cost': this.safeNumber (trade, 'fee_amount'), 'currency': feeCurrencyCode, }; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeStringLower (trade, 'type'); const symbol = this.safeSymbol (undefined, market); @@ -617,18 +607,18 @@ module.exports = class gemini extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'timestampms'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const filled = this.safeFloat (order, 'executed_amount'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const filled = this.safeNumber (order, 'executed_amount'); let status = 'closed'; if (order['is_live']) { status = 'open'; @@ -636,14 +626,8 @@ module.exports = class gemini extends Exchange { if (order['is_cancelled']) { status = 'canceled'; } - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_execution_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_execution_price'); let type = this.safeString (order, 'type'); if (type === 'exchange limit') { type = 'limit'; @@ -658,7 +642,7 @@ module.exports = class gemini extends Exchange { const id = this.safeString (order, 'order_id'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'client_order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -674,13 +658,13 @@ module.exports = class gemini extends Exchange { 'price': price, 'stopPrice': undefined, 'average': average, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -795,7 +779,7 @@ module.exports = class gemini extends Exchange { status = 'ok'; } let fee = undefined; - const feeAmount = this.safeFloat (transaction, 'feeAmount'); + const feeAmount = this.safeNumber (transaction, 'feeAmount'); if (feeAmount !== undefined) { fee = { 'cost': feeAmount, @@ -811,7 +795,7 @@ module.exports = class gemini extends Exchange { 'address': address, 'tag': undefined, // or is it defined? 'type': type, // direction of the transaction, ('deposit' | 'withdraw') - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gopax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gopax.js index e3150163a..b27308f19 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gopax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/gopax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound, InvalidAddress, BadRequest } = require ('./base/errors'); const { TRUNCATE, ROUND, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -218,8 +219,8 @@ module.exports = class gopax extends Exchange { const minimums = this.safeValue (market, 'restApiOrderAmountMin', {}); const marketAsk = this.safeValue (minimums, 'marketAsk', {}); const marketBid = this.safeValue (minimums, 'marketBid', {}); - const takerFeePercent = this.safeFloat (market, 'takerFeePercent'); - const makerFeePercent = this.safeFloat (market, 'makerFeePercent'); + const takerFeePercent = this.safeNumber (market, 'takerFeePercent'); + const makerFeePercent = this.safeNumber (market, 'makerFeePercent'); const taker = parseFloat (this.decimalToPrecision (takerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); const maker = parseFloat (this.decimalToPrecision (makerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); result.push ({ @@ -237,15 +238,15 @@ module.exports = class gopax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (marketAsk, 'amount'), + 'min': this.safeNumber (marketAsk, 'amount'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'priceMin'), + 'min': this.safeNumber (market, 'priceMin'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (marketBid, 'amount'), + 'min': this.safeNumber (marketBid, 'amount'), 'max': undefined, }, }, @@ -280,8 +281,8 @@ module.exports = class gopax extends Exchange { const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'name'); - const fee = this.safeFloat (currency, 'withdrawalFee'); - const precision = this.safeFloat (currency, 'scale'); + const fee = this.safeNumber (currency, 'withdrawalFee'); + const precision = this.safeNumber (currency, 'scale'); result[code] = { 'id': id, 'info': currency, @@ -304,7 +305,7 @@ module.exports = class gopax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalAmountMin'), + 'min': this.safeNumber (currency, 'withdrawalAmountMin'), 'max': undefined, }, }, @@ -372,8 +373,8 @@ module.exports = class gopax extends Exchange { const marketId = this.safeString (ticker, 'name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (ticker, 'time')); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat2 (ticker, 'price', 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'price', 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -384,20 +385,20 @@ module.exports = class gopax extends Exchange { percentage = change / open * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidVolume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askVolume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidVolume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askVolume'), 'vwap': vwap, 'open': open, 'close': last, @@ -433,14 +434,6 @@ module.exports = class gopax extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTradingPairsStats (params); @@ -462,8 +455,8 @@ module.exports = class gopax extends Exchange { parsePublicTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let symbol = undefined; if ('symbol' in market) { symbol = this.safeString (market, 'symbol'); @@ -489,14 +482,14 @@ module.exports = class gopax extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const symbol = this.safeString (trade, 'tradingPairName').replace ('-', '/'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'baseAmount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'baseAmount'); let feeCurrency = symbol.slice (0, 3); if (side === 'sell') { feeCurrency = symbol.slice (4); } const fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': feeCurrency, 'rate': undefined, }; @@ -578,15 +571,15 @@ module.exports = class gopax extends Exchange { } else if (type === '2') { type = 'market'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'baseAmount'); - let cost = this.safeFloat (trade, 'quoteAmount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'baseAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteAmount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -653,11 +646,11 @@ module.exports = class gopax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -697,14 +690,14 @@ module.exports = class gopax extends Exchange { const balance = response[i]; const currencyId = this.safeString2 (balance, 'asset', 'isoAlpha3'); const code = this.safeCurrencyCode (currencyId); - const hold = this.safeFloat (balance, 'hold'); - const pendingWithdrawal = this.safeFloat (balance, 'pendingWithdrawal'); + const hold = this.safeString (balance, 'hold'); + const pendingWithdrawal = this.safeString (balance, 'pendingWithdrawal'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.sum (hold, pendingWithdrawal); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = Precise.stringAdd (hold, pendingWithdrawal); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -781,42 +774,36 @@ module.exports = class gopax extends Exchange { const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); const timeInForce = this.safeStringUpper (order, 'timeInForce'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - const remaining = this.safeFloat (order, 'remaining'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const stopPrice = this.safeNumber (order, 'stopPrice'); + const remaining = this.safeNumber (order, 'remaining'); const marketId = this.safeString (order, 'tradingPairName'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const balanceChange = this.safeValue (order, 'balanceChange', {}); - let filled = this.safeFloat (balanceChange, 'baseNet'); - let cost = this.safeFloat (balanceChange, 'quoteNet'); + const filled = this.safeNumber (balanceChange, 'baseNet'); + let cost = this.safeNumber (balanceChange, 'quoteNet'); if (cost !== undefined) { cost = Math.abs (cost); } let updated = undefined; - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } if ((filled !== undefined) && (filled > 0)) { updated = this.parse8601 (this.safeString (order, 'updatedAt')); } - if ((cost === undefined) && (price !== undefined) && (filled !== undefined)) { - cost = filled * price; - } let fee = undefined; if (side === 'buy') { const baseFee = this.safeValue (balanceChange, 'baseFee', {}); - const taking = this.safeFloat (baseFee, 'taking'); - const making = this.safeFloat (baseFee, 'making'); + const taking = this.safeNumber (baseFee, 'taking'); + const making = this.safeNumber (baseFee, 'making'); fee = { 'currency': market['base'], 'cost': this.sum (taking, making), }; } else { const quoteFee = this.safeValue (balanceChange, 'quoteFee', {}); - const taking = this.safeFloat (quoteFee, 'taking'); - const making = this.safeFloat (quoteFee, 'making'); + const taking = this.safeNumber (quoteFee, 'taking'); + const making = this.safeNumber (quoteFee, 'making'); fee = { 'currency': market['quote'], 'cost': this.sum (taking, making), @@ -826,7 +813,7 @@ module.exports = class gopax extends Exchange { if (timeInForce !== undefined) { postOnly = (timeInForce === 'PO'); } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'datetime': this.iso8601 (timestamp), @@ -848,7 +835,7 @@ module.exports = class gopax extends Exchange { 'trades': undefined, 'fee': fee, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -996,7 +983,7 @@ module.exports = class gopax extends Exchange { request['clientOrderId'] = clientOrderId; params = this.omit (params, 'clientOrderId'); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1125,18 +1112,6 @@ module.exports = class gopax extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetCryptoDepositAddresses (params); @@ -1201,8 +1176,8 @@ module.exports = class gopax extends Exchange { } else if ((type === 'crypto_deposit' || type === 'fiat_deposit')) { type = 'deposit'; } - const amount = this.safeFloat (transaction, 'netAmount'); - const feeCost = this.safeFloat (transaction, 'feeAmount'); + const amount = this.safeNumber (transaction, 'netAmount'); + const feeCost = this.safeNumber (transaction, 'feeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hbtc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hbtc.js index d819c3d77..5dfd98ec5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hbtc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, OrderNotFound, ArgumentsRequired, BadSymbol, BadRequest, NullResponse, InvalidOrder, BadResponse, NotSupported, ExchangeNotAvailable, RequestTimeout, RateLimitExceeded, PermissionDenied, InsufficientFunds, InvalidAddress } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -304,23 +305,23 @@ module.exports = class hbtc extends Exchange { const filter = filters[j]; const filterType = this.safeString (filter, 'filterType'); if (filterType === 'LOT_SIZE') { - amountMin = this.safeFloat (filter, 'minQty'); - amountMax = this.safeFloat (filter, 'maxQty'); + amountMin = this.safeNumber (filter, 'minQty'); + amountMax = this.safeNumber (filter, 'maxQty'); } if (filterType === 'PRICE_FILTER') { - priceMin = this.safeFloat (filter, 'minPrice'); - priceMax = this.safeFloat (filter, 'maxPrice'); + priceMin = this.safeNumber (filter, 'minPrice'); + priceMax = this.safeNumber (filter, 'maxPrice'); } if (filterType === 'MIN_NOTIONAL') { - costMin = this.safeFloat (filter, 'minNotional'); + costMin = this.safeNumber (filter, 'minNotional'); } } if ((costMin === undefined) && (amountMin !== undefined) && (priceMin !== undefined)) { costMin = amountMin * priceMin; } const precision = { - 'price': this.safeFloat2 (market, 'quotePrecision', 'quoteAssetPrecision'), - 'amount': this.safeFloat (market, 'baseAssetPrecision'), + 'price': this.safeNumber2 (market, 'quotePrecision', 'quoteAssetPrecision'), + 'amount': this.safeNumber (market, 'baseAssetPrecision'), }; const limits = { 'amount': { @@ -558,14 +559,6 @@ module.exports = class hbtc extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidAsk (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -717,8 +710,8 @@ module.exports = class hbtc extends Exchange { const currencyId = this.safeString2 (balance, 'asset', 'tokenName'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -728,12 +721,12 @@ module.exports = class hbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = response[currencyId]; const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableMargin'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'availableMargin'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTrades (symbol, since = undefined, limit = 50, params = {}) { @@ -774,11 +767,11 @@ module.exports = class hbtc extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -1464,8 +1457,8 @@ module.exports = class hbtc extends Exchange { // const currencyId = this.safeString (item, 'tokenId'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'change'); - const after = this.safeFloat (item, 'total'); + const amount = this.safeNumber (item, 'change'); + const after = this.safeNumber (item, 'total'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -1605,8 +1598,8 @@ module.exports = class hbtc extends Exchange { } else { type = 'withdrawal'; } - const amount = this.safeFloat (transaction, 'quantity'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'quantity'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'feeTokenId'); @@ -1667,8 +1660,8 @@ module.exports = class hbtc extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'openPrice'); - const close = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; let average = undefined; @@ -1679,19 +1672,19 @@ module.exports = class hbtc extends Exchange { percentage = (change / open) * 100; } } - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat2 (ticker, 'bestBidPrice', 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat2 (ticker, 'bestAskPrice', 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber2 (ticker, 'bestBidPrice', 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber2 (ticker, 'bestAskPrice', 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': vwap, 'open': open, 'close': close, @@ -1741,17 +1734,14 @@ module.exports = class hbtc extends Exchange { // } // const id = this.safeString (trade, 'id'); - const timestamp = this.safeFloat (trade, 'time'); + const timestamp = this.safeNumber (trade, 'time'); const type = undefined; const orderId = this.safeString (trade, 'orderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let side = undefined; let takerOrMaker = undefined; if ('isBuyerMaker' in trade) { @@ -1765,7 +1755,7 @@ module.exports = class hbtc extends Exchange { side = isBuyer ? 'buy' : 'sell'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1871,30 +1861,30 @@ module.exports = class hbtc extends Exchange { const symbol = this.safeSymbol (marketId, market); let type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'avgPrice'); + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'avgPrice'); let amount = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); + let cost = this.safeNumber (order, 'cummulativeQuoteQty'); let filled = undefined; let remaining = undefined; if (type === undefined) { type = this.safeStringLower (order, 'orderType'); if ((market !== undefined) && market['inverse']) { - cost = this.safeFloat (order, 'executedQty'); + cost = this.safeNumber (order, 'executedQty'); amount = undefined; } if (cost === 0.0) { filled = 0; } } else { - amount = this.safeFloat (order, 'origQty'); + amount = this.safeNumber (order, 'origQty'); if (type === 'market') { price = undefined; if (side === 'buy') { amount = undefined; } } - filled = this.safeFloat (order, 'executedQty'); + filled = this.safeNumber (order, 'executedQty'); if (filled !== undefined) { if (amount !== undefined) { remaining = amount - filled; @@ -1906,7 +1896,7 @@ module.exports = class hbtc extends Exchange { } const status = this.parseOrderStatus (this.safeString (order, 'status')); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const result = { 'info': order, 'id': id, @@ -1935,7 +1925,7 @@ module.exports = class hbtc extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'fee'); + const feeCost = this.safeNumber (fees[i], 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'feeToken'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hitbtc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hitbtc.js index b66392816..b7fd38b04 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hitbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hitbtc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, PermissionDenied, ExchangeError, ExchangeNotAvailable, OrderNotFound, InsufficientFunds, InvalidOrder, RequestTimeout, AuthenticationError } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -44,6 +45,7 @@ module.exports = class hitbtc extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': 'M1', @@ -81,10 +83,10 @@ module.exports = class hitbtc extends Exchange { 'api': { 'public': { 'get': [ - 'symbol', // Available Currency Symbols - 'symbol/{symbol}', // Get symbol info 'currency', // Available Currencies 'currency/{currency}', // Get currency info + 'symbol', // Available Currency Symbols + 'symbol/{symbol}', // Get symbol info 'ticker', // Ticker list for all symbols 'ticker/{symbol}', // Ticker for symbol 'trades', @@ -102,11 +104,20 @@ module.exports = class hitbtc extends Exchange { 'order/{clientOrderId}', // Get a single order by clientOrderId 'trading/fee/all', // Get trading fee rate 'trading/fee/{symbol}', // Get trading fee rate + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', 'history/order', // Get historical orders 'history/trades', // Get historical trades 'history/order/{orderId}/trades', // Get historical trades by specified order 'account/balance', // Get main acccount balance - 'account/crypto/address/{currency}', // Get deposit crypro address + 'account/crypto/address/{currency}', // Get current address + 'account/crypto/addresses/{currency}', // Get last 10 deposit addresses for currency + 'account/crypto/used-addresses/{currency}', // Get last 10 unique addresses used for withdraw by currency + 'account/crypto/estimate-withdraw', 'account/crypto/is-mine/{address}', 'account/transactions', // Get account transactions 'account/transactions/{id}', // Get account transaction by id @@ -117,23 +128,33 @@ module.exports = class hitbtc extends Exchange { ], 'post': [ 'order', // Create new order - 'account/crypto/address/{currency}', // Create new deposit crypro address - 'account/crypto/withdraw', // Withdraw crypro + 'margin/order', + 'account/crypto/address/{currency}', // Create new crypto deposit address + 'account/crypto/withdraw', // Withdraw crypto 'account/crypto/transfer-convert', - 'account/transfer', // Transfer amount to trading + 'account/transfer', // Transfer amount to trading account or to main account + 'account/transfer/internal', 'sub-acc/freeze', 'sub-acc/activate', 'sub-acc/transfer', ], 'put': [ 'order/{clientOrderId}', // Create new order - 'account/crypto/withdraw/{id}', // Commit withdraw crypro + 'margin/account/{symbol}', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Commit crypto withdrawal 'sub-acc/acl/{subAccountUserId}', ], 'delete': [ 'order', // Cancel all open orders 'order/{clientOrderId}', // Cancel order - 'account/crypto/withdraw/{id}', // Rollback withdraw crypro + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Rollback crypto withdrawal ], // outdated? 'patch': [ @@ -152,8 +173,20 @@ module.exports = class hitbtc extends Exchange { }, 'options': { 'defaultTimeInForce': 'FOK', + 'accountsByType': { + 'bank': 'bank', + 'exchange': 'exchange', + 'main': 'bank', // alias of the above + 'trading': 'exchange', + }, + 'fetchBalanceMethod': { + 'account': 'account', + 'main': 'account', + 'trading': 'trading', + }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BCC': 'BCC', // initial symbol for Bitcoin Cash, now inactive 'BET': 'DAO.Casino', 'BOX': 'BOX Token', @@ -180,7 +213,6 @@ module.exports = class hitbtc extends Exchange { '20002': OrderNotFound, // canceling non-existent order '20001': InsufficientFunds, // {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}} }, - 'orders': {}, // orders cache / emulation }); } @@ -217,14 +249,14 @@ module.exports = class hitbtc extends Exchange { if (id.indexOf ('_') >= 0) { symbol = id; } - const lot = this.safeFloat (market, 'quantityIncrement'); - const step = this.safeFloat (market, 'tickSize'); + const lot = this.safeNumber (market, 'quantityIncrement'); + const step = this.safeNumber (market, 'tickSize'); const precision = { 'price': step, 'amount': lot, }; - const taker = this.safeFloat (market, 'takeLiquidityRate'); - const maker = this.safeFloat (market, 'provideLiquidityRate'); + const taker = this.safeNumber (market, 'takeLiquidityRate'); + const maker = this.safeNumber (market, 'provideLiquidityRate'); const feeCurrencyId = this.safeString (market, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); result.push (this.extend (this.fees['trading'], { @@ -259,6 +291,49 @@ module.exports = class hitbtc extends Exchange { return result; } + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // account can be "exchange" or "bank", with aliases "main" or "trading" respectively + await this.loadMarkets (); + const currency = this.currency (code); + const requestAmount = this.currencyToPrecision (code, amount); + const request = { + 'currency': currency['id'], + 'amount': requestAmount, + }; + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + const keys = Object.keys (accountsByType); + if (fromId === undefined) { + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ') + ' instead of ' + fromId); + } + if (toId === undefined) { + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ') + ' instead of ' + toId); + } + if (fromId === toId) { + throw new ExchangeError (this.id + ' from and to cannot be the same account'); + } + type = fromId + 'To' + this.capitalize (toId); + } + request['type'] = type; + const response = await this.privatePostAccountTransfer (this.extend (request, params)); + // { id: '2db6ebab-fb26-4537-9ef8-1a689472d236' } + const id = this.safeString (response, 'id'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'amount': requestAmount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': undefined, + }; + } + async fetchCurrencies (params = {}) { const response = await this.publicGetCurrency (params); // @@ -314,7 +389,7 @@ module.exports = class hitbtc extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'payoutFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'payoutFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -354,15 +429,20 @@ module.exports = class hitbtc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } async fetchBalance (params = {}) { await this.loadMarkets (); const type = this.safeString (params, 'type', 'trading'); - const method = 'privateGet' + this.capitalize (type) + 'Balance'; + const fetchBalanceAccounts = this.safeValue (this.options, 'fetchBalanceMethod', {}); + const typeId = this.safeString (fetchBalanceAccounts, type); + if (typeId === undefined) { + throw new ExchangeError (this.id + ' fetchBalance account type must be either main or trading'); + } + const method = 'privateGet' + this.capitalize (typeId) + 'Balance'; const query = this.omit (params, 'type'); const response = await this[method] (query); const result = { 'info': response }; @@ -371,11 +451,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -392,11 +472,11 @@ module.exports = class hitbtc extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'max'), - this.safeFloat (ohlcv, 'min'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'max'), + this.safeNumber (ohlcv, 'min'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -442,10 +522,10 @@ module.exports = class hitbtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); let change = undefined; let percentage = undefined; let average = undefined; @@ -461,11 +541,11 @@ module.exports = class hitbtc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -541,7 +621,7 @@ module.exports = class hitbtc extends Exchange { market = this.safeMarket (marketId, market); const symbol = market['symbol']; let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = market ? market['feeCurrency'] : undefined; fee = { @@ -553,9 +633,11 @@ module.exports = class hitbtc extends Exchange { // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const orderId = this.safeString (trade, 'clientOrderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); const id = this.safeString (trade, 'id'); return { @@ -654,11 +736,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'hash'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -846,66 +928,25 @@ module.exports = class hitbtc extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'cumQuantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'cumQuantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); // we use clientOrderId as the order id with this exchange intentionally // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const id = this.safeString (order, 'clientOrderId'); const clientOrderId = id; - let price = this.safeFloat (order, 'price'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - if (price !== undefined) { - cost = filled * price; - } - } - } + const price = this.safeNumber (order, 'price'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); let trades = this.safeValue (order, 'tradesReport'); - let fee = undefined; - let average = this.safeValue (order, 'avgPrice'); + const fee = undefined; + const average = this.safeNumber (order, 'avgPrice'); if (trades !== undefined) { trades = this.parseTrades (trades, market); - let feeCost = undefined; - const numTrades = trades.length; - let tradesCost = 0; - for (let i = 0; i < numTrades; i++) { - if (feeCost === undefined) { - feeCost = 0; - } - tradesCost = this.sum (tradesCost, trades[i]['cost']); - const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); - if (tradeFeeCost !== undefined) { - feeCost = this.sum (feeCost, tradeFeeCost); - } - } - cost = tradesCost; - if ((filled !== undefined) && (filled > 0)) { - if (average === undefined) { - average = cost / filled; - } - if (type === 'market') { - if (price === undefined) { - price = average; - } - } - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, // https://github.com/ccxt/ccxt/issues/5674 'timestamp': created, @@ -920,13 +961,13 @@ module.exports = class hitbtc extends Exchange { 'stopPrice': undefined, 'average': average, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hollaex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hollaex.js index 52e81fec3..bde50ed15 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hollaex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/hollaex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadRequest, AuthenticationError, NetworkError, ArgumentsRequired, OrderNotFound, InsufficientFunds } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -15,7 +16,7 @@ module.exports = class hollaex extends Exchange { 'name': 'HollaEx', 'countries': [ 'KR' ], 'rateLimit': 333, - 'version': 'v1', + 'version': 'v2', 'has': { 'CORS': false, 'fetchMarkets': true, @@ -35,13 +36,13 @@ module.exports = class hollaex extends Exchange { 'cancelOrder': true, 'cancelAllOrders': true, 'fetchOpenOrders': true, - 'fetchClosedOrders': false, + 'fetchClosedOrders': true, 'fetchOpenOrder': true, 'fetchOrder': false, 'fetchDeposits': true, 'fetchWithdrawals': true, 'fetchTransactions': false, - 'fetchOrders': false, + 'fetchOrders': true, 'fetchMyTrades': true, 'withdraw': true, 'fetchDepositAddress': true, @@ -66,13 +67,17 @@ module.exports = class hollaex extends Exchange { 'public': { 'get': [ 'health', - 'constant', + 'constants', + 'kit', + 'tiers', 'ticker', - 'ticker/all', + 'tickers', + 'orderbook', 'orderbooks', 'trades', 'chart', - // TradingView data + 'charts', + // TradingView 'udf/config', 'udf/history', 'udf/symbols', @@ -82,20 +87,20 @@ module.exports = class hollaex extends Exchange { 'get': [ 'user', 'user/balance', - 'user/trades', - 'user/orders', - 'user/orders/{order_id}', 'user/deposits', 'user/withdrawals', - 'user/withdraw/{currency}/fee', + 'user/withdrawal/fee', + 'user/trades', + 'orders', + 'orders/{order_id}', ], 'post': [ 'user/request-withdrawal', 'order', ], 'delete': [ - 'user/orders', - 'user/orders/{order_id}', + 'order/all', + 'order', ], }, }, @@ -130,7 +135,7 @@ module.exports = class hollaex extends Exchange { } async fetchMarkets (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); // // { // coins: { @@ -197,17 +202,17 @@ module.exports = class hollaex extends Exchange { 'quoteId': quoteId, 'active': active, 'precision': { - 'price': this.safeFloat (market, 'increment_price'), - 'amount': this.safeFloat (market, 'increment_size'), + 'price': this.safeNumber (market, 'increment_price'), + 'amount': this.safeNumber (market, 'increment_size'), }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, 'max': undefined }, }, @@ -218,7 +223,7 @@ module.exports = class hollaex extends Exchange { } async fetchCurrencies (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); const coins = this.safeValue (response, 'coins', {}); const keys = Object.keys (coins); const result = {}; @@ -230,8 +235,8 @@ module.exports = class hollaex extends Exchange { const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'fullname'); const active = this.safeValue (currency, 'active'); - const fee = this.safeFloat (currency, 'withdrawal_fee'); - const precision = this.safeFloat (currency, 'increment_unit'); + const fee = this.safeNumber (currency, 'withdrawal_fee'); + const precision = this.safeNumber (currency, 'increment_unit'); const withdrawalLimits = this.safeValue (currency, 'withdrawal_limits', []); result[code] = { 'id': id, @@ -244,8 +249,8 @@ module.exports = class hollaex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min'), - 'max': this.safeFloat (currency, 'max'), + 'min': this.safeNumber (currency, 'min'), + 'max': this.safeNumber (currency, 'max'), }, 'price': { 'min': undefined, @@ -334,7 +339,7 @@ module.exports = class hollaex extends Exchange { async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.publicGetTickerAll (this.extend (params)); + const response = await this.publicGetTickers (this.extend (params)); // // { // "bch-usdt": { @@ -397,27 +402,27 @@ module.exports = class hollaex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString2 (ticker, 'time', 'timestamp')); - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const result = { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, - 'last': this.safeFloat (ticker, 'last', close), + 'last': this.safeNumber (ticker, 'last', close), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, }; return result; @@ -475,15 +480,12 @@ module.exports = class hollaex extends Exchange { const datetime = this.safeString (trade, 'timestamp'); const timestamp = this.parse8601 (datetime); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const quote = market['quote']; @@ -568,11 +570,11 @@ module.exports = class hollaex extends Exchange { // return [ this.parse8601 (this.safeString (response, 'time')), - this.safeFloat (response, 'open'), - this.safeFloat (response, 'high'), - this.safeFloat (response, 'low'), - this.safeFloat (response, 'close'), - this.safeFloat (response, 'volume'), + this.safeNumber (response, 'open'), + this.safeNumber (response, 'high'), + this.safeNumber (response, 'low'), + this.safeNumber (response, 'close'), + this.safeNumber (response, 'volume'), ]; } @@ -597,11 +599,11 @@ module.exports = class hollaex extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (response, currencyId + '_available'); - account['total'] = this.safeFloat (response, currencyId + '_balance'); + account['free'] = this.safeString (response, currencyId + '_available'); + account['total'] = this.safeString (response, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrder (id, symbol = undefined, params = {}) { @@ -609,67 +611,146 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateGetUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateGetOrdersOrderId (this.extend (request, params)); // // { - // "created_at": "2018-03-23T04:14:08.663Z", - // "title": "string", - // "side": "sell", - // "type": "limit", - // "price": 0, - // "size": 0, - // "symbol": "xht-usdt", // "id": "string", - // "created_by": 1, - // "filled": 0 + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } // } // return this.parseOrder (response); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'open': true, + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'status': 'filled', + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = undefined; - const request = {}; + const request = { + // 'symbol': market['id'], + // 'side': 'buy', // 'sell' + // 'status': 'new', // 'filled', 'pfilled', 'canceled' + // 'open': true, + // 'limit': limit, // default 50, max 100 + // 'page': 1, + // 'order_by': 'created_at', // id, ... + // 'order': 'asc', // 'desc' + // 'start_date': this.iso8601 (since), + // 'end_date': this.iso8601 (this.milliseconds ()), + }; if (symbol !== undefined) { market = this.market (symbol); request['symbol'] = market['id']; } - const response = await this.privateGetUserOrders (this.extend (request, params)); + if (since !== undefined) { + request['start_date'] = this.iso8601 (since); + } + if (limit !== undefined) { + request['limit'] = limit; // default 50, max 100 + } + const response = await this.privateGetOrders (this.extend (request, params)); // - // [ - // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 - // } - // ] + // { + // "count": 1, + // "data": [ + // { + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } + // } + // ] + // } // - return this.parseOrders (response, market); + const data = this.safeValue (response, 'data', []); + return this.parseOrders (data, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'new': 'open', + 'pfilled': 'open', + 'filled': 'closed', + 'canceled': 'canceled', + }; + return this.safeString (statuses, status, status); } parseOrder (order, market = undefined) { // - // fetchOpenOrder, fetchOpenOrders + // createOrder, fetchOpenOrder, fetchOpenOrders // // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // }, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, // } // const marketId = this.safeString (order, 'symbol'); @@ -678,21 +759,11 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filled'); - let cost = undefined; - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = filled * price; - } - } - const status = (type === 'market') ? 'closed' : 'open'; - const result = { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filled'); + const status = this.parseOrderStatus (this.safeString (order, 'status')); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -708,40 +779,56 @@ module.exports = class hollaex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; - return result; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); - const order = { + const request = { 'symbol': market['id'], 'side': side, 'size': amount, 'type': type, + // 'stop': parseFloat (this.priceToPrecision (symbol, stopPrice)), + // 'meta': {}, // other options such as post_only }; if (type !== 'market') { - order['price'] = price; + request['price'] = price; } - const response = await this.privatePostOrder (this.extend (order, params)); + const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop'); + if (stopPrice !== undefined) { + request['stop'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + params = this.omit (params, [ 'stopPrice', 'stop' ]); + } + const response = await this.privatePostOrder (this.extend (request, params)); // // { + // "fee": 0, + // "meta": {}, // "symbol": "xht-usdt", // "side": "sell", - // "size": 1, + // "size": 0.1, // "type": "limit", - // "price": 0.1, + // "price": 1, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, + // "fee_coin": "usdt", // "id": "string", - // "created_by": 34, + // "created_by": 116, // "filled": 0, - // "status": "pending" + // "status": "new", + // "updated_at": "2021-02-17T03:03:19.231Z", + // "created_at": "2021-02-17T03:03:19.231Z", + // "stop": null // } // return this.parseOrder (response, market); @@ -752,7 +839,7 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateDeleteUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateDeleteOrder (this.extend (request, params)); // // { // "title": "string", @@ -777,7 +864,7 @@ module.exports = class hollaex extends Exchange { market = this.markets (symbol); request['symbol'] = market['id']; } - const response = await this.privateDeleteUserOrders (this.extend (request, params)); + const response = await this.privateDeleteOrderAll (this.extend (request, params)); // // [ // { @@ -1043,7 +1130,7 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_at')); const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const type = this.safeString (transaction, 'type'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); let addressTo = undefined; const addressFrom = undefined; @@ -1073,7 +1160,7 @@ module.exports = class hollaex extends Exchange { } const fee = { 'currency': code, - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), }; return { 'info': transaction, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/huobipro.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/huobipro.js index 52dc315e8..22c1d91d5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/huobipro.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/huobipro.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, ArgumentsRequired, BadSymbol, BadRequest, RequestTimeout, NetworkError } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -22,7 +23,9 @@ module.exports = class huobipro extends Exchange { 'hostname': 'api.huobi.pro', // api.testnet.huobi.pro 'pro': true, 'has': { + 'cancelAllOrders': true, 'cancelOrder': true, + 'cancelOrders': true, 'CORS': false, 'createOrder': true, 'fetchBalance': true, @@ -189,6 +192,7 @@ module.exports = class huobipro extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.002, @@ -252,6 +256,7 @@ module.exports = class huobipro extends Exchange { // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/ 'PNT': 'Penta', 'SBTC': 'Super Bitcoin', + 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706 }, }); } @@ -316,8 +321,8 @@ module.exports = class huobipro extends Exchange { 'info': limits, 'limits': { 'amount': { - 'min': this.safeFloat (limits, 'limit-order-must-greater-than'), - 'max': this.safeFloat (limits, 'limit-order-must-less-than'), + 'min': this.safeNumber (limits, 'limit-order-must-greater-than'), + 'max': this.safeNumber (limits, 'limit-order-must-less-than'), }, }, }; @@ -351,9 +356,9 @@ module.exports = class huobipro extends Exchange { }; const maker = (base === 'OMG') ? 0 : 0.2 / 100; const taker = (base === 'OMG') ? 0 : 0.2 / 100; - const minAmount = this.safeFloat (market, 'min-order-amt', Math.pow (10, -precision['amount'])); - const maxAmount = this.safeFloat (market, 'max-order-amt'); - const minCost = this.safeFloat (market, 'min-order-value', 0); + const minAmount = this.safeNumber (market, 'min-order-amt', Math.pow (10, -precision['amount'])); + const maxAmount = this.safeNumber (market, 'max-order-amt'); + const minCost = this.safeNumber (market, 'min-order-value', 0); const state = this.safeString (market, 'state'); const active = (state === 'online'); result.push ({ @@ -432,24 +437,24 @@ module.exports = class huobipro extends Exchange { let askVolume = undefined; if ('bid' in ticker) { if (Array.isArray (ticker['bid'])) { - bid = this.safeFloat (ticker['bid'], 0); - bidVolume = this.safeFloat (ticker['bid'], 1); + bid = this.safeNumber (ticker['bid'], 0); + bidVolume = this.safeNumber (ticker['bid'], 1); } else { - bid = this.safeFloat (ticker, 'bid'); + bid = this.safeNumber (ticker, 'bid'); bidVolume = this.safeValue (ticker, 'bidSize'); } } if ('ask' in ticker) { if (Array.isArray (ticker['ask'])) { - ask = this.safeFloat (ticker['ask'], 0); - askVolume = this.safeFloat (ticker['ask'], 1); + ask = this.safeNumber (ticker['ask'], 0); + askVolume = this.safeNumber (ticker['ask'], 1); } else { - ask = this.safeFloat (ticker, 'ask'); + ask = this.safeNumber (ticker, 'ask'); askVolume = this.safeValue (ticker, 'askSize'); } } - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -460,15 +465,15 @@ module.exports = class huobipro extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -557,7 +562,7 @@ module.exports = class huobipro extends Exchange { // } // const ticker = this.parseTicker (response['tick'], market); - const timestamp = this.safeValue (response, 'ts'); + const timestamp = this.safeInteger (response, 'ts'); ticker['timestamp'] = timestamp; ticker['datetime'] = this.iso8601 (timestamp); return ticker; @@ -626,21 +631,18 @@ module.exports = class huobipro extends Exchange { type = typeParts[1]; } const takerOrMaker = this.safeString (trade, 'role'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'filled-amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'filled-amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - let feeCost = this.safeFloat (trade, 'filled-fees'); + let feeCost = this.safeNumber (trade, 'filled-fees'); let feeCurrency = undefined; if (market !== undefined) { feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-currency')); } - const filledPoints = this.safeFloat (trade, 'filled-points'); + const filledPoints = this.safeNumber (trade, 'filled-points'); if (filledPoints !== undefined) { if ((feeCost === undefined) || (feeCost === 0.0)) { feeCost = filledPoints; @@ -754,11 +756,11 @@ module.exports = class huobipro extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -855,11 +857,11 @@ module.exports = class huobipro extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'deposit-min-amount'), + 'min': this.safeNumber (currency, 'deposit-min-amount'), 'max': Math.pow (10, precision), }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw-min-amount'), + 'min': this.safeNumber (currency, 'withdraw-min-amount'), 'max': Math.pow (10, precision), }, }, @@ -890,14 +892,14 @@ module.exports = class huobipro extends Exchange { account = this.account (); } if (balance['type'] === 'trade') { - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); } if (balance['type'] === 'frozen') { - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrdersByStates (states, symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1072,28 +1074,14 @@ module.exports = class huobipro extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (order, 'created-at'); - let amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount - if ((type === 'market') && (side === 'buy')) { - amount = (status === 'closed') ? filled : undefined; - } - let price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - const cost = this.safeFloat2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - // if cost is defined and filled is not zero - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - const feeCost = this.safeFloat2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees + const cost = this.safeNumber2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo + const feeCost = this.safeNumber2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -1105,7 +1093,7 @@ module.exports = class huobipro extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1119,15 +1107,15 @@ module.exports = class huobipro extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1201,26 +1189,82 @@ module.exports = class huobipro extends Exchange { }); } - currencyToPrecision (currency, fee) { - return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); + async cancelOrders (ids, symbol = undefined, params = {}) { + await this.loadMarkets (); + const clientOrderIds = this.safeValue2 (params, 'clientOrderIds', 'client-order-ids'); + params = this.omit (params, [ 'clientOrderIds', 'client-order-ids' ]); + const request = {}; + if (clientOrderIds === undefined) { + request['order-ids'] = ids; + } else { + request['client-order-ids'] = clientOrderIds; + } + const response = await this.privatePostOrderOrdersBatchcancel (this.extend (request, params)); + // + // { + // "status": "ok", + // "data": { + // "success": [ + // "5983466" + // ], + // "failed": [ + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "first" + // }, + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "second" + // }, + // { + // "err-msg": "The record is not found.", + // "order-id": "", + // "err-code": "base-not-found", + // "client-order-id": "third" + // } + // ] + // } + // } + // + return response; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (market[key], cost)), + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts + // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default + // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok + // 'side': 'buy', // or 'sell' + // 'size': 100, // the number of orders to cancel 1-100 }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.privatePostOrderOrdersBatchCancelOpenOrders (this.extend (request, params)); + // + // { + // code: 200, + // data: { + // "success-count": 2, + // "failed-count": 0, + // "next-id": 5454600 + // } + // } + // + return response; + } + + currencyToPrecision (currency, fee) { + return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); } parseDepositAddress (depositAddress, currency = undefined) { @@ -1362,7 +1406,7 @@ module.exports = class huobipro extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const tag = this.safeString (transaction, 'address-tag'); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -1375,7 +1419,7 @@ module.exports = class huobipro extends Exchange { 'address': this.safeString (transaction, 'address'), 'tag': tag, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ice3x.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ice3x.js deleted file mode 100644 index f228076d1..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ice3x.js +++ /dev/null @@ -1,495 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class ice3x extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'ice3x', - 'name': 'ICE3X', - 'countries': [ 'ZA' ], // South Africa - 'rateLimit': 1000, - 'version': 'v1', - 'has': { - 'cancelOrder': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchCurrencies': true, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTrades': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg', - 'api': 'https://ice3x.com/api', - 'www': 'https://ice3x.com', // 'https://ice3x.co.za', - 'doc': 'https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017', - 'fees': [ - 'https://help.ice3.com/support/solutions/articles/11000033293-trading-fees', - 'https://help.ice3.com/support/solutions/articles/11000033288-fees-explained', - 'https://help.ice3.com/support/solutions/articles/11000008131-what-are-your-fiat-deposit-and-withdrawal-fees-', - 'https://help.ice3.com/support/solutions/articles/11000033289-deposit-fees', - ], - 'referral': 'https://ice3x.com?ref=14341802', - }, - 'api': { - 'public': { - 'get': [ - 'currency/list', - 'currency/info', - 'pair/list', - 'pair/info', - 'stats/marketdepthfull', - 'stats/marketdepthbtcav', - 'stats/marketdepth', - 'orderbook/info', - 'trade/list', - 'trade/info', - ], - }, - 'private': { - 'post': [ - 'balance/list', - 'balance/info', - 'order/new', - 'order/cancel', - 'order/list', - 'order/info', - 'trade/list', - 'trade/info', - 'transaction/list', - 'transaction/info', - 'invoice/list', - 'invoice/info', - 'invoice/pdf', - ], - }, - }, - 'fees': { - 'trading': { - 'maker': 0.005, - 'taker': 0.005, - }, - }, - 'precision': { - 'amount': 8, - 'price': 8, - }, - }); - } - - async fetchCurrencies (params = {}) { - const response = await this.publicGetCurrencyList (params); - const currencies = response['response']['entities']; - const precision = this.precision['amount']; - const result = {}; - for (let i = 0; i < currencies.length; i++) { - const currency = currencies[i]; - const id = this.safeString (currency, 'currency_id'); - const currencyId = this.safeString (currency, 'iso'); - const code = this.safeCurrencyCode (currencyId); - result[code] = { - 'id': id, - 'code': code, - 'name': currency['name'], - 'active': true, - 'precision': precision, - 'limits': { - 'amount': { - 'min': undefined, - 'max': Math.pow (10, precision), - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': Math.pow (10, precision), - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - }, - 'info': currency, - 'fee': undefined, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - if (this.currencies_by_id === undefined) { - this.currencies = await this.fetchCurrencies (); - this.currencies_by_id = this.indexBy (this.currencies, 'id'); - } - const response = await this.publicGetPairList (params); - const markets = this.safeValue (response['response'], 'entities'); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = this.safeString (market, 'pair_id'); - const baseId = this.safeString (market, 'currency_id_from'); - const quoteId = this.safeString (market, 'currency_id_to'); - const baseCurrency = this.currencies_by_id[baseId]; - const quoteCurrency = this.currencies_by_id[quoteId]; - const base = baseCurrency['code']; - const quote = quoteCurrency['code']; - const symbol = base + '/' + quote; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': undefined, - 'info': market, - 'precision': this.precision, - 'limits': this.limits, - }); - } - return result; - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.milliseconds (); - const symbol = market['symbol']; - const last = this.safeFloat (ticker, 'last_price'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'max_bid'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'min_ask'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'vol'), - 'info': ticker, - }; - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetStatsMarketdepthfull (this.extend (request, params)); - const ticker = this.safeValue (response['response'], 'entity'); - return this.parseTicker (ticker, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetStatsMarketdepthfull (params); - const tickers = this.safeValue (response['response'], 'entities'); - const result = {}; - for (let i = 0; i < tickers.length; i++) { - const ticker = tickers[i]; - const marketId = this.safeString (ticker, 'pair_id'); - const market = this.safeValue (this.marketsById, marketId); - if (market !== undefined) { - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); - } - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'pair_id': this.marketId (symbol), - }; - if (limit !== undefined) { - const type = this.safeString (params, 'type'); - if ((type !== 'ask') && (type !== 'bid')) { - // eslint-disable-next-line quotes - throw new ArgumentsRequired (this.id + " fetchOrderBook() requires an exchange-specific extra 'type' param ('bid' or 'ask') when used with a limit"); - } else { - request['items_per_page'] = limit; - } - } - const response = await this.publicGetOrderbookInfo (this.extend (request, params)); - const orderbook = this.safeValue (response['response'], 'entities'); - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.safeTimestamp (trade, 'created'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } - const type = 'limit'; - const side = this.safeString (trade, 'type'); - const id = this.safeString (trade, 'trade_id'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'id': id, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': type, - 'side': side, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetTradeList (this.extend (request, params)); - const trades = this.safeValue (response['response'], 'entities'); - return this.parseTrades (trades, market, since, limit); - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostBalanceList (params); - const result = { 'info': response }; - const balances = this.safeValue (response['response'], 'entities', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - // currency ids are numeric strings - const currencyId = this.safeString (balance, 'currency_id'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseOrder (order, market = undefined) { - const pairId = this.safeInteger (order, 'pair_id'); - let symbol = undefined; - if (pairId && !market && (pairId in this.marketsById)) { - market = this.marketsById[pairId]; - symbol = market['symbol']; - } - const timestamp = this.safeTimestamp (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - let status = this.safeInteger (order, 'active'); - let remaining = this.safeFloat (order, 'remaining'); - let filled = undefined; - if (status === 1) { - status = 'open'; - } else { - status = 'closed'; - remaining = 0; - filled = amount; - } - let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - }; - if (market !== undefined) { - fee['currency'] = market['quote']; - } - } - return { - 'id': this.safeString (order, 'order_id'), - 'clientOrderId': undefined, - 'datetime': this.iso8601 (timestamp), - 'timestamp': timestamp, - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': 'limit', - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': this.safeString (order, 'type'), - 'price': price, - 'stopPrice': undefined, - 'cost': undefined, - 'amount': amount, - 'filled': filled, - 'remaining': remaining, - 'trades': undefined, - 'fee': fee, - 'info': order, - 'average': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - 'type': side, - 'amount': amount, - 'price': price, - }; - const response = await this.privatePostOrderNew (this.extend (request, params)); - const order = this.parseOrder ({ - 'order_id': response['response']['entity']['order_id'], - 'created': this.seconds (), - 'active': 1, - 'type': side, - 'price': price, - 'volume': amount, - 'remaining': amount, - 'info': response, - }, market); - return order; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - const request = { - 'order_id': id, - }; - return await this.privatePostOrderCancel (this.extend (request, params)); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'order _id': id, - }; - const response = await this.privatePostOrderInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const order = this.safeValue (data, 'entity'); - return this.parseOrder (order); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.privatePostOrderList (params); - const data = this.safeValue (response, 'response', {}); - const orders = this.safeValue (data, 'entities', []); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - return this.parseOrders (orders, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - if (limit !== undefined) { - request['items_per_page'] = limit; - } - if (since !== undefined) { - request['date_from'] = parseInt (since / 1000); - } - const response = await this.privatePostTradeList (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const trades = this.safeValue (data, 'entities', []); - return this.parseTrades (trades, market, since, limit); - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency_id': currency['id'], - }; - const response = await this.privatePostBalanceInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const balance = this.safeValue (data, 'entity', {}); - const address = this.safeString (balance, 'address'); - const status = address ? 'ok' : 'none'; - return { - 'currency': code, - 'address': address, - 'tag': undefined, - 'status': status, - 'info': response, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/' + this.version + '/' + path; - if (api === 'public') { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } - } else { - this.checkRequiredCredentials (); - body = this.urlencode (this.extend ({ - 'nonce': this.nonce (), - }, params)); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': this.hmac (this.encode (body), this.encode (this.secret), 'sha512'), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const response = await this.fetch2 (path, api, method, params, headers, body); - const errors = this.safeValue (response, 'errors'); - const data = this.safeValue (response, 'response'); - if (errors || !data) { - const authErrorKeys = [ 'Key', 'user_id', 'Sign' ]; - for (let i = 0; i < authErrorKeys.length; i++) { - const errorKey = authErrorKeys[i]; - const errorMessage = this.safeString (errors, errorKey); - if (!errorMessage) { - continue; - } - if (errorKey === 'user_id' && errorMessage.indexOf ('authorization') < 0) { - continue; - } - throw new AuthenticationError (errorMessage); - } - throw new ExchangeError (this.json (errors)); - } - return response; - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/idex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/idex.js index 7d52a5286..c3c14d981 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/idex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/idex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { PAD_WITH_ZERO } = require ('./base/functions/number'); const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported, InvalidAddress, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -241,14 +242,6 @@ module.exports = class idex extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // { // market: 'DIL-ETH', @@ -268,16 +261,16 @@ module.exports = class idex extends Exchange { // } const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'baseVolume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'baseVolume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'open'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const close = this.safeFloat (ticker, 'close'); - const ask = this.safeFloat (ticker, 'ask'); - const bid = this.safeFloat (ticker, 'bid'); - let percentage = this.safeFloat (ticker, 'percentChange'); + const open = this.safeNumber (ticker, 'open'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const close = this.safeNumber (ticker, 'close'); + const ask = this.safeNumber (ticker, 'ask'); + const bid = this.safeNumber (ticker, 'bid'); + let percentage = this.safeNumber (ticker, 'percentChange'); if (percentage !== undefined) { percentage = 1 + percentage / 100; } @@ -353,11 +346,11 @@ module.exports = class idex extends Exchange { // sequence: 3853 // } const timestamp = this.safeInteger (ohlcv, 'start'); - const open = this.safeFloat (ohlcv, 'open'); - const high = this.safeFloat (ohlcv, 'high'); - const low = this.safeFloat (ohlcv, 'low'); - const close = this.safeFloat (ohlcv, 'close'); - const volume = this.safeFloat (ohlcv, 'volume'); + const open = this.safeNumber (ohlcv, 'open'); + const high = this.safeNumber (ohlcv, 'high'); + const low = this.safeNumber (ohlcv, 'low'); + const close = this.safeNumber (ohlcv, 'close'); + const volume = this.safeNumber (ohlcv, 'volume'); return [ timestamp, open, high, low, close, volume ]; } @@ -419,9 +412,14 @@ module.exports = class idex extends Exchange { // txStatus: 'mined' // } const id = this.safeString (trade, 'fillId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'quoteQuantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteQuantity'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const timestamp = this.safeInteger (trade, 'time'); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); @@ -430,7 +428,7 @@ module.exports = class idex extends Exchange { const oppositeSide = (makerSide === 'buy') ? 'sell' : 'buy'; const side = this.safeString (trade, 'side', oppositeSide); const takerOrMaker = this.safeString (trade, 'liquidity', 'taker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); @@ -503,8 +501,8 @@ module.exports = class idex extends Exchange { const result = []; for (let i = 0; i < bookSide.length; i++) { const order = bookSide[i]; - const price = this.safeFloat (order, 0); - const amount = this.safeFloat (order, 1); + const price = this.safeNumber (order, 0); + const amount = this.safeNumber (order, 1); const orderCount = this.safeInteger (order, 2); result.push ([ price, amount, orderCount ]); } @@ -591,16 +589,13 @@ module.exports = class idex extends Exchange { const entry = response[i]; const currencyId = this.safeString (entry, 'asset'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (entry, 'quantity'); - const free = this.safeFloat (entry, 'availableForTrade'); - const used = this.safeFloat (entry, 'locked'); - result[code] = { - 'free': free, - 'used': used, - 'total': total, - }; + const account = this.account (); + account['total'] = this.safeString (entry, 'quantity'); + account['free'] = this.safeString (entry, 'availableForTrade'); + account['used'] = this.safeString (entry, 'locked'); + result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -821,10 +816,10 @@ module.exports = class idex extends Exchange { const symbol = this.safeSymbol (marketId, market, '-'); const trades = this.parseTrades (fills, market); const type = this.safeString (order, 'type'); - const amount = this.safeFloat (order, 'originalQuantity'); - const filled = this.safeFloat (order, 'executedQuantity'); - const average = this.safeFloat (order, 'avgExecutionPrice'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'originalQuantity'); + const filled = this.safeNumber (order, 'executedQuantity'); + const average = this.safeNumber (order, 'avgExecutionPrice'); + const price = this.safeNumber (order, 'price'); const rawStatus = this.safeString (order, 'status'); const status = this.parseOrderStatus (rawStatus); const fee = { @@ -933,7 +928,7 @@ module.exports = class idex extends Exchange { throw new NotSupported (this.id + ' quoteOrderQuantity is not supported for ' + type + ' orders, only supported for market orders'); } amountEnum = 1; - amount = this.safeFloat (params, 'quoteOrderQuantity'); + amount = this.safeNumber (params, 'quoteOrderQuantity'); } const sideEnum = (side === 'buy') ? 0 : 1; const walletBytes = this.remove0xPrefix (this.walletAddress); @@ -1236,13 +1231,13 @@ module.exports = class idex extends Exchange { } const id = this.safeString2 (transaction, 'depositId', 'withdrawId'); const code = this.safeCurrencyCode (this.safeString (transaction, 'asset'), currency); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const txid = this.safeString (transaction, 'txId'); const timestamp = this.safeInteger (transaction, 'txTime'); let fee = undefined; if ('fee' in transaction) { fee = { - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), 'currency': 'ETH', }; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/independentreserve.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/independentreserve.js index 119a216d5..86dcb348b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/independentreserve.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/independentreserve.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -126,11 +127,11 @@ module.exports = class independentreserve extends Exchange { const currencyId = this.safeString (balance, 'CurrencyCode'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'AvailableBalance'); - account['total'] = this.safeFloat (balance, 'TotalBalance'); + account['free'] = this.safeString (balance, 'AvailableBalance'); + account['total'] = this.safeString (balance, 'TotalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -151,16 +152,16 @@ module.exports = class independentreserve extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'LastPrice'); + const last = this.safeNumber (ticker, 'LastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'DayHighestPrice'), - 'low': this.safeFloat (ticker, 'DayLowestPrice'), - 'bid': this.safeFloat (ticker, 'CurrentHighestBidPrice'), + 'high': this.safeNumber (ticker, 'DayHighestPrice'), + 'low': this.safeNumber (ticker, 'DayLowestPrice'), + 'bid': this.safeNumber (ticker, 'CurrentHighestBidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'CurrentLowestOfferPrice'), + 'ask': this.safeNumber (ticker, 'CurrentLowestOfferPrice'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -169,8 +170,8 @@ module.exports = class independentreserve extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'DayAvgPrice'), - 'baseVolume': this.safeFloat (ticker, 'DayVolumeXbtInSecondaryCurrrency'), + 'average': this.safeNumber (ticker, 'DayAvgPrice'), + 'baseVolume': this.safeNumber (ticker, 'DayVolumeXbtInSecondaryCurrrency'), 'quoteVolume': undefined, 'info': ticker, }; @@ -249,20 +250,10 @@ module.exports = class independentreserve extends Exchange { orderType = 'limit'; } const timestamp = this.parse8601 (this.safeString (order, 'CreatedTimestampUtc')); - const amount = this.safeFloat2 (order, 'VolumeOrdered', 'Volume'); - let filled = this.safeFloat (order, 'VolumeFilled'); - let remaining = this.safeFloat (order, 'Outstanding'); - if (filled === undefined) { - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (0, amount - remaining); - } - } - if (remaining === undefined) { - if ((filled !== undefined) && (amount !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const feeRate = this.safeFloat (order, 'FeePercent'); + const amount = this.safeNumber2 (order, 'VolumeOrdered', 'Volume'); + const filled = this.safeNumber (order, 'VolumeFilled'); + const remaining = this.safeNumber (order, 'Outstanding'); + const feeRate = this.safeNumber (order, 'FeePercent'); let feeCost = undefined; if (feeRate !== undefined) { feeCost = feeRate * filled; @@ -274,10 +265,10 @@ module.exports = class independentreserve extends Exchange { }; const id = this.safeString (order, 'OrderGuid'); const status = this.parseOrderStatus (this.safeString (order, 'Status')); - const cost = this.safeFloat (order, 'Value'); - const average = this.safeFloat (order, 'AvgPrice'); - const price = this.safeFloat (order, 'Price', average); - return { + const cost = this.safeNumber (order, 'Value'); + const average = this.safeNumber (order, 'AvgPrice'); + const price = this.safeNumber (order, 'Price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -299,7 +290,7 @@ module.exports = class independentreserve extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -387,14 +378,11 @@ module.exports = class independentreserve extends Exchange { const timestamp = this.parse8601 (trade['TradeTimestampUtc']); const id = this.safeString (trade, 'TradeGuid'); const orderId = this.safeString (trade, 'OrderGuid'); - const price = this.safeFloat2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); - const amount = this.safeFloat2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); + const amountString = this.safeString2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const baseId = this.safeString (trade, 'PrimaryCurrencyCode'); const quoteId = this.safeString (trade, 'SecondaryCurrencyCode'); let marketId = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/indodax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/indodax.js index f1cc33732..05972a887 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/indodax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/indodax.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, InvalidOrder, OrderNotFound, AuthenticationError, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,7 +165,7 @@ module.exports = class indodax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const taker = this.safeFloat (market, 'trade_fee_percent'); + const taker = this.safeNumber (market, 'trade_fee_percent'); const isMaintenance = this.safeInteger (market, 'is_maintenance'); const active = (isMaintenance) ? false : true; const pricePrecision = this.safeInteger (market, 'price_round'); @@ -174,11 +175,11 @@ module.exports = class indodax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'trade_min_traded_currency'), + 'min': this.safeNumber (market, 'trade_min_traded_currency'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'trade_min_base_currency'), + 'min': this.safeNumber (market, 'trade_min_base_currency'), 'max': undefined, }, 'cost': { @@ -216,11 +217,11 @@ module.exports = class indodax extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (used, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (used, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -257,16 +258,16 @@ module.exports = class indodax extends Exchange { const timestamp = this.safeTimestamp (ticker, 'server_time'); const baseVolume = 'vol_' + market['baseId'].toLowerCase (); const quoteVolume = 'vol_' + market['quoteId'].toLowerCase (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -276,8 +277,8 @@ module.exports = class indodax extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, baseVolume), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, baseVolume), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -291,14 +292,11 @@ module.exports = class indodax extends Exchange { } const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -353,7 +351,7 @@ module.exports = class indodax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status', 'open')); let symbol = undefined; let cost = undefined; - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let amount = undefined; let remaining = undefined; let filled = undefined; @@ -367,18 +365,18 @@ module.exports = class indodax extends Exchange { if ((market['baseId'] === 'idr') && ('remain_rp' in order)) { baseId = 'rp'; } - cost = this.safeFloat (order, 'order_' + quoteId); + cost = this.safeNumber (order, 'order_' + quoteId); if (cost) { amount = cost / price; - const remainingCost = this.safeFloat (order, 'remain_' + quoteId); + const remainingCost = this.safeNumber (order, 'remain_' + quoteId); if (remainingCost !== undefined) { remaining = remainingCost / price; filled = amount - remaining; } } else { - amount = this.safeFloat (order, 'order_' + baseId); + amount = this.safeNumber (order, 'order_' + baseId); cost = price * amount; - remaining = this.safeFloat (order, 'remain_' + baseId); + remaining = this.safeNumber (order, 'remain_' + baseId); filled = amount - remaining; } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/itbit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/itbit.js index 552bb0de5..a46080ccc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/itbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/itbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -114,25 +115,25 @@ module.exports = class itbit extends Exchange { throw new ExchangeError (this.id + ' fetchTicker returned a bad response: ' + this.json (ticker)); } const timestamp = this.parse8601 (serverTimeUTC); - const vwap = this.safeFloat (ticker, 'vwap24h'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); + const vwap = this.safeNumber (ticker, 'vwap24h'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'openToday'), + 'open': this.safeNumber (ticker, 'openToday'), 'close': last, 'last': last, 'previousClose': undefined, @@ -179,23 +180,20 @@ module.exports = class itbit extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const side = this.safeString (trade, 'direction'); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'commissionPaid'); + let feeCost = this.safeNumber (trade, 'commissionPaid'); const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - let rebatesApplied = this.safeFloat (trade, 'rebatesApplied'); + let rebatesApplied = this.safeNumber (trade, 'rebatesApplied'); if (rebatesApplied !== undefined) { rebatesApplied = -rebatesApplied; } const rebateCurrencyId = this.safeString (trade, 'rebateCurrency'); const rebateCurrency = this.safeCurrencyCode (rebateCurrencyId); - const price = this.safeFloat2 (trade, 'price', 'rate'); - const amount = this.safeFloat2 (trade, 'currency1Amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'price', 'rate'); + const amountString = this.safeString2 (trade, 'currency1Amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; const marketId = this.safeString (trade, 'instrument'); if (marketId !== undefined) { @@ -317,7 +315,7 @@ module.exports = class itbit extends Exchange { 'txid': txnHash, 'type': transactionType, 'status': status, - 'amount': this.safeFloat (item, 'amount'), + 'amount': this.safeNumber (item, 'amount'), 'fee': undefined, 'info': item, }); @@ -417,11 +415,11 @@ module.exports = class itbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchWallets (params = {}) { @@ -512,26 +510,16 @@ module.exports = class itbit extends Exchange { const type = this.safeString (order, 'type'); const symbol = this.markets_by_id[order['instrument']]['symbol']; const timestamp = this.parse8601 (order['createdTime']); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'amountFilled'); - let remaining = undefined; - let cost = undefined; + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'amountFilled'); const fee = undefined; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'volumeWeightedAveragePrice'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'volumeWeightedAveragePrice'); const clientOrderId = this.safeString (order, 'clientOrderIdentifier'); const id = this.safeString (order, 'id'); const postOnlyString = this.safeString (order, 'postOnly'); const postOnly = (postOnlyString === 'True'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -546,15 +534,15 @@ module.exports = class itbit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, // 'trades': this.parseTrades (order['trades'], market), 'trades': undefined, - }; + }); } nonce () { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kraken.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kraken.js index 198ee4cf8..514ed0094 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kraken.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kraken.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeNotAvailable, ArgumentsRequired, PermissionDenied, AuthenticationError, ExchangeError, OrderNotFound, DDoSProtection, InvalidNonce, InsufficientFunds, CancelPending, InvalidOrder, InvalidAddress, RateLimitExceeded } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -297,26 +298,38 @@ module.exports = class kraken extends Exchange { // } // } // - const keys = Object.keys (response['result']); + const markets = this.safeValue (response, 'result', {}); + const keys = Object.keys (markets); let result = []; for (let i = 0; i < keys.length; i++) { const id = keys[i]; - const market = response['result'][id]; - const baseId = market['base']; - const quoteId = market['quote']; + const market = markets[id]; + const baseId = this.safeString (market, 'base'); + const quoteId = this.safeString (market, 'quote'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const darkpool = id.indexOf ('.d') >= 0; - const symbol = darkpool ? market['altname'] : (base + '/' + quote); + const altname = this.safeString (market, 'altname'); + const symbol = darkpool ? altname : (base + '/' + quote); + const makerFees = this.safeValue (market, 'fees_maker', []); + const firstMakerFee = this.safeValue (makerFees, 0, []); + const firstMakerFeeRate = this.safeNumber (firstMakerFee, 1); let maker = undefined; - if ('fees_maker' in market) { - maker = parseFloat (market['fees_maker'][0][1]) / 100; + if (firstMakerFeeRate !== undefined) { + maker = parseFloat (firstMakerFeeRate) / 100; + } + const takerFees = this.safeValue (market, 'fees', []); + const firstTakerFee = this.safeValue (takerFees, 0, []); + const firstTakerFeeRate = this.safeNumber (firstTakerFee, 1); + let taker = undefined; + if (firstTakerFeeRate !== undefined) { + taker = parseFloat (firstTakerFeeRate) / 100; } const precision = { - 'amount': market['lot_decimals'], - 'price': market['pair_decimals'], + 'amount': this.safeInteger (market, 'lot_decimals'), + 'price': this.safeInteger (market, 'pair_decimals'), }; - const minAmount = this.safeFloat (market, 'ordermin'); + const minAmount = this.safeNumber (market, 'ordermin'); result.push ({ 'id': id, 'symbol': symbol, @@ -328,7 +341,7 @@ module.exports = class kraken extends Exchange { 'info': market, 'altname': market['altname'], 'maker': maker, - 'taker': parseFloat (market['fees'][0][1]) / 100, + 'taker': taker, 'active': true, 'precision': precision, 'limits': { @@ -451,7 +464,7 @@ module.exports = class kraken extends Exchange { await this.loadMarkets (); this.checkRequiredCredentials (); const response = await this.privatePostTradeVolume (params); - const tradedVolume = this.safeFloat (response['result'], 'volume'); + const tradedVolume = this.safeNumber (response['result'], 'volume'); const tiers = this.fees['trading']['tiers']; let taker = tiers['taker'][1]; let maker = tiers['maker'][1]; @@ -473,8 +486,8 @@ module.exports = class kraken extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); const timestamp = this.safeInteger (bidask, 2); return [ price, amount, timestamp ]; } @@ -512,7 +525,14 @@ module.exports = class kraken extends Exchange { // } // const result = this.safeValue (response, 'result', {}); - const orderbook = this.safeValue (result, market['id']); + let orderbook = this.safeValue (result, market['id']); + // sometimes kraken returns wsname instead of market id + // https://github.com/ccxt/ccxt/issues/8662 + const marketInfo = this.safeValue (market, 'info', {}); + const wsName = this.safeValue (marketInfo, 'wsname'); + if (wsName !== undefined) { + orderbook = this.safeValue (result, wsName, orderbook); + } return this.parseOrderBook (orderbook); } @@ -540,7 +560,7 @@ module.exports = class kraken extends Exchange { 'ask': parseFloat (ticker['a'][0]), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'o'), + 'open': this.safeNumber (ticker, 'o'), 'close': last, 'last': last, 'previousClose': undefined, @@ -611,11 +631,11 @@ module.exports = class kraken extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 6), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 6), ]; } @@ -682,24 +702,24 @@ module.exports = class kraken extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'asset'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); } else { direction = 'in'; } - const time = this.safeFloat (item, 'time'); + const time = this.safeNumber (item, 'time'); let timestamp = undefined; if (time !== undefined) { timestamp = parseInt (time * 1000); } const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -823,9 +843,8 @@ module.exports = class kraken extends Exchange { let timestamp = undefined; let side = undefined; let type = undefined; - let price = undefined; - let amount = undefined; - let cost = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; let orderId = undefined; let fee = undefined; @@ -834,8 +853,8 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 2); side = (trade[3] === 's') ? 'sell' : 'buy'; type = (trade[4] === 'l') ? 'limit' : 'market'; - price = this.safeFloat (trade, 0); - amount = this.safeFloat (trade, 1); + priceString = this.safeString (trade, 0); + amountString = this.safeString (trade, 1); const tradeLength = trade.length; if (tradeLength > 6) { id = this.safeString (trade, 6); // artificially added as per #1794 @@ -856,15 +875,15 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 'time'); side = this.safeString (trade, 'type'); type = this.safeString (trade, 'ordertype'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'vol'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'vol'); if ('fee' in trade) { let currency = undefined; if (market !== undefined) { currency = market['quote']; } fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': currency, }; } @@ -872,11 +891,9 @@ module.exports = class kraken extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': orderId, @@ -951,10 +968,10 @@ module.exports = class kraken extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -983,15 +1000,15 @@ module.exports = class kraken extends Exchange { if (type === 'limit') { request['price'] = this.priceToPrecision (symbol, price); } else if ((type === 'stop-loss') || (type === 'take-profit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice', price); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice', price); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a price/stopPrice parameter for a ' + type + ' order'); } else { request['price'] = this.priceToPrecision (symbol, stopPrice); } } else if ((type === 'stop-loss-limit') || (type === 'take-profit-limit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice'); - const limitPrice = this.safeFloat (params, 'price2'); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice'); + const limitPrice = this.safeNumber (params, 'price2'); const stopPriceDefined = (stopPrice !== undefined); const limitPriceDefined = (limitPrice !== undefined); if (stopPriceDefined && limitPriceDefined) { @@ -1100,10 +1117,10 @@ module.exports = class kraken extends Exchange { if (orderDescription !== undefined) { const parts = orderDescription.split (' '); side = this.safeString (parts, 0); - amount = this.safeFloat (parts, 1); + amount = this.safeNumber (parts, 1); marketId = this.safeString (parts, 2); type = this.safeString (parts, 4); - price = this.safeFloat (parts, 5); + price = this.safeNumber (parts, 5); } side = this.safeString (description, 'type', side); type = this.safeString (description, 'ordertype', type); @@ -1117,27 +1134,23 @@ module.exports = class kraken extends Exchange { market = this.getDelistedMarketById (marketId); } const timestamp = this.safeTimestamp (order, 'opentm'); - amount = this.safeFloat (order, 'vol', amount); - const filled = this.safeFloat (order, 'vol_exec'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = amount - filled; - } + amount = this.safeNumber (order, 'vol', amount); + const filled = this.safeNumber (order, 'vol_exec'); let fee = undefined; - const cost = this.safeFloat (order, 'cost'); - price = this.safeFloat (description, 'price', price); + const cost = this.safeNumber (order, 'cost'); + price = this.safeNumber (description, 'price', price); if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (description, 'price2'); + price = this.safeNumber (description, 'price2'); } if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (order, 'price', price); + price = this.safeNumber (order, 'price', price); } - const average = this.safeFloat (order, 'price'); + const average = this.safeNumber (order, 'price'); if (market !== undefined) { symbol = market['symbol']; if ('fee' in order) { const flags = order['oflags']; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); fee = { 'cost': feeCost, 'rate': undefined, @@ -1161,8 +1174,8 @@ module.exports = class kraken extends Exchange { if (rawTrades !== undefined) { trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id }); } - const stopPrice = this.safeFloat (order, 'stopprice'); - return { + const stopPrice = this.safeNumber (order, 'stopprice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -1181,10 +1194,10 @@ module.exports = class kraken extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1534,10 +1547,10 @@ module.exports = class kraken extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const address = this.safeString (transaction, 'info'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.safeString (transaction, 'type'); // injected from the outside - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost === undefined) { if (type === 'deposit') { feeCost = 0; @@ -1714,7 +1727,7 @@ module.exports = class kraken extends Exchange { throw new ExchangeError (this.id + " withdraw() requires a 'key' parameter (withdrawal key name, as set up on your account)"); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { // 'txid': 'comma delimited list of transaction ids to restrict output to', diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kucoin.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kucoin.js index bcb058989..0b5aca5af 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kucoin.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kucoin.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, InvalidNonce, NotSupported, BadRequest, AuthenticationError, BadSymbol, RateLimitExceeded, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -45,6 +46,7 @@ module.exports = class kucoin extends Exchange { 'fetchTrades': true, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg', @@ -52,6 +54,7 @@ module.exports = class kucoin extends Exchange { 'api': { 'public': 'https://openapi-v2.kucoin.com', 'private': 'https://openapi-v2.kucoin.com', + 'futuresPrivate': 'https://api-futures.kucoin.com', }, 'test': { 'public': 'https://openapi-sandbox.kucoin.com', @@ -160,6 +163,15 @@ module.exports = class kucoin extends Exchange { 'stop-order/cancel', ], }, + 'futuresPrivate': { + 'get': [ + 'account-overview', + 'positions', + ], + 'post': [ + 'transfer-out', + ], + }, }, 'timeframes': { '1m': '1min', @@ -184,6 +196,7 @@ module.exports = class kucoin extends Exchange { 'order_not_exist_or_not_allow_to_cancel': InvalidOrder, // {"code":"400100","msg":"order_not_exist_or_not_allow_to_cancel"} 'Order size below the minimum requirement.': InvalidOrder, // {"code":"400100","msg":"Order size below the minimum requirement."} 'The withdrawal amount is below the minimum requirement.': ExchangeError, // {"code":"400100","msg":"The withdrawal amount is below the minimum requirement."} + 'Unsuccessful! Exceeded the max. funds out-transfer limit': InsufficientFunds, // {"code":"200000","msg":"Unsuccessful! Exceeded the max. funds out-transfer limit"} '400': BadRequest, '401': AuthenticationError, '403': NotSupported, @@ -240,9 +253,7 @@ module.exports = class kucoin extends Exchange { 'version': 'v1', 'symbolSeparator': '-', 'fetchMyTradesMethod': 'private_get_fills', - 'fetchBalance': { - 'type': 'trade', // or 'main' - }, + 'fetchBalance': 'trade', // endpoint versions 'versions': { 'public': { @@ -262,6 +273,25 @@ module.exports = class kucoin extends Exchange { 'accounts/sub-transfer': 'v2', }, }, + 'futuresPrivate': { + 'GET': { + 'account-overview': 'v1', + 'positions': 'v1', + }, + 'POST': { + 'transfer-out': 'v2', + }, + }, + }, + 'accountsByType': { + 'trade': 'trade', + 'trading': 'trade', + 'margin': 'margin', + 'main': 'main', + 'futures': 'contract', + 'contract': 'contract', + 'pool': 'pool', + 'pool-x': 'pool', }, }, }); @@ -342,11 +372,11 @@ module.exports = class kucoin extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const active = this.safeValue (market, 'enableTrading'); - const baseMaxSize = this.safeFloat (market, 'baseMaxSize'); - const baseMinSize = this.safeFloat (market, 'baseMinSize'); - const quoteMaxSize = this.safeFloat (market, 'quoteMaxSize'); - const quoteMinSize = this.safeFloat (market, 'quoteMinSize'); - // const quoteIncrement = this.safeFloat (market, 'quoteIncrement'); + const baseMaxSize = this.safeNumber (market, 'baseMaxSize'); + const baseMinSize = this.safeNumber (market, 'baseMinSize'); + const quoteMaxSize = this.safeNumber (market, 'quoteMaxSize'); + const quoteMinSize = this.safeNumber (market, 'quoteMinSize'); + // const quoteIncrement = this.safeNumber (market, 'quoteIncrement'); const precision = { 'amount': this.precisionFromString (this.safeString (market, 'baseIncrement')), 'price': this.precisionFromString (this.safeString (market, 'priceIncrement')), @@ -357,7 +387,7 @@ module.exports = class kucoin extends Exchange { 'max': baseMaxSize, }, 'price': { - 'min': this.safeFloat (market, 'priceIncrement'), + 'min': this.safeNumber (market, 'priceIncrement'), 'max': quoteMaxSize / baseMinSize, }, 'cost': { @@ -408,7 +438,7 @@ module.exports = class kucoin extends Exchange { const precision = this.safeInteger (entry, 'precision'); const isWithdrawEnabled = this.safeValue (entry, 'isWithdrawEnabled', false); const isDepositEnabled = this.safeValue (entry, 'isDepositEnabled', false); - const fee = this.safeFloat (entry, 'withdrawalMinFee'); + const fee = this.safeNumber (entry, 'withdrawalMinFee'); const active = (isWithdrawEnabled && isDepositEnabled); result[code] = { 'id': id, @@ -475,7 +505,7 @@ module.exports = class kucoin extends Exchange { const response = await this.privateGetWithdrawalsQuotas (this.extend (request, params)); const data = response['data']; const withdrawFees = {}; - withdrawFees[code] = this.safeFloat (data, 'withdrawMinFee'); + withdrawFees[code] = this.safeNumber (data, 'withdrawMinFee'); return { 'info': response, 'withdraw': withdrawFees, @@ -522,35 +552,35 @@ module.exports = class kucoin extends Exchange { // "mark": 0 // } // - let percentage = this.safeFloat (ticker, 'changeRate'); + let percentage = this.safeNumber (ticker, 'changeRate'); if (percentage !== undefined) { percentage = percentage * 100; } - const last = this.safeFloat2 (ticker, 'last', 'lastTradedPrice'); + const last = this.safeNumber2 (ticker, 'last', 'lastTradedPrice'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'vol'); - const quoteVolume = this.safeFloat (ticker, 'volValue'); + const baseVolume = this.safeNumber (ticker, 'vol'); + const quoteVolume = this.safeNumber (ticker, 'volValue'); const vwap = this.vwap (baseVolume, quoteVolume); const timestamp = this.safeInteger2 (ticker, 'time', 'datetime'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'changePrice'), + 'change': this.safeNumber (ticker, 'changePrice'), 'percentage': percentage, - 'average': this.safeFloat (ticker, 'averagePrice'), + 'average': this.safeNumber (ticker, 'averagePrice'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -634,11 +664,11 @@ module.exports = class kucoin extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -836,16 +866,18 @@ module.exports = class kucoin extends Exchange { // 'marginMode': 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned // 'autoBorrow': false, // The system will first borrow you funds at the optimal interest rate and then place an order for you }; - if (type !== 'market') { - request['price'] = this.priceToPrecision (symbol, price); - request['size'] = this.amountToPrecision (symbol, amount); - } else { - if (this.safeValue (params, 'quoteAmount')) { - // used to create market order by quote amount - https://github.com/ccxt/ccxt/issues/4876 - request['funds'] = this.amountToPrecision (symbol, amount); + const quoteAmount = this.safeNumber2 (params, 'cost', 'funds'); + if (type === 'market') { + if (quoteAmount !== undefined) { + params = this.omit (params, [ 'cost', 'funds' ]); + // kucoin uses base precision even for quote values + request['funds'] = this.amountToPrecision (symbol, quoteAmount); } else { request['size'] = this.amountToPrecision (symbol, amount); } + } else { + request['price'] = this.priceToPrecision (symbol, price); + request['size'] = this.amountToPrecision (symbol, amount); } const response = await this.privatePostOrders (this.extend (request, params)); // @@ -879,8 +911,10 @@ module.exports = class kucoin extends Exchange { 'fee': undefined, 'trades': undefined, }; - if (!this.safeValue (params, 'quoteAmount')) { + if (quoteAmount === undefined) { order['amount'] = amount; + } else { + order['cost'] = quoteAmount; } return order; } @@ -1056,15 +1090,18 @@ module.exports = class kucoin extends Exchange { const type = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'createdAt'); const datetime = this.iso8601 (timestamp); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); + if (price === 0.0) { + // market orders + price = undefined; + } const side = this.safeString (order, 'side'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (order, 'fee'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'dealSize'); - const cost = this.safeFloat (order, 'dealFunds'); - const remaining = amount - filled; + const feeCost = this.safeNumber (order, 'fee'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'dealSize'); + const cost = this.safeNumber (order, 'dealFunds'); // bool const isActive = this.safeValue (order, 'isActive', false); const cancelExist = this.safeValue (order, 'cancelExist', false); @@ -1074,20 +1111,11 @@ module.exports = class kucoin extends Exchange { 'currency': feeCurrency, 'cost': feeCost, }; - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const clientOrderId = this.safeString (order, 'clientOid'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': orderId, 'clientOrderId': clientOrderId, 'symbol': symbol, @@ -1100,7 +1128,7 @@ module.exports = class kucoin extends Exchange { 'stopPrice': stopPrice, 'cost': cost, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'timestamp': timestamp, 'datetime': datetime, 'fee': fee, @@ -1109,7 +1137,7 @@ module.exports = class kucoin extends Exchange { 'lastTradeTimestamp': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1310,7 +1338,6 @@ module.exports = class kucoin extends Exchange { const id = this.safeString2 (trade, 'tradeId', 'id'); const orderId = this.safeString (trade, 'orderId'); const takerOrMaker = this.safeString (trade, 'liquidity'); - const amount = this.safeFloat2 (trade, 'size', 'amount'); let timestamp = this.safeInteger (trade, 'time'); if (timestamp !== undefined) { timestamp = parseInt (timestamp / 1000000); @@ -1321,10 +1348,13 @@ module.exports = class kucoin extends Exchange { timestamp = timestamp * 1000; } } - const price = this.safeFloat2 (trade, 'price', 'dealPrice'); + const priceString = this.safeString2 (trade, 'price', 'dealPrice'); + const amountString = this.safeString2 (trade, 'size', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const side = this.safeString (trade, 'side'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); let feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -1336,20 +1366,16 @@ module.exports = class kucoin extends Exchange { fee = { 'cost': feeCost, 'currency': feeCurrency, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } let type = this.safeString (trade, 'type'); if (type === 'match') { type = undefined; } - let cost = this.safeFloat2 (trade, 'funds', 'dealValue'); + let cost = this.safeNumber2 (trade, 'funds', 'dealValue'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'info': trade, @@ -1445,7 +1471,7 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); let address = this.safeString (transaction, 'address'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let txid = this.safeString (transaction, 'walletTxId'); if (txid !== undefined) { const txidParts = txid.split ('@'); @@ -1463,7 +1489,7 @@ module.exports = class kucoin extends Exchange { const rawStatus = this.safeString (transaction, 'status'); const status = this.parseTransactionStatus (rawStatus); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { let rate = undefined; if (amount !== undefined) { @@ -1644,45 +1670,180 @@ module.exports = class kucoin extends Exchange { async fetchBalance (params = {}) { await this.loadMarkets (); - let type = undefined; - const request = {}; - if ('type' in params) { - type = params['type']; - if (type !== undefined) { - request['type'] = type; - } - params = this.omit (params, 'type'); + const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'trade'); + const requestedType = this.safeString (params, 'type', defaultType); + const accountsByType = this.safeValue (this.options, 'accountsByType'); + const type = this.safeString (accountsByType, requestedType); + if (type === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' type must be one of ' + keys.join (', ')); + } + params = this.omit (params, 'type'); + if (type === 'contract') { + // futures api requires a futures apiKey + // only fetches one balance at a time + // by default it will only fetch the BTC balance of the futures account + // you can send 'currency' in params to fetch other currencies + // fetchBalance ({ 'type': 'futures', 'currency': 'USDT' }) + const response = await this.futuresPrivateGetAccountOverview (params); + // + // { + // code: '200000', + // data: { + // accountEquity: 0.00005, + // unrealisedPNL: 0, + // marginBalance: 0.00005, + // positionMargin: 0, + // orderMargin: 0, + // frozenFunds: 0, + // availableBalance: 0.00005, + // currency: 'XBT' + // } + // } + // + const data = this.safeValue (response, 'data'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (data, 'availableBalance'); + account['total'] = this.safeString (data, 'accountEquity'); + const result = { 'info': response }; + result[code] = account; + return this.parseBalance (result, false); } else { - const options = this.safeValue (this.options, 'fetchBalance', {}); - type = this.safeString (options, 'type', 'trade'); - } - const response = await this.privateGetAccounts (this.extend (request, params)); - // - // { - // "code":"200000", - // "data":[ - // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, - // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, - // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - const result = { 'info': response }; - for (let i = 0; i < data.length; i++) { - const balance = data[i]; - const balanceType = this.safeString (balance, 'type'); - if (balanceType === type) { - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'holds'); - result[code] = account; + const request = { + 'type': type, + }; + const response = await this.privateGetAccounts (this.extend (request, params)); + // + // { + // "code":"200000", + // "data":[ + // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, + // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, + // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + const result = { 'info': response }; + for (let i = 0; i < data.length; i++) { + const balance = data[i]; + const balanceType = this.safeString (balance, 'type'); + if (balanceType === type) { + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'holds'); + result[code] = account; + } } + return this.parseBalance (result, false); + } + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const requestedAmount = this.currencyToPrecision (code, amount); + const accountsById = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsById, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsById, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + if (fromId === 'contract') { + if (toId !== 'main') { + throw new ExchangeError (this.id + ' only supports transferring from futures account to main account'); + } + const request = { + 'currency': currency['id'], + 'amount': requestedAmount, + }; + if (!('bizNo' in params)) { + // it doesn't like more than 24 characters + request['bizNo'] = this.uuid22 (); + } + const response = await this.futuresPrivatePostTransferOut (this.extend (request, params)); + // + // { + // code: '200000', + // data: { + // applyId: '605a87217dff1500063d485d', + // bizNo: 'bcd6e5e1291f4905af84dc', + // payAccountType: 'CONTRACT', + // payTag: 'DEFAULT', + // remark: '', + // recAccountType: 'MAIN', + // recTag: 'DEFAULT', + // recRemark: '', + // recSystem: 'KUCOIN', + // status: 'PROCESSING', + // currency: 'XBT', + // amount: '0.00001', + // fee: '0', + // sn: '573688685663948', + // reason: '', + // createdAt: 1616545569000, + // updatedAt: 1616545569000 + // } + // } + // + const data = this.safeValue (response, 'data'); + const timestamp = this.safeInteger (data, 'createdAt'); + const id = this.safeString (data, 'applyId'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const amount = this.safeNumber (data, 'amount'); + const rawStatus = this.safeString (data, 'status'); + let status = undefined; + if (rawStatus === 'PROCESSING') { + status = 'pending'; + } + return { + 'info': response, + 'currency': code, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'amount': amount, + 'fromAccount': fromId, + 'toAccount': toId, + 'id': id, + 'status': status, + }; + } else { + const request = { + 'currency': currency['id'], + 'from': fromId, + 'to': toId, + 'amount': requestedAmount, + }; + if (!('clientOid' in params)) { + request['clientOid'] = this.uuid (); + } + const response = await this.privatePostAccountsInnerTransfer (this.extend (request, params)); + // { code: '200000', data: { orderId: '605a6211e657f00006ad0ad6' } } + const data = this.safeValue (response, 'data'); + const id = this.safeString (data, 'orderId'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'currency': code, + 'amount': requestedAmount, + 'fromAccount': fromId, + 'toAccount': toId, + 'status': undefined, + }; } - return this.parseBalance (result); } async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -1770,11 +1931,11 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'code': code, }; - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'balance'); const direction = this.safeString (item, 'direction'); let before = undefined; if (after !== undefined && amount !== undefined) { @@ -1824,6 +1985,94 @@ module.exports = class kucoin extends Exchange { return this.safeString (types, type, type); } + async fetchPositions (symbols = undefined, params = {}) { + const response = await this.futuresPrivateGetPositions (params); + // + // { + // code: '200000', + // data: [ + // { + // id: '605a9772a229ab0006408258', + // symbol: 'XBTUSDTM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746099, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54371.92, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'USDT', + // isInverse: false + // }, + // { + // id: '605a9772026ac900066550df', + // symbol: 'XBTUSDM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746110, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54354.76, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'XBT', + // isInverse: true + // } + // ] + // } + // + return this.safeValue (response, 'data', response); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { // // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint @@ -1840,16 +2089,16 @@ module.exports = class kucoin extends Exchange { let endpart = ''; headers = (headers !== undefined) ? headers : {}; if (Object.keys (query).length) { - if (method !== 'GET') { + if ((method === 'GET') || (method === 'DELETE')) { + endpoint += '?' + this.urlencode (query); + } else { body = this.json (query); endpart = body; headers['Content-Type'] = 'application/json'; - } else { - endpoint += '?' + this.urlencode (query); } } const url = this.urls['api'][api] + endpoint; - if (api === 'private') { + if ((api === 'private') || (api === 'futuresPrivate')) { this.checkRequiredCredentials (); const timestamp = this.nonce ().toString (); headers = this.extend ({ @@ -1892,8 +2141,8 @@ module.exports = class kucoin extends Exchange { // { code: '200000', data: { ... }} // const errorCode = this.safeString (response, 'code'); - const message = this.safeString (response, 'msg'); - this.throwExactlyMatchedException (this.exceptions['exact'], message, message); - this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, message); + const message = this.safeString (response, 'msg', ''); + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, this.id + ' ' + message); } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kuna.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kuna.js index e652171d1..0067e406f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kuna.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/kuna.js @@ -2,12 +2,13 @@ // --------------------------------------------------------------------------- -const acx = require ('./acx.js'); -const { ArgumentsRequired } = require ('./base/errors'); +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, InsufficientFunds, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class kuna extends acx { +module.exports = class kuna extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'kuna', @@ -17,14 +18,24 @@ module.exports = class kuna extends acx { 'version': 'v2', 'has': { 'CORS': false, - 'fetchTickers': true, + 'cancelOrder': true, + 'createOrder': true, + 'fetchBalance': true, + 'fetchMarkets': true, + 'fetchMyTrades': true, 'fetchOHLCV': 'emulated', 'fetchOpenOrders': true, - 'fetchMyTrades': true, + 'fetchOrder': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchTime': true, + 'fetchTrades': true, 'withdraw': false, }, 'timeframes': undefined, 'urls': { + 'extension': '.json', 'referral': 'https://kuna.io?r=kunaid-gvfihe8az7o4', 'logo': 'https://user-images.githubusercontent.com/51840849/87153927-f0578b80-c2c0-11ea-84b6-74612568e9e1.jpg', 'api': 'https://kuna.io', @@ -32,8 +43,47 @@ module.exports = class kuna extends acx { 'doc': 'https://kuna.io/documents/api', 'fees': 'https://kuna.io/documents/api', }, + 'api': { + 'public': { + 'get': [ + 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. + 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator + 'k', // Get OHLC(k line) of specific market + 'markets', // Get all available markets + 'order_book', // Get the order book of specified market + 'order_book/{market}', + 'tickers', // Get ticker of all markets + 'tickers/{market}', // Get ticker of specific market + 'timestamp', // Get server current time, in seconds since Unix epoch + 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. + 'trades/{market}', + ], + }, + 'private': { + 'get': [ + 'members/me', // Get your profile and accounts info + 'deposits', // Get your deposits history + 'deposit', // Get details of specific deposit + 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. + 'orders', // Get your orders, results is paginated + 'order', // Get information of specified order + 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. + 'withdraws', // Get your cryptocurrency withdraws + 'withdraw', // Get your cryptocurrency withdraw + ], + 'post': [ + 'orders', // Create a Sell/Buy order + 'orders/multi', // Create multiple sell/buy orders + 'orders/clear', // Cancel all my orders + 'order/delete', // Cancel an order + 'withdraw', // Create a withdraw + ], + }, + }, 'fees': { 'trading': { + 'tierBased': false, + 'percentage': true, 'taker': 0.25 / 100, 'maker': 0.25 / 100, }, @@ -56,9 +106,24 @@ module.exports = class kuna extends acx { }, }, }, + 'commonCurrencies': { + 'PLA': 'Plair', + }, + 'exceptions': { + '2002': InsufficientFunds, + '2003': OrderNotFound, + }, }); } + async fetchTime (params = {}) { + const response = await this.publicGetTimestamp (params); + // + // 1594911427 + // + return response * 1000; + } + async fetchMarkets (params = {}) { const quotes = [ 'btc', 'eth', 'eurs', 'rub', 'uah', 'usd', 'usdt', 'gol' ]; const pricePrecisions = { @@ -114,24 +179,100 @@ module.exports = class kuna extends acx { return markets; } - async fetchL3OrderBook (symbol, limit = undefined, params = {}) { - return await this.fetchOrderBook (symbol, limit, params); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); - } + async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; - const response = await this.privateGetOrders (this.extend (request, params)); - // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder - // with order cache + fetchOpenOrders - // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX - return this.parseOrders (response, market, since, limit); + if (limit !== undefined) { + request['limit'] = limit; // default = 300 + } + const orderbook = await this.publicGetDepth (this.extend (request, params)); + const timestamp = this.safeTimestamp (orderbook, 'timestamp'); + return this.parseOrderBook (orderbook, timestamp); + } + + parseTicker (ticker, market = undefined) { + const timestamp = this.safeTimestamp (ticker, 'at'); + ticker = ticker['ticker']; + let symbol = undefined; + if (market) { + symbol = market['symbol']; + } + const last = this.safeNumber (ticker, 'last'); + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'bidVolume': undefined, + 'ask': this.safeNumber (ticker, 'sell'), + 'askVolume': undefined, + 'vwap': undefined, + 'open': this.safeNumber (ticker, 'open'), + 'close': last, + 'last': last, + 'previousClose': undefined, + 'change': undefined, + 'percentage': undefined, + 'average': undefined, + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const response = await this.publicGetTickers (params); + const ids = Object.keys (response); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + let market = undefined; + let symbol = id; + if (id in this.markets_by_id) { + market = this.markets_by_id[id]; + symbol = market['symbol']; + } else { + let base = id.slice (0, 3); + let quote = id.slice (3, 6); + base = base.toUpperCase (); + quote = quote.toUpperCase (); + base = this.safeCurrencyCode (base); + quote = this.safeCurrencyCode (quote); + symbol = base + '/' + quote; + } + result[symbol] = this.parseTicker (response[id], market); + } + return this.filterByArray (result, 'symbol', symbols); + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTickersMarket (this.extend (request, params)); + return this.parseTicker (response, market); + } + + async fetchL3OrderBook (symbol, limit = undefined, params = {}) { + return await this.fetchOrderBook (symbol, limit, params); + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTrades (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); } parseTrade (trade, market = undefined) { @@ -148,9 +289,14 @@ module.exports = class kuna extends acx { }; side = this.safeString (sideMap, side, side); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_id'); const id = this.safeString (trade, 'id'); return { @@ -170,29 +316,6 @@ module.exports = class kuna extends acx { }; } - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); - } - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.privateGetTradesMy (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const trades = await this.fetchTrades (symbol, since, limit, params); @@ -211,4 +334,198 @@ module.exports = class kuna extends acx { } return result; } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + const response = await this.privateGetMembersMe (params); + const balances = this.safeValue (response, 'accounts'); + const result = { 'info': balances }; + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'market': this.marketId (symbol), + 'side': side, + 'volume': amount.toString (), + 'ord_type': type, + }; + if (type === 'limit') { + request['price'] = price.toString (); + } + const response = await this.privatePostOrders (this.extend (request, params)); + const marketId = this.safeValue (response, 'market'); + const market = this.safeValue (this.markets_by_id, marketId); + return this.parseOrder (response, market); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': id, + }; + const response = await this.privatePostOrderDelete (this.extend (request, params)); + const order = this.parseOrder (response); + const status = order['status']; + if (status === 'closed' || status === 'canceled') { + throw new OrderNotFound (this.id + ' ' + this.json (order)); + } + return order; + } + + parseOrderStatus (status) { + const statuses = { + 'done': 'closed', + 'wait': 'open', + 'cancel': 'canceled', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + const marketId = this.safeString (order, 'market'); + const symbol = this.safeSymbol (marketId, market); + const timestamp = this.parse8601 (this.safeString (order, 'created_at')); + const status = this.parseOrderStatus (this.safeString (order, 'state')); + const type = this.safeString (order, 'type'); + const side = this.safeString (order, 'side'); + const id = this.safeString (order, 'id'); + return this.safeOrder ({ + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': undefined, + 'status': status, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': this.safeNumber (order, 'price'), + 'stopPrice': undefined, + 'amount': this.safeNumber (order, 'volume'), + 'filled': this.safeNumber (order, 'executed_volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'trades': undefined, + 'fee': undefined, + 'info': order, + 'cost': undefined, + 'average': undefined, + }); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': parseInt (id), + }; + const response = await this.privateGetOrder (this.extend (request, params)); + return this.parseOrder (response); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetOrders (this.extend (request, params)); + // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder + // with order cache + fetchOpenOrders + // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX + return this.parseOrders (response, market, since, limit); + } + + async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetTradesMy (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); + } + + nonce () { + return this.milliseconds (); + } + + encodeParams (params) { + if ('orders' in params) { + const orders = params['orders']; + let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); + for (let i = 0; i < orders.length; i++) { + const order = orders[i]; + const keys = Object.keys (order); + for (let k = 0; k < keys.length; k++) { + const key = keys[k]; + const value = order[key]; + query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); + } + } + return query; + } + return this.urlencode (this.keysort (params)); + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let request = '/api/' + this.version + '/' + this.implodeParams (path, params); + if ('extension' in this.urls) { + request += this.urls['extension']; + } + const query = this.omit (params, this.extractParams (path)); + let url = this.urls['api'] + request; + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const nonce = this.nonce ().toString (); + const query = this.encodeParams (this.extend ({ + 'access_key': this.apiKey, + 'tonce': nonce, + }, params)); + const auth = method + '|' + request + '|' + query; + const signed = this.hmac (this.encode (auth), this.encode (this.secret)); + const suffix = query + '&signature=' + signed; + if (method === 'GET') { + url += '?' + suffix; + } else { + body = suffix; + headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; + } + } + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; + } + if (code === 400) { + const error = this.safeValue (response, 'error'); + const errorCode = this.safeString (error, 'code'); + const feedback = this.id + ' ' + this.json (response); + this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); + // fallback to default error handler + } + } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lakebtc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lakebtc.js index 8acd8cc41..991e6ff86 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lakebtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lakebtc.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, BadSymbol, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -112,10 +113,10 @@ module.exports = class lakebtc extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -133,16 +134,16 @@ module.exports = class lakebtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -152,7 +153,7 @@ module.exports = class lakebtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -183,14 +184,11 @@ module.exports = class lakebtc extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/latoken.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/latoken.js index 45cb5951d..ecc53a8c6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/latoken.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/latoken.js @@ -4,7 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, DDoSProtection, BadRequest, AuthenticationError } = require ('./base/errors'); -const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -85,6 +85,7 @@ module.exports = class latoken extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.1 / 100, @@ -169,7 +170,7 @@ module.exports = class latoken extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minQty'), + 'min': this.safeNumber (market, 'minQty'), 'max': undefined, }, 'price': { @@ -219,7 +220,7 @@ module.exports = class latoken extends Exchange { const numericId = this.safeInteger (currency, 'currencyId'); const code = this.safeCurrencyCode (id); const precision = this.safeInteger (currency, 'precission'); - const fee = this.safeFloat (currency, 'fee'); + const fee = this.safeNumber (currency, 'fee'); const active = undefined; result[code] = { 'id': id, @@ -253,27 +254,6 @@ module.exports = class latoken extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privateGetAccountBalances (params); @@ -297,17 +277,15 @@ module.exports = class latoken extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const frozen = this.safeFloat (balance, 'frozen'); - const pending = this.safeFloat (balance, 'pending'); - const used = this.sum (frozen, pending); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': used, - 'total': this.safeFloat (balance, 'amount'), - }; + const frozen = this.safeString (balance, 'frozen'); + const pending = this.safeString (balance, 'pending'); + const account = this.account (); + account['used'] = Precise.stringAdd (frozen, pending); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -352,20 +330,20 @@ module.exports = class latoken extends Exchange { // const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; if (open !== undefined && close !== undefined) { change = close - open; } - const percentage = this.safeFloat (ticker, 'priceChange'); + const percentage = this.safeNumber (ticker, 'priceChange'); const timestamp = this.nonce (); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'low': this.safeFloat (ticker, 'low'), - 'high': this.safeFloat (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -379,7 +357,7 @@ module.exports = class latoken extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -463,22 +441,19 @@ module.exports = class latoken extends Exchange { timestamp *= 1000; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'orderId'); - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -613,29 +588,17 @@ module.exports = class latoken extends Exchange { const symbol = this.safeSymbol (marketId, market); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executedAmount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executedAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderStatus')); - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const timeFilled = this.safeTimestamp (order, 'timeFilled'); let lastTradeTimestamp = undefined; if ((timeFilled !== undefined) && (timeFilled > 0)) { lastTradeTimestamp = timeFilled; } const clientOrderId = this.safeString (order, 'cliOrdId'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -650,14 +613,14 @@ module.exports = class latoken extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'average': undefined, - 'remaining': remaining, + 'remaining': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lbank.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lbank.js index 9b39a0236..e9e4658dc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lbank.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lbank.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, DDoSProtection, AuthenticationError, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -201,8 +202,8 @@ module.exports = class lbank extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const info = ticker; ticker = info['ticker']; - const last = this.safeFloat (ticker, 'latest'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'latest'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; if (percentage !== undefined) { const relativeChange = this.sum (1, percentage / 100); @@ -223,8 +224,8 @@ module.exports = class lbank extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -237,8 +238,8 @@ module.exports = class lbank extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'turnover'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'turnover'), 'info': info, }; } @@ -288,17 +289,15 @@ module.exports = class lbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (trade, 'date_ms'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'tid'); const type = undefined; - const side = this.safeString (trade, 'type'); + let side = this.safeString (trade, 'type'); + side = side.replace ('_market', ''); return { 'id': id, 'info': this.safeValue (trade, 'info', trade), @@ -346,11 +345,11 @@ module.exports = class lbank extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -415,12 +414,12 @@ module.exports = class lbank extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (freeze, currencyId); - account['total'] = this.safeFloat (asset, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (freeze, currencyId); + account['total'] = this.safeString (asset, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -448,35 +447,20 @@ module.exports = class lbank extends Exchange { // "status":2 // } // - let symbol = undefined; - const responseMarket = this.safeValue (this.marketsById, order['symbol']); - if (responseMarket !== undefined) { - symbol = responseMarket['symbol']; - } else if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeInteger (order, 'create_time'); // Limit Order Request Returns: Order Price // Market Order Returns: cny amount of market order - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount', 0.0); - const filled = this.safeFloat (order, 'deal_amount', 0.0); - const av_price = this.safeFloat (order, 'avg_price'); - let cost = undefined; - if (av_price !== undefined) { - cost = filled * av_price; - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount', 0.0); + const filled = this.safeNumber (order, 'deal_amount', 0.0); + const average = this.safeNumber (order, 'avg_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'order_id'); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -490,15 +474,15 @@ module.exports = class lbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': this.safeValue (order, 'info', order), - 'average': undefined, - }; + 'average': average, + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/liquid.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/liquid.js index 732eda853..0365ef102 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/liquid.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/liquid.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported } = require ('./base/errors'); +const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -108,7 +109,7 @@ module.exports = class liquid extends Exchange { 'trading': { 'tierBased': true, 'percentage': true, - 'taker': 0.0015, + 'taker': 0.0030, 'maker': 0.0000, 'tiers': { 'perpetual': { @@ -127,48 +128,52 @@ module.exports = class liquid extends Exchange { [ 300000000, -0.00025 ], ], 'taker': [ - [ 0, 0.000600 ], - [ 25000, 0.000575 ], - [ 50000, 0.000550 ], - [ 100000, 0.000525 ], - [ 1000000, 0.000500 ], - [ 10000000, 0.000475 ], - [ 25000000, 0.000450 ], - [ 50000000, 0.000425 ], - [ 75000000, 0.000400 ], - [ 100000000, 0.000375 ], - [ 200000000, 0.000350 ], - [ 300000000, 0.000325 ], + [ 0, 0.00120 ], + [ 25000, 0.00115 ], + [ 50000, 0.00110 ], + [ 100000, 0.00105 ], + [ 1000000, 0.00100 ], + [ 10000000, 0.00095 ], + [ 25000000, 0.00090 ], + [ 50000000, 0.00085 ], + [ 75000000, 0.00080 ], + [ 100000000, 0.00075 ], + [ 200000000, 0.00070 ], + [ 300000000, 0.00065 ], ], }, 'spot': { 'taker': [ - [ 0, 0.0015 ], - [ 10000, 0.0015 ], - [ 20000, 0.0014 ], - [ 50000, 0.0013 ], - [ 100000, 0.0010 ], - [ 1000000, 0.0008 ], - [ 5000000, 0.0006 ], - [ 10000000, 0.0005 ], - [ 25000000, 0.0005 ], - [ 50000000, 0.00045 ], - [ 100000000, 0.0004 ], - [ 200000000, 0.0003 ], + [ 0, 0.003 ], + [ 10000, 0.0029 ], + [ 20000, 0.0028 ], + [ 50000, 0.0026 ], + [ 100000, 0.0020 ], + [ 1000000, 0.0016 ], + [ 5000000, 0.0012 ], + [ 10000000, 0.0010 ], + [ 25000000, 0.0009 ], + [ 50000000, 0.0008 ], + [ 100000000, 0.0007 ], + [ 200000000, 0.0006 ], + [ 500000000, 0.0004 ], + [ 1000000000, 0.0003 ], ], 'maker': [ [ 0, 0.0000 ], - [ 10000, 0.0015 ], - [ 20000, 0.1400 ], - [ 50000, 0.1300 ], - [ 100000, 0.0800 ], - [ 1000000, 0.0004 ], - [ 5000000, 0.00035 ], - [ 10000000, 0.00025 ], + [ 10000, 0.0020 ], + [ 20000, 0.0019 ], + [ 50000, 0.0018 ], + [ 100000, 0.0016 ], + [ 1000000, 0.0008 ], + [ 5000000, 0.0007 ], + [ 10000000, 0.0005 ], [ 25000000, 0.0000 ], [ 50000000, 0.0000 ], [ 100000000, 0.0000 ], [ 200000000, 0.0000 ], + [ 500000000, 0.0000 ], + [ 1000000000, 0.0000 ], ], }, }, @@ -187,6 +192,7 @@ module.exports = class liquid extends Exchange { 'less_than_order_size': InvalidOrder, 'price_too_high': InvalidOrder, 'price_too_small': InvalidOrder, // {"errors":{"order":["price_too_small"]}} + 'product_disabled': BadSymbol, // {"errors":{"order":["product_disabled"]}} }, 'commonCurrencies': { 'WIN': 'WCOIN', @@ -236,7 +242,7 @@ module.exports = class liquid extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': decimalPrecision, 'limits': { 'amount': { @@ -252,7 +258,7 @@ module.exports = class liquid extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal'), + 'min': this.safeNumber (currency, 'minimum_withdrawal'), 'max': undefined, }, }, @@ -377,19 +383,19 @@ module.exports = class liquid extends Exchange { let maker = this.fees['trading']['maker']; let taker = this.fees['trading']['taker']; if (type === 'swap') { - maker = this.safeFloat (market, 'maker_fee', this.fees['trading']['maker']); - taker = this.safeFloat (market, 'taker_fee', this.fees['trading']['taker']); + maker = this.safeNumber (market, 'maker_fee', this.fees['trading']['maker']); + taker = this.safeNumber (market, 'taker_fee', this.fees['trading']['taker']); } const disabled = this.safeValue (market, 'disabled', false); const active = !disabled; const baseCurrency = this.safeValue (currenciesByCode, base); const precision = { 'amount': 0.00000001, - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; let minAmount = undefined; if (baseCurrency !== undefined) { - minAmount = this.safeFloat (baseCurrency['info'], 'minimum_order_quantity'); + minAmount = this.safeNumber (baseCurrency['info'], 'minimum_order_quantity'); } const limits = { 'amount': { @@ -471,8 +477,8 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } for (let i = 0; i < fiat.length; i++) { @@ -480,11 +486,11 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -503,7 +509,7 @@ module.exports = class liquid extends Exchange { if (ticker['last_traded_price']) { const length = ticker['last_traded_price'].length; if (length > 0) { - last = this.safeFloat (ticker, 'last_traded_price'); + last = this.safeNumber (ticker, 'last_traded_price'); } } } @@ -528,7 +534,7 @@ module.exports = class liquid extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'last_price_24h'); + const open = this.safeNumber (ticker, 'last_price_24h'); if (open !== undefined && last !== undefined) { change = last - open; average = this.sum (last, open) / 2; @@ -540,11 +546,11 @@ module.exports = class liquid extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_market_ask'), - 'low': this.safeFloat (ticker, 'low_market_bid'), - 'bid': this.safeFloat (ticker, 'market_bid'), + 'high': this.safeNumber (ticker, 'high_market_ask'), + 'low': this.safeNumber (ticker, 'low_market_bid'), + 'bid': this.safeNumber (ticker, 'market_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'market_ask'), + 'ask': this.safeNumber (ticker, 'market_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -554,7 +560,7 @@ module.exports = class liquid extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'volume_24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -600,14 +606,11 @@ module.exports = class liquid extends Exchange { if (mySide !== undefined) { takerOrMaker = (takerSide === mySide) ? 'taker' : 'maker'; } - let cost = undefined; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -810,9 +813,9 @@ module.exports = class liquid extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeValue (this.markets_by_id, marketId); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'filled_quantity'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + let filled = this.safeNumber (order, 'filled_quantity'); + const price = this.safeNumber (order, 'price'); let symbol = undefined; let feeCurrency = undefined; if (market !== undefined) { @@ -822,7 +825,7 @@ module.exports = class liquid extends Exchange { const type = this.safeString (order, 'order_type'); let tradeCost = 0; let tradeFilled = 0; - let average = this.safeFloat (order, 'average_price'); + let average = this.safeNumber (order, 'average_price'); const trades = this.parseTrades (this.safeValue (order, 'executions', []), market, undefined, undefined, { 'order': orderId, 'type': type, @@ -879,7 +882,7 @@ module.exports = class liquid extends Exchange { 'trades': trades, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'order_fee'), + 'cost': this.safeNumber (order, 'order_fee'), }, 'info': order, }; @@ -1034,7 +1037,7 @@ module.exports = class liquid extends Exchange { const updated = this.safeTimestamp (transaction, 'updated_at'); const type = 'withdrawal'; const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/luno.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/luno.js index 2bbec0ec1..ad5568218 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/luno.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/luno.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -79,6 +80,10 @@ module.exports = class luno extends Exchange { 'quotes/{id}', 'withdrawals', 'withdrawals/{id}', + 'transfers', + // GET /api/exchange/2/listorders + // GET /api/exchange/2/orders/{id} + // GET /api/exchange/3/order ], 'post': [ 'accounts', @@ -153,12 +158,12 @@ module.exports = class luno extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), - 'max': this.safeFloat (market, 'max_volume'), + 'min': this.safeNumber (market, 'min_volume'), + 'max': this.safeNumber (market, 'max_volume'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -209,20 +214,22 @@ module.exports = class luno extends Exchange { const wallet = wallets[i]; const currencyId = this.safeString (wallet, 'asset'); const code = this.safeCurrencyCode (currencyId); - const reserved = this.safeFloat (wallet, 'reserved'); - const unconfirmed = this.safeFloat (wallet, 'unconfirmed'); - const balance = this.safeFloat (wallet, 'balance'); + const reserved = this.safeString (wallet, 'reserved'); + const unconfirmed = this.safeString (wallet, 'unconfirmed'); + const balance = this.safeString (wallet, 'balance'); + const reservedUnconfirmed = Precise.stringAdd (reserved, unconfirmed); + const balanceUnconfirmed = Precise.stringAdd (balance, unconfirmed); if (code in result) { - result[code]['used'] = this.sum (result[code]['used'], reserved, unconfirmed); - result[code]['total'] = this.sum (result[code]['total'], balance, unconfirmed); + result[code]['used'] = Precise.stringAdd (result[code]['used'], reservedUnconfirmed); + result[code]['total'] = Precise.stringAdd (result[code]['total'], balanceUnconfirmed); } else { const account = this.account (); - account['used'] = this.sum (reserved, unconfirmed); - account['total'] = this.sum (balance, unconfirmed); + account['used'] = reservedUnconfirmed; + account['total'] = balanceUnconfirmed; result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -273,18 +280,12 @@ module.exports = class luno extends Exchange { const side = (order['type'] === 'ASK') ? 'sell' : 'buy'; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'limit_volume'); - const quoteFee = this.safeFloat (order, 'fee_counter'); - const baseFee = this.safeFloat (order, 'fee_base'); - const filled = this.safeFloat (order, 'base'); - const cost = this.safeFloat (order, 'counter'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'limit_volume'); + const quoteFee = this.safeNumber (order, 'fee_counter'); + const baseFee = this.safeNumber (order, 'fee_base'); + const filled = this.safeNumber (order, 'base'); + const cost = this.safeNumber (order, 'counter'); const fee = { 'currency': undefined }; if (quoteFee) { fee['cost'] = quoteFee; @@ -298,7 +299,7 @@ module.exports = class luno extends Exchange { } } const id = this.safeString (order, 'order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -315,12 +316,12 @@ module.exports = class luno extends Exchange { 'amount': amount, 'filled': filled, 'cost': cost, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -366,16 +367,16 @@ module.exports = class luno extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -385,7 +386,7 @@ module.exports = class luno extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'rolling_24_hour_volume'), + 'baseVolume': this.safeNumber (ticker, 'rolling_24_hour_volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -436,8 +437,8 @@ module.exports = class luno extends Exchange { } else { side = trade['is_buy'] ? 'buy' : 'sell'; } - const feeBase = this.safeFloat (trade, 'fee_base'); - const feeCounter = this.safeFloat (trade, 'fee_counter'); + const feeBase = this.safeNumber (trade, 'fee_base'); + const feeCounter = this.safeNumber (trade, 'fee_counter'); let feeCurrency = undefined; let feeCost = undefined; if (feeBase !== undefined) { @@ -462,10 +463,10 @@ module.exports = class luno extends Exchange { 'type': undefined, 'side': side, 'takerOrMaker': takerOrMaker, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), // Does not include potential fee costs - 'cost': this.safeFloat (trade, 'counter'), + 'cost': this.safeNumber (trade, 'counter'), 'fee': { 'cost': feeCost, 'currency': feeCurrency, @@ -512,8 +513,8 @@ module.exports = class luno extends Exchange { const response = await this.privateGetFeeInfo (params); return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } @@ -647,9 +648,9 @@ module.exports = class luno extends Exchange { const timestamp = this.safeValue (entry, 'timestamp'); const currencyId = this.safeString (entry, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - const available_delta = this.safeFloat (entry, 'available_delta'); - const balance_delta = this.safeFloat (entry, 'balance_delta'); - const after = this.safeFloat (entry, 'balance'); + const available_delta = this.safeNumber (entry, 'available_delta'); + const balance_delta = this.safeNumber (entry, 'balance_delta'); + const after = this.safeNumber (entry, 'balance'); const comment = this.safeString (entry, 'description'); let before = after; let amount = 0.0; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lykke.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lykke.js index edc0fe73a..707034d20 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lykke.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/lykke.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -184,18 +185,16 @@ module.exports = class lykke extends Exchange { const id = this.safeString2 (trade, 'id', 'Id'); const orderId = this.safeString (trade, 'OrderId'); const timestamp = this.parse8601 (this.safeString2 (trade, 'dateTime', 'DateTime')); - const price = this.safeFloat2 (trade, 'price', 'Price'); - let amount = this.safeFloat2 (trade, 'volume', 'Amount'); + const priceString = this.safeString2 (trade, 'price', 'Price'); + let amountString = this.safeString2 (trade, 'volume', 'Amount'); let side = this.safeStringLower (trade, 'action'); if (side === undefined) { - if (amount < 0) { - side = 'sell'; - } else { - side = 'buy'; - } + side = (amountString[0] === '-') ? 'sell' : 'buy'; } - amount = Math.abs (amount); - const cost = price * amount; + amountString = (amountString[0] === '-') ? amountString.slice (1) : amountString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = { 'cost': 0, // There are no fees for trading. https://www.lykke.com/wallet-fees-and-limits/ 'currency': market['quote'], @@ -256,11 +255,11 @@ module.exports = class lykke extends Exchange { const currencyId = this.safeString (balance, 'AssetId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Balance'); - account['used'] = this.safeFloat (balance, 'Reserved'); + account['total'] = this.safeString (balance, 'Balance'); + account['used'] = this.safeString (balance, 'Reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -307,7 +306,7 @@ module.exports = class lykke extends Exchange { // } // const id = this.safeString (result, 'Id'); - price = this.safeFloat (result, 'Price'); + price = this.safeNumber (result, 'Price'); return { 'id': id, 'info': result, @@ -398,16 +397,16 @@ module.exports = class lykke extends Exchange { if (market) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'lastPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -418,7 +417,7 @@ module.exports = class lykke extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume24H'), + 'quoteVolume': this.safeNumber (ticker, 'volume24H'), 'info': ticker, }; } @@ -476,20 +475,18 @@ module.exports = class lykke extends Exchange { } else if (('CreatedAt' in order) && (order['CreatedAt'])) { timestamp = this.parse8601 (order['CreatedAt']); } - const price = this.safeFloat (order, 'Price'); + const price = this.safeNumber (order, 'Price'); let side = undefined; - let amount = this.safeFloat (order, 'Volume'); + let amount = this.safeNumber (order, 'Volume'); if (amount < 0) { side = 'sell'; amount = Math.abs (amount); } else { side = 'buy'; } - const remaining = Math.abs (this.safeFloat (order, 'RemainingVolume')); - const filled = amount - remaining; - const cost = filled * price; + const remaining = Math.abs (this.safeNumber (order, 'RemainingVolume')); const id = this.safeString (order, 'Id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -503,15 +500,15 @@ module.exports = class lykke extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -572,8 +569,8 @@ module.exports = class lykke extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - let amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + let amount = this.safeNumber (bidask, amountKey); if (amount < 0) { amount = -amount; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mercado.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mercado.js index a2fd9593e..2746e14b8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mercado.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mercado.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -160,7 +161,7 @@ module.exports = class mercado extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, baseId), + 'min': this.safeNumber (amountLimits, baseId), 'max': undefined, }, 'price': { @@ -196,16 +197,16 @@ module.exports = class mercado extends Exchange { const response = await this.publicGetCoinTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'ticker', {}); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -215,7 +216,7 @@ module.exports = class mercado extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -230,15 +231,12 @@ module.exports = class mercado extends Exchange { const id = this.safeString2 (trade, 'tid', 'operation_id'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee_rate'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee_rate'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -295,12 +293,12 @@ module.exports = class mercado extends Exchange { if (currencyId in balances) { const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -407,32 +405,31 @@ module.exports = class mercado extends Exchange { // } // const id = this.safeString (order, 'order_id'); + const order_type = this.safeString (order, 'order_type'); let side = undefined; if ('order_type' in order) { - side = (order['order_type'] === 1) ? 'buy' : 'sell'; + side = (order_type === '1') ? 'buy' : 'sell'; } const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'coin_pair'); market = this.safeMarket (marketId, market); const timestamp = this.safeTimestamp (order, 'created_timestamp'); const fee = { - 'cost': this.safeFloat (order, 'fee'), + 'cost': this.safeNumber (order, 'fee'), 'currency': market['quote'], }; - const price = this.safeFloat (order, 'limit_price'); - // price = this.safeFloat (order, 'executed_price_avg', price); - const average = this.safeFloat (order, 'executed_price_avg'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'executed_quantity'); - const remaining = amount - filled; - const cost = filled * average; + const price = this.safeNumber (order, 'limit_price'); + // price = this.safeNumber (order, 'executed_price_avg', price); + const average = this.safeNumber (order, 'executed_price_avg'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const lastTradeTimestamp = this.safeTimestamp (order, 'updated_timestamp'); const rawTrades = this.safeValue (order, 'operations', []); const trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'side': side, 'order': id, }); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -446,15 +443,15 @@ module.exports = class mercado extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -512,11 +509,11 @@ module.exports = class mercado extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mixcoins.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mixcoins.js index 85138f138..11bbf93b6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mixcoins.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/mixcoins.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -72,11 +73,11 @@ module.exports = class mixcoins extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.safeFloat (balance, 'lock'); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = this.safeString (balance, 'lock'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -96,16 +97,16 @@ module.exports = class mixcoins extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'result'); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -115,7 +116,7 @@ module.exports = class mixcoins extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -128,14 +129,11 @@ module.exports = class mixcoins extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ndax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ndax.js index 0367c2695..37e8b2760 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ndax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ndax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -244,7 +245,7 @@ module.exports = class ndax extends Exchange { const name = this.safeString (currency, 'ProductFullName'); const type = this.safeString (currency, 'ProductType'); const code = this.safeCurrencyCode (this.safeString (currency, 'Product')); - const precision = this.safeFloat (currency, 'TickSize'); + const precision = this.safeNumber (currency, 'TickSize'); const isDisabled = this.safeValue (currency, 'IsDisabled'); const active = !isDisabled; result[code] = { @@ -325,8 +326,8 @@ module.exports = class ndax extends Exchange { const quote = this.safeCurrencyCode (this.safeString (market, 'Product2Symbol')); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'QuantityIncrement'), - 'price': this.safeFloat (market, 'PriceIncrement'), + 'amount': this.safeNumber (market, 'QuantityIncrement'), + 'price': this.safeNumber (market, 'PriceIncrement'), }; const sessionStatus = this.safeString (market, 'SessionStatus'); const isDisable = this.safeValue (market, 'IsDisable'); @@ -344,11 +345,11 @@ module.exports = class ndax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinimumQuantity'), + 'min': this.safeNumber (market, 'MinimumQuantity'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'MinimumPrice'), + 'min': this.safeNumber (market, 'MinimumPrice'), 'max': undefined, }, 'cost': { @@ -469,27 +470,27 @@ module.exports = class ndax extends Exchange { const timestamp = this.safeInteger (ticker, 'TimeStamp'); const marketId = this.safeString (ticker, 'InstrumentId'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'LastTradedPx'); - const percentage = this.safeFloat (ticker, 'Rolling24HrPxChangePercent'); - const change = this.safeFloat (ticker, 'Rolling24HrPxChange'); - const open = this.safeFloat (ticker, 'SessionOpen'); + const last = this.safeNumber (ticker, 'LastTradedPx'); + const percentage = this.safeNumber (ticker, 'Rolling24HrPxChangePercent'); + const change = this.safeNumber (ticker, 'Rolling24HrPxChange'); + const open = this.safeNumber (ticker, 'SessionOpen'); let average = undefined; if ((last !== undefined) && (change !== undefined)) { average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'Rolling24HrVolume'); - const quoteVolume = this.safeFloat (ticker, 'Rolling24HrNotional'); + const baseVolume = this.safeNumber (ticker, 'Rolling24HrVolume'); + const quoteVolume = this.safeNumber (ticker, 'Rolling24HrNotional'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'SessionHigh'), - 'low': this.safeFloat (ticker, 'SessionLow'), - 'bid': this.safeFloat (ticker, 'BestBid'), - 'bidVolume': undefined, // this.safeFloat (ticker, 'BidQty'), always shows 0 - 'ask': this.safeFloat (ticker, 'BestOffer'), - 'askVolume': undefined, // this.safeFloat (ticker, 'AskQty'), always shows 0 + 'high': this.safeNumber (ticker, 'SessionHigh'), + 'low': this.safeNumber (ticker, 'SessionLow'), + 'bid': this.safeNumber (ticker, 'BestBid'), + 'bidVolume': undefined, // this.safeNumber (ticker, 'BidQty'), always shows 0 + 'ask': this.safeNumber (ticker, 'BestOffer'), + 'askVolume': undefined, // this.safeNumber (ticker, 'AskQty'), always shows 0 'vwap': vwap, 'open': open, 'close': last, @@ -562,11 +563,11 @@ module.exports = class ndax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -714,8 +715,8 @@ module.exports = class ndax extends Exchange { // "OMSId":1 // } // - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let cost = undefined; let timestamp = undefined; let id = undefined; @@ -726,11 +727,8 @@ module.exports = class ndax extends Exchange { let fee = undefined; let type = undefined; if (Array.isArray (trade)) { - price = this.safeFloat (trade, 3); - amount = this.safeFloat (trade, 2); - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + priceString = this.safeString (trade, 3); + amountString = this.safeString (trade, 2); timestamp = this.safeInteger (trade, 6); id = this.safeString (trade, 0); marketId = this.safeInteger (trade, 1); @@ -742,13 +740,13 @@ module.exports = class ndax extends Exchange { id = this.safeString (trade, 'TradeId'); orderId = this.safeString2 (trade, 'OrderId', 'OrigOrderId'); marketId = this.safeString2 (trade, 'InstrumentId', 'Instrument'); - price = this.safeFloat (trade, 'Price'); - amount = this.safeFloat (trade, 'Quantity'); - cost = this.safeFloat2 (trade, 'Value', 'GrossValueExecuted'); + priceString = this.safeString (trade, 'Price'); + amountString = this.safeString (trade, 'Quantity'); + cost = this.safeNumber2 (trade, 'Value', 'GrossValueExecuted'); takerOrMaker = this.safeStringLower (trade, 'MakerTaker'); side = this.safeStringLower (trade, 'Side'); type = this.safeStringLower (trade, 'OrderType'); - const feeCost = this.safeFloat (trade, 'Fee'); + const feeCost = this.safeNumber (trade, 'Fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'FeeProductId'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -758,6 +756,11 @@ module.exports = class ndax extends Exchange { }; } } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const symbol = this.safeSymbol (marketId, market); return { 'info': trade, @@ -872,11 +875,11 @@ module.exports = class ndax extends Exchange { const currencyId = this.safeString (balance, 'ProductId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Amount'); - account['used'] = this.safeFloat (balance, 'Hold'); + account['total'] = this.safeString (balance, 'Amount'); + account['used'] = this.safeString (balance, 'Hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseLedgerEntryType (type) { @@ -922,8 +925,8 @@ module.exports = class ndax extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'ReferenceType')); const currencyId = this.safeString (item, 'ProductId'); const code = this.safeCurrencyCode (currencyId, currency); - const credit = this.safeFloat (item, 'CR'); - const debit = this.safeFloat (item, 'DR'); + const credit = this.safeNumber (item, 'CR'); + const debit = this.safeNumber (item, 'DR'); let amount = undefined; let direction = undefined; if (credit > 0) { @@ -935,7 +938,7 @@ module.exports = class ndax extends Exchange { } const timestamp = this.safeInteger (item, 'TimeStamp'); let before = undefined; - const after = this.safeFloat (item, 'Balance'); + const after = this.safeNumber (item, 'Balance'); if (direction === 'out') { before = this.sum (after, amount); } else if (direction === 'in') { @@ -1083,36 +1086,26 @@ module.exports = class ndax extends Exchange { // const id = this.safeString2 (order, 'ReplacementOrderId', 'OrderId'); const timestamp = this.safeInteger (order, 'ReceiveTime'); - let lastTradeTimestamp = undefined; + const lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); const marketId = this.safeString (order, 'Instrument'); const symbol = this.safeSymbol (marketId, market); const side = this.safeStringLower (order, 'Side'); const type = this.safeStringLower (order, 'OrderType'); const clientOrderId = this.safeString2 (order, 'ReplacementClOrdId', 'ClientOrderId'); - let price = this.safeFloat (order, 'Price', 0.0); + let price = this.safeNumber (order, 'Price', 0.0); price = (price > 0.0) ? price : undefined; - const amount = this.safeFloat (order, 'OrigQuantity'); - const filled = this.safeFloat (order, 'QuantityExecuted'); - const cost = this.safeFloat (order, 'GrossValueExecuted'); - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (filled > 0) { - lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); - average = this.safeFloat (order, 'AvgPrice', 0.0); - average = (average > 0) ? average : undefined; - } - } - let stopPrice = this.safeFloat (order, 'StopPrice', 0.0); + const amount = this.safeNumber (order, 'OrigQuantity'); + const filled = this.safeNumber (order, 'QuantityExecuted'); + const cost = this.safeNumber (order, 'GrossValueExecuted'); + let average = this.safeNumber (order, 'AvgPrice', 0.0); + average = (average > 0) ? average : undefined; + let stopPrice = this.safeNumber (order, 'StopPrice', 0.0); stopPrice = (stopPrice > 0.0) ? stopPrice : undefined; const timeInForce = undefined; const status = this.parseOrderStatus (this.safeString (order, 'OrderState')); const fee = undefined; const trades = undefined; - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -1131,10 +1124,10 @@ module.exports = class ndax extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1932,8 +1925,8 @@ module.exports = class ndax extends Exchange { } const addressTo = address; const status = this.parseTransactionStatusByType (this.safeString (transaction, 'TicketStatus'), type); - const amount = this.safeFloat (transaction, 'Amount'); - const feeCost = this.safeFloat (transaction, 'FeeAmount'); + const amount = this.safeNumber (transaction, 'Amount'); + const feeCost = this.safeNumber (transaction, 'FeeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/novadax.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/novadax.js index dfc6569d2..76f763414 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/novadax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/novadax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, BadRequest, CancelPending, OrderNotFound, InsufficientFunds, RateLimitExceeded, InvalidOrder, AccountSuspended, BadSymbol, OnMaintenance } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -197,7 +198,7 @@ module.exports = class novadax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -205,7 +206,7 @@ module.exports = class novadax extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderValue'), + 'min': this.safeNumber (market, 'minOrderValue'), 'max': undefined, }, }; @@ -247,8 +248,8 @@ module.exports = class novadax extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const open = this.safeFloat (ticker, 'open24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'open24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let percentage = undefined; let change = undefined; let average = undefined; @@ -257,18 +258,18 @@ module.exports = class novadax extends Exchange { percentage = change / open * 100; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'baseVolume24h'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume24h'); + const baseVolume = this.safeNumber (ticker, 'baseVolume24h'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -424,11 +425,13 @@ module.exports = class novadax extends Exchange { const orderId = this.safeString (trade, 'orderId'); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeStringLower (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - cost = amount * price; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'volume'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); @@ -440,7 +443,7 @@ module.exports = class novadax extends Exchange { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { - 'cost': this.safeFloat (parts, 0), + 'cost': this.safeNumber (parts, 0), 'currency': feeCurrencyCode, }; } @@ -548,11 +551,11 @@ module.exports = class novadax extends Exchange { const volumeField = this.safeString (options, 'volume', 'amount'); // or vol return [ this.safeTimestamp (ohlcv, 'score'), - this.safeFloat (ohlcv, 'openPrice'), - this.safeFloat (ohlcv, 'highPrice'), - this.safeFloat (ohlcv, 'lowPrice'), - this.safeFloat (ohlcv, 'closePrice'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'openPrice'), + this.safeNumber (ohlcv, 'highPrice'), + this.safeNumber (ohlcv, 'lowPrice'), + this.safeNumber (ohlcv, 'closePrice'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -580,12 +583,12 @@ module.exports = class novadax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'available'); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); + account['total'] = this.safeString (balance, 'available'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -608,7 +611,7 @@ module.exports = class novadax extends Exchange { if (uppercaseSide === 'SELL') { request['amount'] = this.amountToPrecision (symbol, amount); } else if (uppercaseSide === 'BUY') { - let value = this.safeFloat (params, 'value'); + let value = this.safeNumber (params, 'value'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -838,21 +841,17 @@ module.exports = class novadax extends Exchange { // } // const id = this.safeString (order, 'id'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'filledValue'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'filledValue'); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeInteger (order, 'timestamp'); - const average = this.safeFloat (order, 'averagePrice'); - const filled = this.safeFloat (order, 'filledAmount'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } + const average = this.safeNumber (order, 'averagePrice'); + const filled = this.safeNumber (order, 'filledAmount'); let fee = undefined; - const feeCost = this.safeFloat (order, 'filledFee'); + const feeCost = this.safeNumber (order, 'filledFee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -861,7 +860,7 @@ module.exports = class novadax extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -879,11 +878,11 @@ module.exports = class novadax extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async withdraw (code, amount, address, tag = undefined, params = {}) { @@ -1046,7 +1045,7 @@ module.exports = class novadax extends Exchange { } else if (type === 'COIN_OUT') { type = 'withdraw'; } - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'addressTag'); const txid = this.safeString (transaction, 'txHash'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/oceanex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/oceanex.js index 28cb8e857..6073f75d5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/oceanex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/oceanex.js @@ -147,10 +147,10 @@ module.exports = class oceanex extends Exchange { 'active': true, 'info': market, 'precision': { - 'amount': this.safeValue (market, 'amount_precision'), - 'price': this.safeValue (market, 'price_precision'), - 'base': this.safeValue (market, 'ask_precision'), - 'quote': this.safeValue (market, 'bid_precision'), + 'amount': this.safeInteger (market, 'amount_precision'), + 'price': this.safeInteger (market, 'price_precision'), + 'base': this.safeInteger (market, 'ask_precision'), + 'quote': this.safeInteger (market, 'bid_precision'), }, 'limits': { 'amount': { @@ -162,7 +162,7 @@ module.exports = class oceanex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeValue (market, 'minimum_trading_amount'), + 'min': this.safeNumber (market, 'minimum_trading_amount'), 'max': undefined, }, }, @@ -256,21 +256,21 @@ module.exports = class oceanex extends Exchange { 'symbol': market['symbol'], 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (ticker, 'last'), - 'last': this.safeFloat (ticker, 'last'), + 'close': this.safeNumber (ticker, 'last'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -395,8 +395,8 @@ module.exports = class oceanex extends Exchange { 'type': 'limit', 'takerOrMaker': undefined, 'side': side, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), 'cost': undefined, 'fee': undefined, }; @@ -423,8 +423,8 @@ module.exports = class oceanex extends Exchange { result[symbol] = { 'info': group, 'symbol': symbol, - 'maker': this.safeFloat (maker, 'value'), - 'taker': this.safeFloat (taker, 'value'), + 'maker': this.safeNumber (maker, 'value'), + 'taker': this.safeNumber (taker, 'value'), }; } return result; @@ -446,11 +446,11 @@ module.exports = class oceanex extends Exchange { const currencyId = this.safeValue (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -558,12 +558,12 @@ module.exports = class oceanex extends Exchange { // const status = this.parseOrderStatus (this.safeValue (order, 'state')); const marketId = this.safeString2 (order, 'market', 'market_id'); - const symbol = this.safeSymbol (marketId); + const symbol = this.safeSymbol (marketId, market); let timestamp = this.safeTimestamp (order, 'created_on'); if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'created_at')); } - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, @@ -575,17 +575,17 @@ module.exports = class oceanex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeValue (order, 'side'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_price'), - 'amount': this.safeFloat (order, 'volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'filled': this.safeFloat (order, 'executed_volume'), + 'average': this.safeNumber (order, 'avg_price'), + 'amount': this.safeNumber (order, 'volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'filled': this.safeNumber (order, 'executed_volume'), 'status': status, 'cost': undefined, 'trades': undefined, 'fee': undefined, - }; + }); } parseOrderStatus (status) { @@ -678,7 +678,7 @@ module.exports = class oceanex extends Exchange { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['codes'], errorCode, feedback); this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - throw new ExchangeError (response); + throw new ExchangeError (feedback); } } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/okex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/okex.js index b9b09c4e0..02d686c17 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/okex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/okex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -798,7 +799,7 @@ module.exports = class okex extends Exchange { let option = false; let baseId = this.safeString (market, 'base_currency'); let quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { if ('option_type' in market) { marketType = 'option'; @@ -824,12 +825,12 @@ module.exports = class okex extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = spot ? (base + '/' + quote) : id; - const lotSize = this.safeFloat2 (market, 'lot_size', 'trade_increment'); + const lotSize = this.safeNumber2 (market, 'lot_size', 'trade_increment'); const precision = { - 'amount': this.safeFloat (market, 'size_increment', lotSize), - 'price': this.safeFloat (market, 'tick_size'), + 'amount': this.safeNumber (market, 'size_increment', lotSize), + 'price': this.safeNumber (market, 'tick_size'), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const active = true; const fees = this.safeValue2 (this.fees, marketType, 'trading', {}); return this.extend (fees, { @@ -1004,7 +1005,7 @@ module.exports = class okex extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal'), + 'min': this.safeNumber (currency, 'min_withdrawal'), 'max': undefined, }, }, @@ -1079,18 +1080,18 @@ module.exports = class okex extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open_24h'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open_24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_24h'), - 'low': this.safeFloat (ticker, 'low_24h'), - 'bid': this.safeFloat (ticker, 'best_bid'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (ticker, 'best_ask'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber (ticker, 'high_24h'), + 'low': this.safeNumber (ticker, 'low_24h'), + 'bid': this.safeNumber (ticker, 'best_bid'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (ticker, 'best_ask'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': undefined, 'open': open, 'close': last, @@ -1099,8 +1100,8 @@ module.exports = class okex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'base_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'quote_volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'base_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'quote_volume_24h'), 'info': ticker, }; } @@ -1237,9 +1238,12 @@ module.exports = class okex extends Exchange { quote = market['quote']; } const timestamp = this.parse8601 (this.safeString2 (trade, 'timestamp', 'created_at')); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'size', 'qty'); - amount = this.safeFloat (trade, 'order_qty', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'size', 'qty'); + amountString = this.safeString (trade, 'order_qty', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -1247,13 +1251,7 @@ module.exports = class okex extends Exchange { takerOrMaker = 'taker'; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -1362,22 +1360,22 @@ module.exports = class okex extends Exchange { } return [ timestamp, // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets ]; } else { return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, 'volume'), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, 'volume'), // Base Volume ]; } } @@ -1523,9 +1521,9 @@ module.exports = class okex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeNumber (balance, 'balance'); + account['used'] = this.safeNumber (balance, 'hold'); + account['free'] = this.safeNumber (balance, 'available'); result[code] = account; } return this.parseBalance (result); @@ -1595,9 +1593,9 @@ module.exports = class okex extends Exchange { const currencyId = parts[1]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (marketBalance, 'balance'); - account['used'] = this.safeFloat (marketBalance, 'hold'); - account['free'] = this.safeFloat (marketBalance, 'available'); + account['total'] = this.safeNumber (marketBalance, 'balance'); + account['used'] = this.safeNumber (marketBalance, 'hold'); + account['free'] = this.safeNumber (marketBalance, 'available'); accounts[code] = account; } else { throw new NotSupported (this.id + ' margin balance response format has changed!'); @@ -1650,29 +1648,29 @@ module.exports = class okex extends Exchange { const code = this.safeCurrencyCode (id); const balance = this.safeValue (info, id, {}); const account = this.account (); - const totalAvailBalance = this.safeFloat (balance, 'total_avail_balance'); + const totalAvailBalance = this.safeNumber (balance, 'total_avail_balance'); if (this.safeString (balance, 'margin_mode') === 'fixed') { const contracts = this.safeValue (balance, 'contracts', []); let free = totalAvailBalance; for (let i = 0; i < contracts.length; i++) { const contract = contracts[i]; - const fixedBalance = this.safeFloat (contract, 'fixed_balance'); - const realizedPnl = this.safeFloat (contract, 'realized_pnl'); - const marginFrozen = this.safeFloat (contract, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (contract, 'margin_for_unfilled'); + const fixedBalance = this.safeNumber (contract, 'fixed_balance'); + const realizedPnl = this.safeNumber (contract, 'realized_pnl'); + const marginFrozen = this.safeNumber (contract, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (contract, 'margin_for_unfilled'); const margin = this.sum (fixedBalance, realizedPnl) - marginFrozen - marginForUnfilled; free = this.sum (free, margin); } account['free'] = free; } else { - const realizedPnl = this.safeFloat (balance, 'realized_pnl'); - const unrealizedPnl = this.safeFloat (balance, 'unrealized_pnl'); - const marginFrozen = this.safeFloat (balance, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (balance, 'margin_for_unfilled'); + const realizedPnl = this.safeNumber (balance, 'realized_pnl'); + const unrealizedPnl = this.safeNumber (balance, 'unrealized_pnl'); + const marginFrozen = this.safeNumber (balance, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (balance, 'margin_for_unfilled'); account['free'] = this.sum (totalAvailBalance, realizedPnl, unrealizedPnl) - marginFrozen - marginForUnfilled; } // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); + account['total'] = this.safeNumber (balance, 'equity'); result[code] = account; } return this.parseBalance (result); @@ -1710,8 +1708,8 @@ module.exports = class okex extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeNumber (balance, 'equity'); + account['free'] = this.safeNumber (balance, 'total_avail_balance'); result[symbol] = account; } return this.parseBalance (result); @@ -1915,7 +1913,7 @@ module.exports = class okex extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2125,8 +2123,8 @@ module.exports = class okex extends Exchange { symbol = market['symbol']; } } - let amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat2 (order, 'filled_size', 'filled_qty'); + let amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber2 (order, 'filled_size', 'filled_qty'); let remaining = undefined; if (amount !== undefined) { if (filled !== undefined) { @@ -2137,9 +2135,9 @@ module.exports = class okex extends Exchange { if (type === 'market') { remaining = 0; } - let cost = this.safeFloat2 (order, 'filled_notional', 'funds'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); + let cost = this.safeNumber2 (order, 'filled_notional', 'funds'); + const price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'price_avg'); if (cost === undefined) { if (filled !== undefined && average !== undefined) { cost = average * filled; @@ -2150,7 +2148,7 @@ module.exports = class okex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'state')); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -2163,7 +2161,7 @@ module.exports = class okex extends Exchange { if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) { clientOrderId = undefined; // fix empty clientOrderId string } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); return { 'info': order, 'id': id, @@ -2407,16 +2405,6 @@ module.exports = class okex extends Exchange { return await this.fetchOrdersByState ('7', symbol, since, limit, params); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -2444,7 +2432,8 @@ module.exports = class okex extends Exchange { async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); - const currency = this.currency (code); + const parts = code.split ('-'); + const currency = this.currency (parts[0]); const request = { 'currency': currency['id'], }; @@ -2457,8 +2446,8 @@ module.exports = class okex extends Exchange { // } // ] // - const addresses = this.parseDepositAddresses (response); - const address = this.safeValue (addresses, code); + const addressesByCode = this.parseDepositAddresses (response); + const address = this.safeValue (addressesByCode, code); if (address === undefined) { throw new InvalidAddress (this.id + ' fetchDepositAddress cannot return nonexistent addresses, you should create withdrawal addresses with the exchange website first'); } @@ -2633,7 +2622,7 @@ module.exports = class okex extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const txid = this.safeString (transaction, 'txid'); const timestamp = this.parse8601 (this.safeString (transaction, 'timestamp')); @@ -2696,19 +2685,19 @@ module.exports = class okex extends Exchange { let feeCurrencyId = undefined; if (receivedCurrencyId === quoteId) { side = this.safeString (otherTrade, 'side'); - amount = this.safeFloat (otherTrade, 'size'); - cost = this.safeFloat (userTrade, 'size'); + amount = this.safeNumber (otherTrade, 'size'); + cost = this.safeNumber (userTrade, 'size'); feeCurrencyId = this.safeString (otherTrade, 'currency'); } else { side = this.safeString (userTrade, 'side'); - amount = this.safeFloat (userTrade, 'size'); - cost = this.safeFloat (otherTrade, 'size'); + amount = this.safeNumber (userTrade, 'size'); + cost = this.safeNumber (otherTrade, 'size'); feeCurrencyId = this.safeString (userTrade, 'currency'); } const id = this.safeString (userTrade, 'trade_id'); - const price = this.safeFloat (userTrade, 'price'); - const feeCostFirst = this.safeFloat (otherTrade, 'fee'); - const feeCostSecond = this.safeFloat (userTrade, 'fee'); + const price = this.safeNumber (userTrade, 'price'); + const feeCostFirst = this.safeNumber (otherTrade, 'fee'); + const feeCostSecond = this.safeNumber (userTrade, 'fee'); const feeCurrencyCodeFirst = this.safeCurrencyCode (this.safeString (otherTrade, 'currency')); const feeCurrencyCodeSecond = this.safeCurrencyCode (this.safeString (userTrade, 'currency')); let fee = undefined; @@ -3140,7 +3129,7 @@ module.exports = class okex extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); let method = undefined; const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType'); @@ -3522,14 +3511,14 @@ module.exports = class okex extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'timestamp')); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; const marketId = this.safeString (item, 'instrument_id'); let symbol = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/paymium.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/paymium.js index 1af0c5355..2d0d8418c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/paymium.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/paymium.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -96,12 +97,12 @@ module.exports = class paymium extends Exchange { if (free in response) { const account = this.account (); const used = 'locked_' + currencyId; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -120,30 +121,30 @@ module.exports = class paymium extends Exchange { }; const ticker = await this.publicGetDataCurrencyTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'at'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'price'); + const last = this.safeNumber (ticker, 'price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'variation'), + 'percentage': this.safeNumber (ticker, 'variation'), 'average': undefined, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, @@ -159,15 +160,12 @@ module.exports = class paymium extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); + const priceString = this.safeString (trade, 'price'); const amountField = 'traded_' + market['base'].toLowerCase (); - const amount = this.safeFloat (trade, amountField); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const amountString = this.safeString (trade, amountField); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/phemex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/phemex.js index b1c294ab2..ae494da41 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/phemex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/phemex.js @@ -305,13 +305,13 @@ module.exports = class phemex extends Exchange { }); } - parseSafeFloat (value = undefined) { + parseSafeNumber (value = undefined) { if (value === undefined) { return value; } value = value.replace (',', ''); const parts = value.split (' '); - return this.safeFloat (parts, 0); + return this.safeNumber (parts, 0); } parseSwapMarket (market) { @@ -335,7 +335,9 @@ module.exports = class phemex extends Exchange { // "minPriceEp":5000, // "maxPriceEp":10000000000, // "maxOrderQty":1000000, - // "type":"Perpetual" + // "type":"Perpetual", + // "status":"Listed", + // "tipOrderQty":1000000, // "steps":"50", // "riskLimits":[ // {"limit":100,"initialMargin":"1.0%","initialMarginEr":1000000,"maintenanceMargin":"0.5%","maintenanceMarginEr":500000}, @@ -360,7 +362,7 @@ module.exports = class phemex extends Exchange { // } // const id = this.safeString (market, 'symbol'); - const baseId = this.safeString (market, 'baseCurrency', 'contractUnderlyingAssets'); + const baseId = this.safeString2 (market, 'baseCurrency', 'contractUnderlyingAssets'); const quoteId = this.safeString (market, 'quoteCurrency'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); @@ -377,16 +379,16 @@ module.exports = class phemex extends Exchange { } const linear = !inverse; const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const priceScale = this.safeInteger (market, 'priceScale'); const ratioScale = this.safeInteger (market, 'ratioScale'); const valueScale = this.safeInteger (market, 'valueScale'); - const minPriceEp = this.safeFloat (market, 'minPriceEp'); - const maxPriceEp = this.safeFloat (market, 'maxPriceEp'); - const makerFeeRateEr = this.safeFloat (market, 'makerFeeRateEr'); - const takerFeeRateEr = this.safeFloat (market, 'takerFeeRateEr'); + const minPriceEp = this.safeNumber (market, 'minPriceEp'); + const maxPriceEp = this.safeNumber (market, 'maxPriceEp'); + const makerFeeRateEr = this.safeNumber (market, 'makerFeeRateEr'); + const takerFeeRateEr = this.safeNumber (market, 'takerFeeRateEr'); if (makerFeeRateEr !== undefined) { maker = this.fromEn (makerFeeRateEr, ratioScale, 0.00000001); } @@ -404,10 +406,11 @@ module.exports = class phemex extends Exchange { }, 'cost': { 'min': undefined, - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderQty')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderQty')), }, }; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -456,7 +459,9 @@ module.exports = class phemex extends Exchange { // "defaultMakerFee":"0.001", // "defaultMakerFeeEr":100000, // "baseQtyPrecision":6, - // "quoteQtyPrecision":2 + // "quoteQtyPrecision":2, + // "status":"Listed", + // "tipOrderQty":20 // } // const type = this.safeStringLower (market, 'type'); @@ -467,30 +472,31 @@ module.exports = class phemex extends Exchange { const inverse = undefined; const spot = true; const swap = false; - const taker = this.safeFloat (market, 'defaultTakerFee'); - const maker = this.safeFloat (market, 'defaultMakerFee'); + const taker = this.safeNumber (market, 'defaultTakerFee'); + const maker = this.safeNumber (market, 'defaultMakerFee'); const precision = { - 'amount': this.parseSafeFloat (this.safeString (market, 'baseTickSize')), - 'price': this.parseSafeFloat (this.safeString (market, 'quoteTickSize')), + 'amount': this.parseSafeNumber (this.safeString (market, 'baseTickSize')), + 'price': this.parseSafeNumber (this.safeString (market, 'quoteTickSize')), }; const limits = { 'amount': { 'min': precision['amount'], - 'max': this.parseSafeFloat (this.safeString (market, 'maxBaseOrderSize')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxBaseOrderSize')), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.parseSafeFloat (this.safeString (market, 'minOrderValue')), - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderValue')), + 'min': this.parseSafeNumber (this.safeString (market, 'minOrderValue')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderValue')), }, }; const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -680,8 +686,8 @@ module.exports = class phemex extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const valueScale = this.safeInteger (currency, 'valueScale'); - const minValueEv = this.safeFloat (currency, 'minValueEv'); - const maxValueEv = this.safeFloat (currency, 'maxValueEv'); + const minValueEv = this.safeNumber (currency, 'minValueEv'); + const maxValueEv = this.safeNumber (currency, 'maxValueEv'); let minAmount = undefined; let maxAmount = undefined; let precision = undefined; @@ -731,12 +737,12 @@ module.exports = class phemex extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - let amount = this.safeFloat (bidask, amountKey); + let amount = this.safeNumber (bidask, amountKey); if (market['spot']) { amount = this.fromEv (amount, market); } return [ - this.fromEp (this.safeFloat (bidask, priceKey), market), + this.fromEp (this.safeNumber (bidask, priceKey), market), amount, ]; } @@ -870,16 +876,16 @@ module.exports = class phemex extends Exchange { // let baseVolume = undefined; if ((market !== undefined) && market['spot']) { - baseVolume = this.fromEv (this.safeFloat (ohlcv, 7), market); + baseVolume = this.fromEv (this.safeNumber (ohlcv, 7), market); } else { baseVolume = this.safeInteger (ohlcv, 7); } return [ this.safeTimestamp (ohlcv, 0), - this.fromEp (this.safeFloat (ohlcv, 3), market), - this.fromEp (this.safeFloat (ohlcv, 4), market), - this.fromEp (this.safeFloat (ohlcv, 5), market), - this.fromEp (this.safeFloat (ohlcv, 6), market), + this.fromEp (this.safeNumber (ohlcv, 3), market), + this.fromEp (this.safeNumber (ohlcv, 4), market), + this.fromEp (this.safeNumber (ohlcv, 5), market), + this.fromEp (this.safeNumber (ohlcv, 6), market), baseVolume, ]; } @@ -972,11 +978,11 @@ module.exports = class phemex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.000001); - const last = this.fromEp (this.safeFloat (ticker, 'lastEp'), market); - const quoteVolume = this.fromEp (this.safeFloat (ticker, 'turnoverEv'), market); - let baseVolume = this.safeFloat (ticker, 'volume'); + const last = this.fromEp (this.safeNumber (ticker, 'lastEp'), market); + const quoteVolume = this.fromEp (this.safeNumber (ticker, 'turnoverEv'), market); + let baseVolume = this.safeNumber (ticker, 'volume'); if (baseVolume === undefined) { - baseVolume = this.fromEv (this.safeFloat (ticker, 'volumeEv')); + baseVolume = this.fromEv (this.safeNumber (ticker, 'volumeEv')); } let vwap = undefined; if ((market !== undefined) && (market['spot'])) { @@ -985,7 +991,7 @@ module.exports = class phemex extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.fromEp (this.safeFloat (ticker, 'openEp'), market); + const open = this.fromEp (this.safeNumber (ticker, 'openEp'), market); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -997,11 +1003,11 @@ module.exports = class phemex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.fromEp (this.safeFloat (ticker, 'highEp'), market), - 'low': this.fromEp (this.safeFloat (ticker, 'lowEp'), market), - 'bid': this.fromEp (this.safeFloat (ticker, 'bidEp'), market), + 'high': this.fromEp (this.safeNumber (ticker, 'highEp'), market), + 'low': this.fromEp (this.safeNumber (ticker, 'lowEp'), market), + 'bid': this.fromEp (this.safeNumber (ticker, 'bidEp'), market), 'bidVolume': undefined, - 'ask': this.fromEp (this.safeFloat (ticker, 'askEp'), market), + 'ask': this.fromEp (this.safeNumber (ticker, 'askEp'), market), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -1192,8 +1198,8 @@ module.exports = class phemex extends Exchange { id = this.safeString (trade, tradeLength - 4); } side = this.safeStringLower (trade, tradeLength - 3); - price = this.fromEp (this.safeFloat (trade, tradeLength - 2), market); - amount = this.fromEv (this.safeFloat (trade, tradeLength - 1), market); + price = this.fromEp (this.safeNumber (trade, tradeLength - 2), market); + amount = this.fromEv (this.safeNumber (trade, tradeLength - 1), market); if (market['spot']) { if ((price !== undefined) && (amount !== undefined)) { cost = price * amount; @@ -1209,14 +1215,14 @@ module.exports = class phemex extends Exchange { if (execStatus === 'MakerFill') { takerOrMaker = 'maker'; } - price = this.fromEp (this.safeFloat (trade, 'execPriceEp'), market); - amount = this.fromEv (this.safeFloat (trade, 'execBaseQtyEv'), market); - amount = this.safeFloat (trade, 'execQty', amount); - cost = this.fromEv (this.safeFloat2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); - const feeCost = this.fromEv (this.safeFloat (trade, 'execFeeEv'), market); + price = this.fromEp (this.safeNumber (trade, 'execPriceEp'), market); + amount = this.fromEv (this.safeNumber (trade, 'execBaseQtyEv'), market); + amount = this.safeNumber (trade, 'execQty', amount); + cost = this.fromEv (this.safeNumber2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); + const feeCost = this.fromEv (this.safeNumber (trade, 'execFeeEv'), market); if (feeCost !== undefined) { let feeRate = undefined; - let feeRateEr = this.safeFloat (trade, 'feeRateEr'); + let feeRateEr = this.safeNumber (trade, 'feeRateEr'); if (feeRateEr < 0) { feeRateEr = Math.abs (feeRateEr); feeRate = this.fromEr (feeRateEr, market); @@ -1292,9 +1298,9 @@ module.exports = class phemex extends Exchange { const currency = this.safeValue (this.currencies, code, {}); const scale = this.safeInteger (currency, 'valueScale', 8); const account = this.account (); - const balanceEv = this.safeFloat (balance, 'balanceEv'); - const lockedTradingBalanceEv = this.safeFloat (balance, 'lockedTradingBalanceEv'); - const lockedWithdrawEv = this.safeFloat (balance, 'lockedWithdrawEv'); + const balanceEv = this.safeNumber (balance, 'balanceEv'); + const lockedTradingBalanceEv = this.safeNumber (balance, 'lockedTradingBalanceEv'); + const lockedWithdrawEv = this.safeNumber (balance, 'lockedWithdrawEv'); const total = this.fromEn (balanceEv, scale, scale, DECIMAL_PLACES); const lockedTradingBalance = this.fromEn (lockedTradingBalanceEv, scale, scale, DECIMAL_PLACES); const lockedWithdraw = this.fromEn (lockedWithdrawEv, scale, scale, DECIMAL_PLACES); @@ -1388,8 +1394,8 @@ module.exports = class phemex extends Exchange { const code = this.safeCurrencyCode (currencyId); const currency = this.currency (code); const account = this.account (); - const accountBalanceEv = this.safeFloat (balance, 'accountBalanceEv'); - const totalUsedBalanceEv = this.safeFloat (balance, 'totalUsedBalanceEv'); + const accountBalanceEv = this.safeNumber (balance, 'accountBalanceEv'); + const totalUsedBalanceEv = this.safeNumber (balance, 'totalUsedBalanceEv'); const valueScale = this.safeInteger (currency, 'valueScale', 8); account['total'] = this.fromEn (accountBalanceEv, valueScale, valueScale, DECIMAL_PLACES); account['used'] = this.fromEn (totalUsedBalanceEv, valueScale, valueScale, DECIMAL_PLACES); @@ -1621,21 +1627,21 @@ module.exports = class phemex extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let price = this.fromEp (this.safeFloat (order, 'priceEp'), market); + let price = this.fromEp (this.safeNumber (order, 'priceEp'), market); if (price === 0) { price = undefined; } - const amount = this.fromEv (this.safeFloat (order, 'baseQtyEv'), market); - const remaining = this.fromEv (this.safeFloat (order, 'leavesBaseQtyEv'), market); - let filled = this.fromEv (this.safeFloat (order, 'cumBaseQtyEv'), market); - const cost = this.fromEv (this.safeFloat (order, 'quoteQtyEv'), market); - const average = this.fromEp (this.safeFloat (order, 'avgPriceEp'), market); + const amount = this.fromEv (this.safeNumber (order, 'baseQtyEv'), market); + const remaining = this.fromEv (this.safeNumber (order, 'leavesBaseQtyEv'), market); + let filled = this.fromEv (this.safeNumber (order, 'cumBaseQtyEv'), market); + const cost = this.fromEv (this.safeNumber (order, 'quoteQtyEv'), market); + const average = this.fromEp (this.safeNumber (order, 'avgPriceEp'), market); const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'ordType')); const timestamp = this.safeIntegerProduct2 (order, 'actionTimeNs', 'createTimeNs', 0.000001); let fee = undefined; - const feeCost = this.fromEv (this.safeFloat (order, 'cumFeeEv'), market); + const feeCost = this.fromEv (this.safeNumber (order, 'cumFeeEv'), market); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1648,7 +1654,7 @@ module.exports = class phemex extends Exchange { } } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.fromEp (this.safeFloat (order, 'stopPxEp', market)); + const stopPrice = this.fromEp (this.safeNumber (order, 'stopPxEp', market)); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -1721,18 +1727,18 @@ module.exports = class phemex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'orderType')); - const price = this.fromEp (this.safeFloat (order, 'priceEp'), market); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); + const price = this.fromEp (this.safeNumber (order, 'priceEp'), market); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); const timestamp = this.safeIntegerProduct (order, 'actionTimeNs', 0.000001); - const cost = this.safeFloat (order, 'cumValue'); + const cost = this.safeNumber (order, 'cumValue'); let lastTradeTimestamp = this.safeIntegerProduct (order, 'transactTimeNs', 0.000001); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -1807,7 +1813,7 @@ module.exports = class phemex extends Exchange { } request['qtyType'] = qtyType; if (qtyType === 'ByQuote') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); params = this.omit (params, 'cost'); if (this.options['createOrderByQuoteRequiresPrice']) { if (price !== undefined) { @@ -1827,7 +1833,7 @@ module.exports = class phemex extends Exchange { if (type === 'Limit') { request['priceEp'] = this.toEp (price, market); } - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice !== undefined) { request['stopPxEp'] = this.toEp (stopPrice, market); } @@ -2335,7 +2341,7 @@ module.exports = class phemex extends Exchange { const code = currency['code']; const timestamp = this.safeInteger2 (transaction, 'createdAt', 'submitedAt'); let type = this.safeStringLower (transaction, 'type'); - const feeCost = this.fromEn (this.safeFloat (transaction, 'feeEv'), currency['valueScale'], currency['precision']); + const feeCost = this.fromEn (this.safeNumber (transaction, 'feeEv'), currency['valueScale'], currency['precision']); let fee = undefined; if (feeCost !== undefined) { type = 'withdrawal'; @@ -2345,7 +2351,7 @@ module.exports = class phemex extends Exchange { }; } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.fromEn (this.safeFloat (transaction, 'amountEv'), currency['valueScale'], currency['precision']); + const amount = this.fromEn (this.safeNumber (transaction, 'amountEv'), currency['valueScale'], currency['precision']); return { 'info': transaction, 'id': id, @@ -2367,7 +2373,7 @@ module.exports = class phemex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.safeString (params, 'code'); const request = {}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/poloniex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/poloniex.js index 30eee15c9..fbb6447ad 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/poloniex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/poloniex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, RequestTimeout, AuthenticationError, PermissionDenied, DDoSProtection, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, CancelPending, InvalidNonce, OnMaintenance, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -113,6 +114,7 @@ module.exports = class poloniex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', // starting from Jan 8 2020 'maker': 0.0009, 'taker': 0.0009, @@ -207,24 +209,6 @@ module.exports = class poloniex extends Exchange { }); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - parseOHLCV (ohlcv, market = undefined) { // // { @@ -240,11 +224,11 @@ module.exports = class poloniex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'date'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'quoteVolume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'quoteVolume'), ]; } @@ -337,11 +321,11 @@ module.exports = class poloniex extends Exchange { const balance = this.safeValue (response, currencyId, {}); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onOrders'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFees (params = {}) { @@ -359,8 +343,8 @@ module.exports = class poloniex extends Exchange { // return { 'info': fees, - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), 'withdraw': {}, 'deposit': {}, }; @@ -418,8 +402,8 @@ module.exports = class poloniex extends Exchange { let open = undefined; let change = undefined; let average = undefined; - const last = this.safeFloat (ticker, 'last'); - const relativeChange = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const relativeChange = this.safeNumber (ticker, 'percentChange'); if (relativeChange !== -1) { open = last / this.sum (1, relativeChange); change = last - open; @@ -429,11 +413,11 @@ module.exports = class poloniex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24hr'), - 'low': this.safeFloat (ticker, 'low24hr'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high24hr'), + 'low': this.safeNumber (ticker, 'low24hr'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -443,8 +427,8 @@ module.exports = class poloniex extends Exchange { 'change': change, 'percentage': relativeChange * 100, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -485,7 +469,7 @@ module.exports = class poloniex extends Exchange { const code = this.safeCurrencyCode (id); const active = (currency['delisted'] === 0) && !currency['disabled']; const numericId = this.safeInteger (currency, 'id'); - const fee = this.safeFloat (currency, 'txFee'); + const fee = this.safeNumber (currency, 'txFee'); result[code] = { 'id': id, 'numericId': numericId, @@ -576,13 +560,18 @@ module.exports = class poloniex extends Exchange { } const side = this.safeString (trade, 'type'); let fee = undefined; - const price = this.safeFloat (trade, 'rate'); - const cost = this.safeFloat (trade, 'total'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const feeDisplay = this.safeString (trade, 'feeDisplay'); if (feeDisplay !== undefined) { const parts = feeDisplay.split (' '); - const feeCost = this.safeFloat (parts, 0); + const feeCost = this.safeNumber (parts, 0); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -601,7 +590,7 @@ module.exports = class poloniex extends Exchange { } } let takerOrMaker = undefined; - const takerAdjustment = this.safeFloat (trade, 'takerAdjustment'); + const takerAdjustment = this.safeNumber (trade, 'takerAdjustment'); if (takerAdjustment !== undefined) { takerOrMaker = 'taker'; } @@ -847,9 +836,9 @@ module.exports = class poloniex extends Exchange { if (resultingTrades !== undefined) { trades = this.parseTrades (resultingTrades, market); } - const price = this.safeFloat2 (order, 'price', 'rate'); - let remaining = this.safeFloat (order, 'amount'); - let amount = this.safeFloat (order, 'startingAmount'); + const price = this.safeNumber2 (order, 'price', 'rate'); + let remaining = this.safeNumber (order, 'amount'); + let amount = this.safeNumber (order, 'startingAmount'); let filled = undefined; let cost = 0; if (amount !== undefined) { @@ -899,7 +888,7 @@ module.exports = class poloniex extends Exchange { } const id = this.safeString (order, 'orderNumber'); let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -1396,11 +1385,11 @@ module.exports = class poloniex extends Exchange { const defaultType = ('withdrawalNumber' in transaction) ? 'withdrawal' : 'deposit'; const type = this.safeString (transaction, 'type', defaultType); const id = this.safeString2 (transaction, 'withdrawalNumber', 'depositNumber'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'paymentID'); // according to https://poloniex.com/fees/ - const feeCost = this.safeFloat (transaction, 'fee', 0); + const feeCost = this.safeNumber (transaction, 'fee', 0); if (type === 'withdrawal') { // poloniex withdrawal amount includes the fee amount = amount - feeCost; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/probit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/probit.js index 522045f2c..2b551ca0a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/probit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/probit.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, BadResponse, BadRequest, InvalidOrder, InsufficientFunds, AuthenticationError, ArgumentsRequired, InvalidAddress, RateLimitExceeded, DDoSProtection, BadSymbol } = require ('./base/errors'); const { TRUNCATE, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -140,9 +141,11 @@ module.exports = class probit extends Exchange { }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', 'CBC': 'CryptoBharatCoin', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'HBC': 'Hybrid Bank Cash', 'UNI': 'UNICORN Token', }, @@ -191,11 +194,11 @@ module.exports = class probit extends Exchange { const costPrecision = this.safeInteger (market, 'cost_precision'); const precision = { 'amount': 1 / Math.pow (10, amountPrecision), - 'price': this.safeFloat (market, 'price_increment'), + 'price': this.safeNumber (market, 'price_increment'), 'cost': 1 / Math.pow (10, costPrecision), }; - const takerFeeRate = this.safeFloat (market, 'taker_fee_rate'); - const makerFeeRate = this.safeFloat (market, 'maker_fee_rate'); + const takerFeeRate = this.safeNumber (market, 'taker_fee_rate'); + const makerFeeRate = this.safeNumber (market, 'maker_fee_rate'); result.push ({ 'id': id, 'info': market, @@ -210,16 +213,16 @@ module.exports = class probit extends Exchange { 'maker': makerFeeRate / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_cost'), - 'max': this.safeFloat (market, 'max_cost'), + 'min': this.safeNumber (market, 'min_cost'), + 'max': this.safeNumber (market, 'max_cost'), }, }, }); @@ -306,7 +309,7 @@ module.exports = class probit extends Exchange { // [ { 'amount': '0.015', 'priority': 1, 'currency_id': 'ETH' }, {} ] for (let j = 0; j < withdrawalFees.length; j++) { const withdrawalFee = withdrawalFees[j]; - const amount = this.safeFloat (withdrawalFee, 'amount'); + const amount = this.safeNumber (withdrawalFee, 'amount'); const priority = this.safeInteger (withdrawalFee, 'priority'); if ((amount !== undefined) && (priority !== undefined)) { fees.push (withdrawalFee); @@ -314,7 +317,7 @@ module.exports = class probit extends Exchange { } const withdrawalFeesByPriority = this.sortBy (fees, 'priority'); const withdrawalFee = this.safeValue (withdrawalFeesByPriority, 0, {}); - const fee = this.safeFloat (withdrawalFee, 'amount'); + const fee = this.safeNumber (withdrawalFee, 'amount'); result[code] = { 'id': id, 'code': code, @@ -337,11 +340,11 @@ module.exports = class probit extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (platform, 'min_deposit_amount'), + 'min': this.safeNumber (platform, 'min_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (platform, 'min_withdrawal_amount'), + 'min': this.safeNumber (platform, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -371,11 +374,11 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (balance, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'total'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -427,14 +430,6 @@ module.exports = class probit extends Exchange { return this.parseTickers (data, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -482,8 +477,8 @@ module.exports = class probit extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); - const close = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); + const close = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); let percentage = undefined; let open = undefined; if (change !== undefined) { @@ -492,15 +487,15 @@ module.exports = class probit extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -642,16 +637,13 @@ module.exports = class probit extends Exchange { marketId = this.safeString (trade, 'market_id', marketId); const symbol = this.safeSymbol (marketId, market, '-'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'order_id'); - const feeCost = this.safeFloat (trade, 'fee_amount'); + const feeCost = this.safeNumber (trade, 'fee_amount'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency_id'); @@ -795,11 +787,11 @@ module.exports = class probit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'start_time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_volume'), ]; } @@ -898,37 +890,24 @@ module.exports = class probit extends Exchange { const marketId = this.safeString (order, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'time')); - let price = this.safeFloat (order, 'limit_price'); - const filled = this.safeFloat (order, 'filled_quantity'); - let remaining = this.safeFloat (order, 'open_quantity'); - const canceledAmount = this.safeFloat (order, 'cancelled_quantity'); + let price = this.safeNumber (order, 'limit_price'); + const filled = this.safeNumber (order, 'filled_quantity'); + let remaining = this.safeNumber (order, 'open_quantity'); + const canceledAmount = this.safeNumber (order, 'cancelled_quantity'); if (canceledAmount !== undefined) { remaining = this.sum (remaining, canceledAmount); } - const amount = this.safeFloat (order, 'quantity', this.sum (filled, remaining)); - let cost = this.safeFloat2 (order, 'filled_cost', 'cost'); + const amount = this.safeNumber (order, 'quantity', this.sum (filled, remaining)); + const cost = this.safeNumber2 (order, 'filled_cost', 'cost'); if (type === 'market') { price = undefined; } - let average = undefined; - if (filled !== undefined) { - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if (cost !== undefined) { - if (filled > 0) { - average = cost / filled; - } - } - } let clientOrderId = this.safeString (order, 'client_order_id'); if (clientOrderId === '') { clientOrderId = undefined; } const timeInForce = this.safeStringUpper (order, 'time_in_force'); - return { + return this.safeOrder ({ 'id': id, 'info': order, 'clientOrderId': clientOrderId, @@ -945,11 +924,11 @@ module.exports = class probit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'average': average, + 'average': undefined, 'cost': cost, 'fee': undefined, 'trades': undefined, - }; + }); } costToPrecision (symbol, cost) { @@ -979,7 +958,7 @@ module.exports = class probit extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -1104,16 +1083,6 @@ module.exports = class probit extends Exchange { return this.parseDepositAddresses (data); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { // In order to use this method // you need to allow API withdrawal from the API Settings Page, and @@ -1144,7 +1113,7 @@ module.exports = class probit extends Exchange { parseTransaction (transaction, currency = undefined) { const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'destination_tag'); const txid = this.safeString (transaction, 'hash'); @@ -1153,7 +1122,7 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (transaction, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined && feeCost !== 0) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/qtrade.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/qtrade.js index aa66545bf..d77b576c4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/qtrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/qtrade.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, InsufficientFunds, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -179,11 +180,11 @@ module.exports = class qtrade extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_buy_value'), + 'min': this.safeNumber (market, 'minimum_buy_value'), 'max': undefined, }, 'price': { @@ -264,12 +265,12 @@ module.exports = class qtrade extends Exchange { 'info': currency, 'type': type, 'name': name, - 'fee': this.safeFloat (config, 'withdraw_fee'), + 'fee': this.safeNumber (config, 'withdraw_fee'), 'precision': this.safeInteger (currency, 'precision'), 'active': active, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimum_order'), + 'min': this.safeNumber (currency, 'minimum_order'), 'max': undefined, }, 'price': { @@ -304,11 +305,11 @@ module.exports = class qtrade extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'market_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'market_volume'), ]; } @@ -370,8 +371,8 @@ module.exports = class qtrade extends Exchange { const result = []; for (let j = 0; j < prices.length; j++) { const priceAsString = prices[j]; - const price = this.safeFloat (prices, j); - const amount = this.safeFloat (bidasks, priceAsString); + const price = this.safeNumber (prices, j); + const amount = this.safeNumber (bidasks, priceAsString); result.push ([ price, amount ]); } orderbook[side] = result; @@ -403,12 +404,12 @@ module.exports = class qtrade extends Exchange { const marketId = this.safeString (ticker, 'id_hr'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeIntegerProduct (ticker, 'last_change', 0.001); - const previous = this.safeFloat (ticker, 'day_open'); - const last = this.safeFloat (ticker, 'last'); - const day_change = this.safeFloat (ticker, 'day_change'); + const previous = this.safeNumber (ticker, 'day_open'); + const last = this.safeNumber (ticker, 'last'); + const day_change = this.safeNumber (ticker, 'day_change'); let percentage = undefined; let change = undefined; - let average = this.safeFloat (ticker, 'day_avg_price'); + let average = this.safeNumber (ticker, 'day_avg_price'); if (day_change !== undefined) { percentage = day_change * 100; if (previous !== undefined) { @@ -418,18 +419,18 @@ module.exports = class qtrade extends Exchange { if ((average === undefined) && (last !== undefined) && (previous !== undefined)) { average = this.sum (last, previous) / 2; } - const baseVolume = this.safeFloat (ticker, 'day_volume_market'); - const quoteVolume = this.safeFloat (ticker, 'day_volume_base'); + const baseVolume = this.safeNumber (ticker, 'day_volume_market'); + const quoteVolume = this.safeNumber (ticker, 'day_volume_base'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'day_high'), - 'low': this.safeFloat (ticker, 'day_low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'day_high'), + 'low': this.safeNumber (ticker, 'day_low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': previous, @@ -637,16 +638,16 @@ module.exports = class qtrade extends Exchange { const side = this.safeString (trade, 'side'); const marketId = this.safeString (trade, 'market_string'); const symbol = this.safeSymbol (marketId, market, '_'); - let cost = this.safeFloat2 (trade, 'base_volume', 'base_amount'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'market_amount', 'amount'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - if (price !== undefined) { - cost = price * amount; - } + let cost = this.safeNumber2 (trade, 'base_volume', 'base_amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'market_amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'base_fee'); + const feeCost = this.safeNumber (trade, 'base_fee'); if (feeCost !== undefined) { const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; fee = { @@ -703,7 +704,7 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); account['used'] = 0; result[code] = account; } @@ -713,10 +714,10 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -845,10 +846,9 @@ module.exports = class qtrade extends Exchange { side = this.safeString (parts, 0); orderType = this.safeString (parts, 1); } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'market_amount'); - let remaining = this.safeFloat (order, 'market_amount_remaining'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'market_amount'); + const remaining = this.safeNumber (order, 'market_amount_remaining'); const open = this.safeValue (order, 'open', false); const closeReason = this.safeString (order, 'close_reason'); let status = undefined; @@ -860,58 +860,21 @@ module.exports = class qtrade extends Exchange { status = 'closed'; } const marketId = this.safeString (order, 'market_string'); - const symbol = this.safeSymbol (marketId, market, '_'); + market = this.safeMarket (marketId, market, '_'); + const symbol = market['symbol']; const rawTrades = this.safeValue (order, 'trades', []); const parsedTrades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id, 'side': side, 'type': orderType, }); - const numTrades = parsedTrades.length; - let lastTradeTimestamp = undefined; - let feeCost = undefined; - let cost = undefined; - if (numTrades > 0) { - feeCost = 0; - cost = 0; - filled = 0; - remaining = amount; - for (let i = 0; i < parsedTrades.length; i++) { - const trade = parsedTrades[i]; - feeCost = this.sum (trade['fee']['cost'], feeCost); - lastTradeTimestamp = this.safeInteger (trade, 'timestamp'); - cost = this.sum (trade['cost'], cost); - filled = this.sum (trade['amount'], filled); - remaining = Math.max (0, remaining - trade['amount']); - } - } - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; - fee = { - 'currency': feeCurrencyCode, - 'cost': feeCost, - }; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let average = undefined; - if (filled !== undefined) { - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': orderType, 'timeInForce': undefined, @@ -919,15 +882,16 @@ module.exports = class qtrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, - 'fee': fee, - 'cost': cost, + 'fee': undefined, + 'fees': undefined, + 'cost': undefined, 'trades': parsedTrades, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -1396,7 +1360,7 @@ module.exports = class qtrade extends Exchange { const tagTo = tag; const cancelRequested = this.safeValue (transaction, 'cancel_requested'); const type = (cancelRequested === undefined) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); let status = this.parseTransactionStatus (this.safeString (transaction, 'status')); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/rightbtc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/rightbtc.js index d22048303..c1cc6bc9b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/rightbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/rightbtc.js @@ -185,8 +185,8 @@ module.exports = class rightbtc extends Exchange { return result; } - divideSafeFloat (x, key, divisor) { - const value = this.safeFloat (x, key); + divideSafeNumber (x, key, divisor) { + const value = this.safeNumber (x, key); if (value !== undefined) { return value / divisor; } @@ -196,12 +196,12 @@ module.exports = class rightbtc extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); - const last = this.divideSafeFloat (ticker, 'last', 1e8); - const high = this.divideSafeFloat (ticker, 'high', 1e8); - const low = this.divideSafeFloat (ticker, 'low', 1e8); - const bid = this.divideSafeFloat (ticker, 'buy', 1e8); - const ask = this.divideSafeFloat (ticker, 'sell', 1e8); - const baseVolume = this.divideSafeFloat (ticker, 'vol24h', 1e8); + const last = this.divideSafeNumber (ticker, 'last', 1e8); + const high = this.divideSafeNumber (ticker, 'high', 1e8); + const low = this.divideSafeNumber (ticker, 'low', 1e8); + const bid = this.divideSafeNumber (ticker, 'buy', 1e8); + const ask = this.divideSafeNumber (ticker, 'sell', 1e8); + const baseVolume = this.divideSafeNumber (ticker, 'vol24h', 1e8); return { 'symbol': symbol, 'timestamp': timestamp, @@ -305,9 +305,9 @@ module.exports = class rightbtc extends Exchange { let id = this.safeString (trade, 'tid'); id = this.safeString (trade, 'trade_id', id); const orderId = this.safeString (trade, 'order_id'); - const price = this.divideSafeFloat (trade, 'price', 1e8); - let amount = this.safeFloat (trade, 'amount'); - amount = this.safeFloat (trade, 'quantity', amount); + const price = this.divideSafeNumber (trade, 'price', 1e8); + let amount = this.safeNumber (trade, 'amount'); + amount = this.safeNumber (trade, 'quantity', amount); if (amount !== undefined) { amount = amount / 1e8; } @@ -404,8 +404,8 @@ module.exports = class rightbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); // https://github.com/ccxt/ccxt/issues/3873 - account['free'] = this.divideSafeFloat (balance, 'balance', 1e8); - account['used'] = this.divideSafeFloat (balance, 'frozen', 1e8); + account['free'] = this.divideSafeNumber (balance, 'balance', 1e8); + account['used'] = this.divideSafeNumber (balance, 'frozen', 1e8); result[code] = account; } return this.parseBalance (result); @@ -494,30 +494,18 @@ module.exports = class rightbtc extends Exchange { } else if ('transactTime' in order) { timestamp = order['transactTime']; } - let price = this.safeFloat2 (order, 'limit', 'price'); + let price = this.safeNumber2 (order, 'limit', 'price'); if (price !== undefined) { price = price / 1e8; } - const amount = this.divideSafeFloat (order, 'quantity', 1e8); - let filled = this.divideSafeFloat (order, 'filled_quantity', 1e8); - let remaining = this.divideSafeFloat (order, 'rest', 1e8); - const cost = this.divideSafeFloat (order, 'cost', 1e8); + const amount = this.divideSafeNumber (order, 'quantity', 1e8); + const filled = this.divideSafeNumber (order, 'filled_quantity', 1e8); + const remaining = this.divideSafeNumber (order, 'rest', 1e8); + const cost = this.divideSafeNumber (order, 'cost', 1e8); // lines 483-494 should be generalized into a base class method - if (amount !== undefined) { - if (remaining === undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - if (filled === undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } - } const type = 'limit'; const side = this.safeStringLower (order, 'side'); - const feeCost = this.divideSafeFloat (order, 'min_fee', 1e8); + const feeCost = this.divideSafeNumber (order, 'min_fee', 1e8); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -525,13 +513,13 @@ module.exports = class rightbtc extends Exchange { feeCurrency = market['quote']; } fee = { - 'rate': this.safeFloat (order, 'fee'), + 'rate': this.safeNumber (order, 'fee'), 'cost': feeCost, 'currency': feeCurrency, }; } const trades = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -553,7 +541,7 @@ module.exports = class rightbtc extends Exchange { 'fee': fee, 'trades': trades, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ripio.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ripio.js index b3a30607e..8155014d3 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ripio.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/ripio.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, BadSymbol, BadRequest, InvalidOrder, ArgumentsRequired, OrderNotFound, InsufficientFunds, DDoSProtection } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -149,12 +150,12 @@ module.exports = class ripio extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'min_amount'), - 'price': this.safeFloat (market, 'price_tick'), + 'amount': this.safeNumber (market, 'min_amount'), + 'price': this.safeNumber (market, 'price_tick'), }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -162,15 +163,15 @@ module.exports = class ripio extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_value'), + 'min': this.safeNumber (market, 'min_value'), 'max': undefined, }, }; const active = this.safeValue (market, 'enabled', true); const fees = this.safeValue (market, 'fees', []); const firstFee = this.safeValue (fees, 0, {}); - const maker = this.safeFloat (firstFee, 'maker_fee', 0.0); - const taker = this.safeFloat (firstFee, 'taker_fee', 0.0); + const maker = this.safeNumber (firstFee, 'maker_fee', 0.0); + const taker = this.safeNumber (firstFee, 'taker_fee', 0.0); result.push ({ 'id': id, 'symbol': symbol, @@ -277,18 +278,18 @@ module.exports = class ripio extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); const marketId = this.safeString (ticker, 'pair'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const average = this.safeFloat (ticker, 'avg'); + const last = this.safeNumber (ticker, 'last_price'); + const average = this.safeNumber (ticker, 'avg'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bid_volume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'ask_volume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bid_volume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'ask_volume'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -430,15 +431,14 @@ module.exports = class ripio extends Exchange { if (side !== undefined) { side = side.toLowerCase (); } - const price = this.safeFloat2 (trade, 'price', 'match_price'); - const amount = this.safeFloat2 (trade, 'amount', 'exchanged'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString2 (trade, 'price', 'match_price'); + const amountString = this.safeString2 (trade, 'amount', 'exchanged'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'pair'); market = this.safeMarket (marketId, market); - const feeCost = this.safeFloat (trade, takerOrMaker + '_fee'); + const feeCost = this.safeNumber (trade, takerOrMaker + '_fee'); const orderId = this.safeString (trade, takerOrMaker); let fee = undefined; if (feeCost !== undefined) { @@ -512,11 +512,11 @@ module.exports = class ripio extends Exchange { const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -775,16 +775,16 @@ module.exports = class ripio extends Exchange { // } // const id = this.safeString (order, 'order_id'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat (order, 'notional'); + const amount = this.safeNumber (order, 'amount'); + let cost = this.safeNumber (order, 'notional'); const type = this.safeStringLower (order, 'order_type'); const priceField = (type === 'market') ? 'fill_price' : 'limit_price'; - const price = this.safeFloat (order, priceField); + const price = this.safeNumber (order, priceField); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeTimestamp (order, 'created_at'); let average = this.safeValue (order, 'fill_price'); - let filled = this.safeFloat (order, 'filled'); + let filled = this.safeNumber (order, 'filled'); let remaining = undefined; const fills = this.safeValue (order, 'fills'); let trades = undefined; @@ -819,7 +819,7 @@ module.exports = class ripio extends Exchange { } const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); return { 'id': id, 'clientOrderId': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/southxchange.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/southxchange.js index d2bdd8cec..96ca247a0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/southxchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/southxchange.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -114,14 +115,14 @@ module.exports = class southxchange extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const deposited = this.safeFloat (balance, 'Deposited'); - const unconfirmed = this.safeFloat (balance, 'Unconfirmed'); + const deposited = this.safeString (balance, 'Deposited'); + const unconfirmed = this.safeString (balance, 'Unconfirmed'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'Available'); - account['total'] = this.sum (deposited, unconfirmed); + account['free'] = this.safeString (balance, 'Available'); + account['total'] = Precise.stringAdd (deposited, unconfirmed); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -139,16 +140,16 @@ module.exports = class southxchange extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'Last'); + const last = this.safeNumber (ticker, 'Last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'Bid'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -156,9 +157,9 @@ module.exports = class southxchange extends Exchange { 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'Variation24Hr'), + 'percentage': this.safeNumber (ticker, 'Variation24Hr'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume24Hr'), + 'baseVolume': this.safeNumber (ticker, 'Volume24Hr'), 'quoteVolume': undefined, 'info': ticker, }; @@ -192,14 +193,11 @@ module.exports = class southxchange extends Exchange { parseTrade (trade, market) { const timestamp = this.safeTimestamp (trade, 'At'); - const price = this.safeFloat (trade, 'Price'); - const amount = this.safeFloat (trade, 'Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'Price'); + const amountString = this.safeString (trade, 'Amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'Type'); let symbol = undefined; if (market !== undefined) { @@ -240,21 +238,13 @@ module.exports = class southxchange extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const timestamp = undefined; - const price = this.safeFloat (order, 'LimitPrice'); - const amount = this.safeFloat (order, 'OriginalAmount'); - const remaining = this.safeFloat (order, 'Amount'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - cost = price * amount; - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'LimitPrice'); + const amount = this.safeNumber (order, 'OriginalAmount'); + const remaining = this.safeNumber (order, 'Amount'); const type = 'limit'; const side = this.safeStringLower (order, 'Type'); const id = this.safeString (order, 'Code'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -269,15 +259,14 @@ module.exports = class southxchange extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'filled': filled, + 'cost': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -410,8 +399,8 @@ module.exports = class southxchange extends Exchange { const type = this.safeString (item, 'Type'); const ledgerEntryType = this.parseLedgerEntryType (type); const code = this.safeCurrencyCode (this.safeString (item, 'CurrencyCode'), currency); - let amount = this.safeFloat (item, 'Amount'); - const after = this.safeFloat (item, 'TotalBalance'); + let amount = this.safeNumber (item, 'Amount'); + const after = this.safeNumber (item, 'TotalBalance'); let before = undefined; if (amount !== undefined) { if (after !== undefined) { @@ -582,7 +571,7 @@ module.exports = class southxchange extends Exchange { // } // const id = this.safeString (transaction, 'MovementId'); - const amount = this.safeFloat (transaction, 'Amount'); + const amount = this.safeNumber (transaction, 'Amount'); const address = this.safeString (transaction, 'Address'); const addressTo = address; const addressFrom = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/stex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/stex.js index af2e256f3..f4979c48a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/stex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/stex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, OrderNotFound, PermissionDenied, BadRequest, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -186,6 +187,7 @@ module.exports = class stex extends Exchange { 'BITSW': 'BITS', 'BHD': 'Bithold', 'BTH': 'Bithereum', + 'MPH': 'Chasyr Token', 'SBTC': 'SBTCT', // SiamBitcoin }, 'options': { @@ -249,7 +251,7 @@ module.exports = class stex extends Exchange { // differentiated fees for each particular method const code = this.safeCurrencyCode (this.safeString (currency, 'code')); const precision = this.safeInteger (currency, 'precision'); - const fee = this.safeFloat (currency, 'withdrawal_fee_const'); // todo: redesign + const fee = this.safeNumber (currency, 'withdrawal_fee_const'); // todo: redesign const active = this.safeValue (currency, 'active', true); result[code] = { 'id': id, @@ -266,11 +268,11 @@ module.exports = class stex extends Exchange { 'price': { 'min': Math.pow (10, -precision), 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (currency, 'minimum_deposit_amount'), + 'min': this.safeNumber (currency, 'minimum_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal_amount'), + 'min': this.safeNumber (currency, 'minimum_withdrawal_amount'), 'max': undefined, }, }, @@ -331,11 +333,11 @@ module.exports = class stex extends Exchange { 'price': this.safeInteger (market, 'market_precision'), }; const active = this.safeValue (market, 'active'); - const minBuyPrice = this.safeFloat (market, 'min_buy_price'); - const minSellPrice = this.safeFloat (market, 'min_sell_price'); + const minBuyPrice = this.safeNumber (market, 'min_buy_price'); + const minSellPrice = this.safeNumber (market, 'min_sell_price'); const minPrice = Math.max (minBuyPrice, minSellPrice); - const buyFee = this.safeFloat (market, 'buy_fee_percent') / 100; - const sellFee = this.safeFloat (market, 'sell_fee_percent') / 100; + const buyFee = this.safeNumber (market, 'buy_fee_percent') / 100; + const sellFee = this.safeNumber (market, 'sell_fee_percent') / 100; const fee = Math.max (buyFee, sellFee); result.push ({ 'id': id, @@ -354,7 +356,7 @@ module.exports = class stex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_order_amount'), + 'min': this.safeNumber (market, 'min_order_amount'), 'max': undefined, }, 'price': { 'min': minPrice, 'max': undefined }, @@ -518,8 +520,8 @@ module.exports = class stex extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString2 (ticker, 'id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -532,11 +534,11 @@ module.exports = class stex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -546,20 +548,12 @@ module.exports = class stex extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volumeQuote'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volumeQuote'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker (params); @@ -625,11 +619,11 @@ module.exports = class stex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -704,12 +698,11 @@ module.exports = class stex extends Exchange { // const id = this.safeString (trade, 'id'); const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; @@ -822,11 +815,11 @@ module.exports = class stex extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'currency_id')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen_balance'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -885,9 +878,9 @@ module.exports = class stex extends Exchange { const marketId = this.safeString2 (order, 'currency_pair_id', 'currency_pair_name'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (order, 'timestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'initial_amount'); - const filled = this.safeFloat (order, 'processed_amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'initial_amount'); + const filled = this.safeNumber (order, 'processed_amount'); let remaining = undefined; let cost = undefined; if (filled !== undefined) { @@ -917,7 +910,7 @@ module.exports = class stex extends Exchange { 'order': id, }); } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); const result = { 'info': order, 'id': id, @@ -948,7 +941,7 @@ module.exports = class stex extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'amount'); + const feeCost = this.safeNumber (fees[i], 'amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1532,13 +1525,13 @@ module.exports = class stex extends Exchange { code = currency['code']; } const type = ('deposit_status_id' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeStringLower (transaction, 'status')); const timestamp = this.safeTimestamp2 (transaction, 'timestamp', 'created_ts'); const updated = this.safeTimestamp (transaction, 'updated_ts'); const txid = this.safeString (transaction, 'txid'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'fee_currency_id', 'deposit_fee_currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1774,8 +1767,8 @@ module.exports = class stex extends Exchange { for (let i = 0; i < data.length; i++) { const id = this.safeString (data[i], 'id'); const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (data[i], 'withdrawal_fee_const'); - depositFees[code] = this.safeFloat (data[i], 'deposit_fee_const'); + withdrawFees[code] = this.safeNumber (data[i], 'withdrawal_fee_const'); + depositFees[code] = this.safeNumber (data[i], 'deposit_fee_const'); } return { 'withdraw': withdrawFees, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/Exchange/test.ticker.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/Exchange/test.ticker.js index 7d91ea0ba..201873531 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/Exchange/test.ticker.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/Exchange/test.ticker.js @@ -74,6 +74,7 @@ module.exports = (exchange, ticker, method, symbol) => { if (![ + 'bybit', 'coinmarketcap', 'xbtce', 'coss', diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/functions/test.number.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/functions/test.number.js index f2e5eedd3..23e9f7926 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/functions/test.number.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/functions/test.number.js @@ -1,6 +1,7 @@ 'use strict' const { numberToString, decimalToPrecision, ROUND, TRUNCATE, DECIMAL_PLACES, TICK_SIZE, PAD_WITH_ZERO, SIGNIFICANT_DIGITS, toWei, fromWei } = require ('../../../../ccxt'); +const Precise = require ('../../../base/Precise') const assert = require ('assert'); // ---------------------------------------------------------------------------- @@ -287,3 +288,58 @@ assert (decimalToPrecision ('1602000000000000000000', TRUNCATE, 3, SIGNIFICANT_D // throws (() => // decimalToPrecision ('0.01', TRUNCATE, -1, TICK_SIZE), // "TICK_SIZE cant be used with negative numPrecisionDigits") + +// ---------------------------------------------------------------------------- + +const w = '-1.123e-6'; +const x = '0.00000002'; +const y = '69696900000'; +const z = '0'; +const a = '1e8'; + +assert (Precise.stringMul (x, y) === '1393.938'); +assert (Precise.stringMul (y, x) === '1393.938'); +assert (Precise.stringAdd (x, y) === '69696900000.00000002'); +assert (Precise.stringAdd (y, x) === '69696900000.00000002'); +assert (Precise.stringSub (x, y) === '-69696899999.99999998'); +assert (Precise.stringSub (y, x) === '69696899999.99999998'); +assert (Precise.stringDiv (x, y, 1) === '0'); +assert (Precise.stringDiv (x, y) === '0'); +assert (Precise.stringDiv (x, y, 19) === '0.0000000000000000002'); +assert (Precise.stringDiv (x, y, 20) === '0.00000000000000000028'); +assert (Precise.stringDiv (x, y, 21) === '0.000000000000000000286'); +assert (Precise.stringDiv (x, y, 22) === '0.0000000000000000002869'); +assert (Precise.stringDiv (y, x) === '3484845000000000000'); + +assert (Precise.stringMul (x, w) === '-0.00000000000002246'); +assert (Precise.stringMul (w, x) === '-0.00000000000002246'); +assert (Precise.stringAdd (x, w) === '-0.000001103'); +assert (Precise.stringAdd (w, x) === '-0.000001103'); +assert (Precise.stringSub (x, w) === '0.000001143'); +assert (Precise.stringSub (w, x) === '-0.000001143'); +assert (Precise.stringDiv (x, w) === '-0.017809439002671415'); +assert (Precise.stringDiv (w, x) === '-56.15'); + +assert (Precise.stringMul (z, w) === '0'); +assert (Precise.stringMul (z, x) === '0'); +assert (Precise.stringMul (z, y) === '0'); +assert (Precise.stringMul (w, z) === '0'); +assert (Precise.stringMul (x, z) === '0'); +assert (Precise.stringMul (y, z) === '0'); +assert (Precise.stringAdd (z, w) === '-0.000001123'); +assert (Precise.stringAdd (z, x) === '0.00000002'); +assert (Precise.stringAdd (z, y) === '69696900000'); +assert (Precise.stringAdd (w, z) === '-0.000001123'); +assert (Precise.stringAdd (x, z) === '0.00000002'); +assert (Precise.stringAdd (y, z) === '69696900000'); + +assert (Precise.stringMul (x, a) === '2'); +assert (Precise.stringMul (a, x) === '2'); +assert (Precise.stringMul (y, a) === '6969690000000000000'); +assert (Precise.stringMul (a, y) === '6969690000000000000'); +assert (Precise.stringDiv (y, a) === '696.969'); +assert (Precise.stringDiv (y, a, -1) === '690'); +assert (Precise.stringDiv (y, a, 0) === '696'); +assert (Precise.stringDiv (y, a, 1) === '696.9'); +assert (Precise.stringDiv (y, a, 2) === '696.96'); +assert (Precise.stringDiv (a, y) === '0.001434784043479695'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/test.base.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/test.base.js index 0eb7fcffa..6068fa10a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/test.base.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/test/base/test.base.js @@ -167,7 +167,7 @@ describe ('ccxt base code', () => { const exchange = new Exchange ({ 'id': 'mock' }) const propsSeenBefore = index ( - ["isNode", "empty", "keys", "values", "extend", "clone", "index", "ordered", "unique", "keysort", "indexBy", "groupBy", "filterBy", "sortBy", "flatten", "pluck", "omit", "sum", "deepExtend", "uuid", "unCamelCase", "capitalize", "isNumber", "isArray", "isObject", "isString", "isStringCoercible", "isDictionary", "hasProps", "prop", "asFloat", "asInteger", "safeFloat", "safeInteger", "safeValue", "safeString", "decimal", "toFixed", "truncate", "truncateToString", "precisionFromString", "stringToBinary", "stringToBase64", "base64ToBinary", "base64ToString", "binaryToString", "binaryConcat", "urlencode", "rawencode", "urlencodeBase64", "hash", "hmac", "jwt", "time", "setTimeout_safe", "sleep", "TimedOut", "timeout", "throttle", "json", "unjson", "aggregate", "is_node", "index_by", "group_by", "filter_by", "sort_by", "deep_extend", "un_camel_case", "is_number", "is_array", "is_object", "is_string", "is_string_coercible", "is_dictionary", "has_props", "as_float", "as_integer", "safe_float", "safe_integer", "safe_value", "safe_string", "to_fixed", "truncate_to_string", "precision_from_string", "string_to_binary", "string_to_base64", "utf16To_base64", "base64To_binary", "base64To_string", "binary_to_string", "binary_concat", "urlencode_base64", "set_timeout_safe", "Timed_out", "encode", "decode", "userAgents", "headers", "proxy", "origin", "iso8601", "parse8601", "milliseconds", "microseconds", "seconds", "id", "enableRateLimit", "rateLimit", "parseJsonResponse", "substituteCommonCurrencyCodes", "parseBalanceFromOpenOrders", "verbose", "debug", "journal", "userAgent", "twofa", "timeframes", "hasPublicAPI", "hasPrivateAPI", "hasCORS", "hasDeposit", "hasFetchBalance", "hasFetchClosedOrders", "hasFetchCurrencies", "hasFetchMyTrades", "hasFetchOHLCV", "hasFetchOpenOrders", "hasFetchOrder", "hasFetchOrderBook", "hasFetchOrders", "hasFetchTicker", "hasFetchTickers", "hasFetchBidsAsks", "hasFetchTrades", "hasWithdraw", "hasCreateOrder", "hasCancelOrder", "apiKey", "secret", "uid", "login", "password", "requiredCredentials", "exceptions", "balance", "orderbooks", "tickers", "fees", "orders", "trades", "currencies", "last_http_response", "last_json_response", "arrayConcat", "market_id", "market_ids", "array_concat", "implode_params", "extract_params", "fetch_balance", "fetch_free_balance", "fetch_used_balance","fetch_total_balance", "fetch_l2_order_book", "fetch_order_book", "fetch_bids_asks", "fetch_tickers", "fetch_ticker", "fetch_trades", "fetch_order", "fetch_orders", "fetch_open_orders", "fetch_closed_orders", "fetch_order_status", "fetch_markets", "load_markets", "set_markets", "parse_balance", "parse_bid_ask", "parse_bids_asks", "parse_order_book", "parse_trades", "parse_orders", "parse_ohlcv", "parse_ohlcvs", "edit_limit_buy_order", "edit_limit_sell_order", "edit_limit_order", "edit_order", "create_limit_buy_order", "create_limit_sell_order", "create_market_buy_order", "create_market_sell_order", "create_order", "calculate_fee", "common_currency_code", "price_to_precision", "amount_to_precision", "amount_to_string", "fee_to_precision", "cost_to_precision", "constructor", "getMarket", "describe", "defaults", "nonce", "encodeURIComponent", "checkRequiredCredentials", "initRestRateLimiter", "defineRestApi", "fetch", "fetch2", "request", "handleErrors", "defaultErrorHandler", "handleRestErrors", "handleRestResponse", "setMarkets", "loadMarkets", "fetchBidsAsks", "fetchTickers", "fetchOrder", "fetchOrders", "fetchOpenOrders", "fetchClosedOrders", "fetchMyTrades", "fetchCurrencies", "fetchMarkets", "fetchOrderStatus", "account", "commonCurrencyCode", "currency", "market", "marketId", "marketIds", "symbol", "extractParams", "implodeParams", "url", "parseBidAsk", "parseBidsAsks", "fetchL2OrderBook", "parseOrderBook", "parseBalance", "fetchPartialBalance", "fetchFreeBalance", "fetchUsedBalance", "fetchTotalBalance", "filterBySinceLimit", "parseTrades", "parseOrders", "filterOrdersBySymbol", "parseOHLCV", "parseOHLCVs", "editLimitBuyOrder", "editLimitSellOrder", "editLimitOrder", "editOrder", "createLimitBuyOrder", "createLimitSellOrder", "createMarketBuyOrder", "createMarketSellOrder", "costToPrecision", "priceToPrecision", "amountToPrecision", "amountToLots", "feeToPrecision", "calculateFee", "Ymd", "YmdHMS"] + ["isNode", "empty", "keys", "values", "extend", "clone", "index", "ordered", "unique", "keysort", "indexBy", "groupBy", "filterBy", "sortBy", "flatten", "pluck", "omit", "sum", "deepExtend", "uuid", "unCamelCase", "capitalize", "isNumber", "isArray", "isObject", "isString", "isStringCoercible", "isDictionary", "hasProps", "prop", "asFloat", "asInteger", "safeFloat", "safeInteger", "safeValue", "safeString", "decimal", "toFixed", "truncate", "truncateToString", "precisionFromString", "stringToBinary", "stringToBase64", "base64ToBinary", "base64ToString", "binaryToString", "binaryConcat", "urlencode", "rawencode", "urlencodeBase64", "hash", "hmac", "jwt", "time", "setTimeout_safe", "sleep", "TimedOut", "timeout", "throttle", "json", "aggregate", "is_node", "index_by", "group_by", "filter_by", "sort_by", "deep_extend", "un_camel_case", "is_number", "is_array", "is_object", "is_string", "is_string_coercible", "is_dictionary", "has_props", "as_float", "as_integer", "safe_float", "safe_integer", "safe_value", "safe_string", "to_fixed", "truncate_to_string", "precision_from_string", "string_to_binary", "string_to_base64", "utf16To_base64", "base64To_binary", "base64To_string", "binary_to_string", "binary_concat", "urlencode_base64", "set_timeout_safe", "Timed_out", "encode", "decode", "userAgents", "headers", "proxy", "origin", "iso8601", "parse8601", "milliseconds", "microseconds", "seconds", "id", "enableRateLimit", "rateLimit", "parseJsonResponse", "substituteCommonCurrencyCodes", "parseBalanceFromOpenOrders", "verbose", "debug", "journal", "userAgent", "twofa", "timeframes", "hasPublicAPI", "hasPrivateAPI", "hasCORS", "hasDeposit", "hasFetchBalance", "hasFetchClosedOrders", "hasFetchCurrencies", "hasFetchMyTrades", "hasFetchOHLCV", "hasFetchOpenOrders", "hasFetchOrder", "hasFetchOrderBook", "hasFetchOrders", "hasFetchTicker", "hasFetchTickers", "hasFetchBidsAsks", "hasFetchTrades", "hasWithdraw", "hasCreateOrder", "hasCancelOrder", "apiKey", "secret", "uid", "login", "password", "requiredCredentials", "exceptions", "balance", "orderbooks", "tickers", "fees", "orders", "trades", "currencies", "last_http_response", "last_json_response", "arrayConcat", "market_id", "market_ids", "array_concat", "implode_params", "extract_params", "fetch_balance", "fetch_free_balance", "fetch_used_balance","fetch_total_balance", "fetch_l2_order_book", "fetch_order_book", "fetch_bids_asks", "fetch_tickers", "fetch_ticker", "fetch_trades", "fetch_order", "fetch_orders", "fetch_open_orders", "fetch_closed_orders", "fetch_order_status", "fetch_markets", "load_markets", "set_markets", "parse_balance", "parse_bid_ask", "parse_bids_asks", "parse_order_book", "parse_trades", "parse_orders", "parse_ohlcv", "parse_ohlcvs", "edit_limit_buy_order", "edit_limit_sell_order", "edit_limit_order", "edit_order", "create_limit_buy_order", "create_limit_sell_order", "create_market_buy_order", "create_market_sell_order", "create_order", "calculate_fee", "common_currency_code", "price_to_precision", "amount_to_precision", "amount_to_string", "fee_to_precision", "cost_to_precision", "constructor", "getMarket", "describe", "defaults", "nonce", "encodeURIComponent", "checkRequiredCredentials", "initRestRateLimiter", "defineRestApi", "fetch", "fetch2", "request", "handleErrors", "defaultErrorHandler", "handleRestErrors", "handleRestResponse", "setMarkets", "loadMarkets", "fetchBidsAsks", "fetchTickers", "fetchOrder", "fetchOrders", "fetchOpenOrders", "fetchClosedOrders", "fetchMyTrades", "fetchCurrencies", "fetchMarkets", "fetchOrderStatus", "account", "commonCurrencyCode", "currency", "market", "marketId", "marketIds", "symbol", "extractParams", "implodeParams", "url", "parseBidAsk", "parseBidsAsks", "fetchL2OrderBook", "parseOrderBook", "parseBalance", "fetchPartialBalance", "fetchFreeBalance", "fetchUsedBalance", "fetchTotalBalance", "filterBySinceLimit", "parseTrades", "parseOrders", "filterOrdersBySymbol", "parseOHLCV", "parseOHLCVs", "editLimitBuyOrder", "editLimitSellOrder", "editLimitOrder", "editOrder", "createLimitBuyOrder", "createLimitSellOrder", "createMarketBuyOrder", "createMarketSellOrder", "costToPrecision", "priceToPrecision", "amountToPrecision", "amountToLots", "feeToPrecision", "calculateFee", "Ymd", "YmdHMS"] ) const props = index (Object.getOwnPropertyNames (exchange).concat ( diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/therock.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/therock.js index 12217e2b2..88ccb385d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/therock.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/therock.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -171,8 +172,8 @@ module.exports = class therock extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const buy_fee = this.safeFloat (market, 'buy_fee'); - const sell_fee = this.safeFloat (market, 'sell_fee'); + const buy_fee = this.safeNumber (market, 'buy_fee'); + const sell_fee = this.safeNumber (market, 'sell_fee'); let taker = Math.max (buy_fee, sell_fee); taker = taker / 100; const maker = taker; @@ -193,11 +194,11 @@ module.exports = class therock extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_quantity_offer'), + 'min': this.safeNumber (market, 'minimum_quantity_offer'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'minimum_price_offer'), + 'min': this.safeNumber (market, 'minimum_price_offer'), 'max': undefined, }, 'cost': { @@ -221,11 +222,11 @@ module.exports = class therock extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'trading_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'trading_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -244,27 +245,27 @@ module.exports = class therock extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'close'), // previous day close, if any + 'previousClose': this.safeNumber (ticker, 'close'), // previous day close, if any 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_traded'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume_traded'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -339,14 +340,11 @@ module.exports = class therock extends Exchange { const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; let feeCost = undefined; const transactions = this.safeValue (trade, 'transactions', []); @@ -356,7 +354,7 @@ module.exports = class therock extends Exchange { if (feeCost === undefined) { feeCost = 0; } - feeCost = this.sum (feeCost, this.safeFloat (feeTransactions[i], 'price')); + feeCost = this.sum (feeCost, this.safeNumber (feeTransactions[i], 'price')); } if (feeCost !== undefined) { fee = { @@ -511,7 +509,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (item, 'price'); + const amount = this.safeNumber (item, 'price'); const timestamp = this.parse8601 (this.safeString (item, 'date')); const status = 'ok'; return { @@ -743,7 +741,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'price'); + const amount = this.safeNumber (transaction, 'price'); const timestamp = this.parse8601 (this.safeString (transaction, 'date')); const status = 'ok'; // todo parse tags @@ -918,15 +916,15 @@ module.exports = class therock extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'date')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'amount_unfilled'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amount_unfilled'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let trades = this.safeValue (order, 'trades'); let cost = undefined; let average = undefined; @@ -953,7 +951,7 @@ module.exports = class therock extends Exchange { cost = 0; } } - const stopPrice = this.safeFloat (order, 'conditional_price'); + const stopPrice = this.safeNumber (order, 'conditional_price'); return { 'id': id, 'clientOrderId': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidebit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidebit.js index acf65de25..05efc673a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidebit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidebit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, OrderNotFound, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -182,11 +183,11 @@ module.exports = class tidebit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -211,15 +212,15 @@ module.exports = class tidebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'ask': this.safeFloat (ticker, 'sell'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'ask': this.safeNumber (ticker, 'sell'), 'bidVolume': undefined, 'askVolume': undefined, 'vwap': undefined, @@ -230,7 +231,7 @@ module.exports = class tidebit extends Exchange { 'percentage': undefined, 'previousClose': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -264,9 +265,14 @@ module.exports = class tidebit extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -311,11 +317,11 @@ module.exports = class tidebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -401,18 +407,12 @@ module.exports = class tidebit extends Exchange { const id = this.safeString (order, 'id'); const type = this.safeString (order, 'ord_type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const filled = this.safeFloat (order, 'executed_volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - let cost = undefined; - if (price !== undefined) { - if (filled !== undefined) { - cost = price * filled; - } - } - const average = this.safeFloat (order, 'avg_price'); - return { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const filled = this.safeNumber (order, 'executed_volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -429,12 +429,12 @@ module.exports = class tidebit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': average, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidex.js index 0988a4ad1..65c0e6d9e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/tidex.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class tidex extends Exchange { describe () { @@ -83,6 +84,7 @@ module.exports = class tidex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.1 / 100, @@ -127,19 +129,48 @@ module.exports = class tidex extends Exchange { async fetchCurrencies (params = {}) { const response = await this.webGetCurrency (params); + // + // [ + // { + // "id":2, + // "symbol":"BTC", + // "type":2, + // "name":"Bitcoin", + // "amountPoint":8, + // "depositEnable":true, + // "depositMinAmount":0.0005, + // "withdrawEnable":true, + // "withdrawFee":0.0004, + // "withdrawMinAmount":0.0005, + // "settings":{ + // "Blockchain":"https://blockchair.com/bitcoin/", + // "TxUrl":"https://blockchair.com/bitcoin/transaction/{0}", + // "AddrUrl":"https://blockchair.com/bitcoin/address/{0}", + // "ConfirmationCount":3, + // "NeedMemo":false + // }, + // "visible":true, + // "isDelisted":false + // } + // ] + // const result = {}; for (let i = 0; i < response.length; i++) { const currency = response[i]; const id = this.safeString (currency, 'symbol'); - const precision = currency['amountPoint']; + const precision = this.safeInteger (currency, 'amountPoint'); const code = this.safeCurrencyCode (id); - let active = currency['visible'] === true; - const canWithdraw = currency['withdrawEnable'] === true; - const canDeposit = currency['depositEnable'] === true; + const visible = this.safeValue (currency, 'visible'); + let active = visible === true; + const withdrawEnable = this.safeValue (currency, 'withdrawEnable'); + const depositEnable = this.safeValue (currency, 'depositEnable'); + const canWithdraw = withdrawEnable === true; + const canDeposit = depositEnable === true; if (!canWithdraw || !canDeposit) { active = false; } const name = this.safeString (currency, 'name'); + const fee = this.safeNumber (currency, 'withdrawFee'); result[code] = { 'id': id, 'code': code, @@ -149,7 +180,7 @@ module.exports = class tidex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': currency['withdrawFee'], + 'fee': fee, }, 'deposit': { 'active': canDeposit, @@ -170,11 +201,11 @@ module.exports = class tidex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawMinAmount'), + 'min': this.safeNumber (currency, 'withdrawMinAmount'), 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'depositMinAmount'), + 'min': this.safeNumber (currency, 'depositMinAmount'), 'max': undefined, }, }, @@ -184,26 +215,25 @@ module.exports = class tidex extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615861869, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":3.0, + // "min_amount":0.001, + // "max_amount":1000000.0, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.1, + // }, + // }, + // } + // const markets = response['pairs']; const keys = Object.keys (markets); const result = []; @@ -220,19 +250,20 @@ module.exports = class tidex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }, }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -241,7 +272,7 @@ module.exports = class tidex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -262,11 +293,11 @@ module.exports = class tidex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (funds, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'value'); - account['used'] = this.safeFloat (balance, 'inOrders'); + account['free'] = this.safeString (balance, 'value'); + account['used'] = this.safeString (balance, 'inOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -338,16 +369,16 @@ module.exports = class tidex extends Exchange { timestamp = undefined; } } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -356,9 +387,9 @@ module.exports = class tidex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -406,16 +437,19 @@ module.exports = class tidex extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const orderId = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = 'limit'; // all trades are still limit trades let takerOrMaker = undefined; let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -434,12 +468,6 @@ module.exports = class tidex extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': orderId, @@ -495,17 +523,18 @@ module.exports = class tidex extends Exchange { let status = 'open'; let filled = 0.0; let remaining = amount; - if ('return' in response) { - id = this.safeString (response['return'], 'order_id'); + const returnResult = this.safeValue (response, 'return'); + if (returnResult !== undefined) { + id = this.safeString (returnResult, 'order_id'); if (id === '0') { - id = this.safeString (response['return'], 'init_order_id'); + id = this.safeString (returnResult, 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (returnResult, 'received', filled); + remaining = this.safeNumber (returnResult, 'remains', amount); } const timestamp = this.milliseconds (); - return { + return this.safeOrder ({ 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -515,7 +544,7 @@ module.exports = class tidex extends Exchange { 'type': type, 'side': side, 'price': price, - 'cost': price * filled, + 'cost': undefined, 'amount': amount, 'remaining': remaining, 'filled': filled, @@ -525,7 +554,7 @@ module.exports = class tidex extends Exchange { 'clientOrderId': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -554,23 +583,15 @@ module.exports = class tidex extends Exchange { const symbol = this.safeSymbol (marketId, market); let remaining = undefined; let amount = undefined; - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; + const price = this.safeNumber (order, 'rate'); if ('start_amount' in order) { - amount = this.safeFloat (order, 'start_amount'); - remaining = this.safeFloat (order, 'amount'); + amount = this.safeNumber (order, 'start_amount'); + remaining = this.safeNumber (order, 'amount'); } else { - remaining = this.safeFloat (order, 'amount'); - } - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } + remaining = this.safeNumber (order, 'amount'); } const fee = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -584,15 +605,15 @@ module.exports = class tidex extends Exchange { 'side': this.safeString (order, 'type'), 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/timex.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/timex.js index 4c71ac4ff..227f97553 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/timex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/timex.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, PermissionDenied, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, RateLimitExceeded, NotSupported, BadRequest, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class timex extends Exchange { describe () { @@ -450,11 +451,11 @@ module.exports = class timex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'totalBalance'); - account['used'] = this.safeFloat (balance, 'lockedBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + account['used'] = this.safeString (balance, 'lockedBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -815,7 +816,7 @@ module.exports = class timex extends Exchange { const result = this.safeValue (response, 0, {}); return { 'info': response, - 'maker': this.safeFloat (result, 'fee'), + 'maker': this.safeNumber (result, 'fee'), 'taker': undefined, }; } @@ -852,18 +853,18 @@ module.exports = class timex extends Exchange { 'amount': this.precisionFromString (this.safeString (market, 'quantityIncrement')), 'price': this.precisionFromString (this.safeString (market, 'tickSize')), }; - const amountIncrement = this.safeFloat (market, 'quantityIncrement'); - const minBase = this.safeFloat (market, 'baseMinSize'); + const amountIncrement = this.safeNumber (market, 'quantityIncrement'); + const minBase = this.safeNumber (market, 'baseMinSize'); const minAmount = Math.max (amountIncrement, minBase); - const priceIncrement = this.safeFloat (market, 'tickSize'); - const minCost = this.safeFloat (market, 'quoteMinSize'); + const priceIncrement = this.safeNumber (market, 'tickSize'); + const minCost = this.safeNumber (market, 'quoteMinSize'); const limits = { 'amount': { 'min': minAmount, 'max': undefined }, 'price': { 'min': priceIncrement, 'max': undefined }, 'cost': { 'min': Math.max (minCost, minAmount * priceIncrement), 'max': undefined }, }; - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); return { 'id': id, 'symbol': symbol, @@ -924,7 +925,7 @@ module.exports = class timex extends Exchange { const name = this.safeString (currency, 'name'); const precision = this.safeInteger (currency, 'decimals'); const active = this.safeValue (currency, 'active'); - // const fee = this.safeFloat (currency, 'withdrawalFee'); + // const fee = this.safeNumber (currency, 'withdrawalFee'); const feeString = this.safeString (currency, 'withdrawalFee'); const tradeDecimals = this.safeInteger (currency, 'tradeDecimals'); let fee = undefined; @@ -961,14 +962,6 @@ module.exports = class timex extends Exchange { }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // // { @@ -988,8 +981,8 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '/'); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -1005,11 +998,11 @@ module.exports = class timex extends Exchange { 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -1019,8 +1012,8 @@ module.exports = class timex extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'volumeQuote'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volumeQuote'), }; } @@ -1039,23 +1032,27 @@ module.exports = class timex extends Exchange { // fetchMyTrades, fetchOrder (private) // // { - // "fee": "0.3", - // "id": 100, - // "makerOrTaker": "MAKER", - // "makerOrderId": "string", - // "price": "0.017", - // "quantity": "0.3", + // "id": "7613414", + // "makerOrderId": "0x8420af060722f560098f786a2894d4358079b6ea5d14b395969ed77bc87a623a", + // "takerOrderId": "0x1235ef158a361815b54c9988b6241c85aedcbc1fe81caf8df8587d5ab0373d1a", + // "symbol": "LTCUSDT", // "side": "BUY", - // "symbol": "TIMEETH", - // "takerOrderId": "string", - // "timestamp": "2019-12-08T04:54:11.171Z" - // } + // "quantity": "0.2", + // "fee": "0.22685", + // "feeToken": "USDT", + // "price": "226.85", + // "makerOrTaker": "TAKER", + // "timestamp": "2021-04-09T15:39:45.608" + // } // const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeStringLower2 (trade, 'direction', 'side'); const takerOrMaker = this.safeStringLower (trade, 'makerOrTaker'); @@ -1064,18 +1061,14 @@ module.exports = class timex extends Exchange { orderId = this.safeString (trade, takerOrMaker + 'OrderId'); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); + const feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'feeToken')); if (feeCost !== undefined) { - const feeCurrency = (market === undefined) ? undefined : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrency, }; } - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = this.costToPrecision (symbol, amount * price); - } return { 'info': trade, 'id': id, @@ -1107,11 +1100,11 @@ module.exports = class timex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1142,14 +1135,12 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'filledQuantity'); - const canceledQuantity = this.safeFloat (order, 'cancelledQuantity'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'filledQuantity'); + const canceledQuantity = this.safeNumber (order, 'cancelledQuantity'); let status = undefined; if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0.0); if (filled >= amount) { status = 'closed'; } else if ((canceledQuantity !== undefined) && (canceledQuantity > 0)) { @@ -1158,30 +1149,19 @@ module.exports = class timex extends Exchange { status = 'open'; } } - const cost = parseFloat (this.costToPrecision (symbol, price * filled)); - const fee = undefined; - let lastTradeTimestamp = undefined; - let trades = undefined; - const rawTrades = this.safeValue (order, 'trades'); - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'order': id, - }); - } - if (trades !== undefined) { - const numTrades = trades.length; - if (numTrades > 0) { - lastTradeTimestamp = trades[numTrades - 1]['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'order': id, + 'type': type, + }); const clientOrderId = this.safeString (order, 'clientOrderId'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': undefined, @@ -1190,14 +1170,14 @@ module.exports = class timex extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/upbit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/upbit.js index 829aa6586..890c30126 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/upbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/upbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, PermissionDenied, AddressPending } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -229,9 +230,9 @@ module.exports = class upbit extends Exchange { } else if ((locked !== undefined) && locked) { active = false; } - const maxOnetimeWithdrawal = this.safeFloat (withdrawLimits, 'onetime'); - const maxDailyWithdrawal = this.safeFloat (withdrawLimits, 'daily', maxOnetimeWithdrawal); - const remainingDailyWithdrawal = this.safeFloat (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); + const maxOnetimeWithdrawal = this.safeNumber (withdrawLimits, 'onetime'); + const maxDailyWithdrawal = this.safeNumber (withdrawLimits, 'daily', maxOnetimeWithdrawal); + const remainingDailyWithdrawal = this.safeNumber (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); let maxWithdrawLimit = undefined; if (remainingDailyWithdrawal > 0) { maxWithdrawLimit = remainingDailyWithdrawal; @@ -247,11 +248,11 @@ module.exports = class upbit extends Exchange { 'code': code, 'name': code, 'active': active, - 'fee': this.safeFloat (currencyInfo, 'withdraw_fee'), + 'fee': this.safeNumber (currencyInfo, 'withdraw_fee'), 'precision': precision, 'limits': { 'withdraw': { - 'min': this.safeFloat (withdrawLimits, 'minimum'), + 'min': this.safeNumber (withdrawLimits, 'minimum'), 'max': maxWithdrawLimit, }, }, @@ -314,8 +315,8 @@ module.exports = class upbit extends Exchange { }; const state = this.safeString (marketInfo, 'state'); const active = (state === 'active'); - const bidFee = this.safeFloat (response, 'bid_fee'); - const askFee = this.safeFloat (response, 'ask_fee'); + const bidFee = this.safeNumber (response, 'bid_fee'); + const askFee = this.safeNumber (response, 'ask_fee'); const fee = Math.max (bidFee, askFee); return { 'info': response, @@ -331,7 +332,7 @@ module.exports = class upbit extends Exchange { 'taker': fee, 'limits': { 'amount': { - 'min': this.safeFloat (ask, 'min_total'), + 'min': this.safeNumber (ask, 'min_total'), 'max': undefined, }, 'price': { @@ -339,8 +340,8 @@ module.exports = class upbit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (bid, 'min_total'), - 'max': this.safeFloat (marketInfo, 'max_total'), + 'min': this.safeNumber (bid, 'min_total'), + 'max': this.safeNumber (marketInfo, 'max_total'), }, }, }; @@ -379,8 +380,8 @@ module.exports = class upbit extends Exchange { 'price': 8, }; const active = true; - const makerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); - const takerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); + const makerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); + const takerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); result.push ({ 'id': id, 'symbol': symbol, @@ -433,11 +434,11 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { @@ -540,30 +541,30 @@ module.exports = class upbit extends Exchange { const timestamp = this.safeInteger (ticker, 'trade_timestamp'); const marketId = this.safeString2 (ticker, 'market', 'code'); const symbol = this.safeSymbol (marketId, market, '-'); - const previous = this.safeFloat (ticker, 'prev_closing_price'); - const last = this.safeFloat (ticker, 'trade_price'); - const change = this.safeFloat (ticker, 'signed_change_price'); - const percentage = this.safeFloat (ticker, 'signed_change_rate'); + const previous = this.safeNumber (ticker, 'prev_closing_price'); + const last = this.safeNumber (ticker, 'trade_price'); + const change = this.safeNumber (ticker, 'signed_change_price'); + const percentage = this.safeNumber (ticker, 'signed_change_rate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price'), - 'low': this.safeFloat (ticker, 'low_price'), + 'high': this.safeNumber (ticker, 'high_price'), + 'low': this.safeNumber (ticker, 'low_price'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'opening_price'), + 'open': this.safeNumber (ticker, 'opening_price'), 'close': last, 'last': last, 'previousClose': previous, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'acc_trade_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'acc_trade_price_24h'), + 'baseVolume': this.safeNumber (ticker, 'acc_trade_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'acc_trade_price_24h'), 'info': ticker, }; } @@ -670,15 +671,13 @@ module.exports = class upbit extends Exchange { } else if (askOrBid === 'bid') { side = 'buy'; } - let cost = this.safeFloat (trade, 'funds'); - const price = this.safeFloat2 (trade, 'trade_price', 'price'); - const amount = this.safeFloat2 (trade, 'trade_volume', 'volume'); + let cost = this.safeNumber (trade, 'funds'); + const priceString = this.safeString2 (trade, 'trade_price', 'price'); + const amountString = this.safeString2 (trade, 'trade_volume', 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString2 (trade, 'market', 'code'); market = this.safeMarket (marketId, market); @@ -773,11 +772,11 @@ module.exports = class upbit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'candle_date_time_utc')), - this.safeFloat (ohlcv, 'opening_price'), - this.safeFloat (ohlcv, 'high_price'), - this.safeFloat (ohlcv, 'low_price'), - this.safeFloat (ohlcv, 'trade_price'), - this.safeFloat (ohlcv, 'candle_acc_trade_volume'), // base volume + this.safeNumber (ohlcv, 'opening_price'), + this.safeNumber (ohlcv, 'high_price'), + this.safeNumber (ohlcv, 'low_price'), + this.safeNumber (ohlcv, 'trade_price'), + this.safeNumber (ohlcv, 'candle_acc_trade_volume'), // base volume ]; } @@ -1046,7 +1045,7 @@ module.exports = class upbit extends Exchange { // } // const id = this.safeString (transaction, 'uuid'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = undefined; // not present in the data structure received from the exchange const tag = undefined; // not present in the data structure received from the exchange const txid = this.safeString (transaction, 'txid'); @@ -1059,7 +1058,7 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -1144,10 +1143,10 @@ module.exports = class upbit extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const status = this.parseOrderStatus (this.safeString (order, 'state')); let lastTradeTimestamp = undefined; - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - const filled = this.safeFloat (order, 'executed_volume'); + let price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const filled = this.safeNumber (order, 'executed_volume'); let cost = undefined; if (type === 'price') { type = 'market'; @@ -1156,7 +1155,7 @@ module.exports = class upbit extends Exchange { } let average = undefined; let fee = undefined; - let feeCost = this.safeFloat (order, 'paid_fee'); + let feeCost = this.safeNumber (order, 'paid_fee'); const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); let trades = this.safeValue (order, 'trades', []); @@ -1179,7 +1178,7 @@ module.exports = class upbit extends Exchange { cost = this.sum (cost, trade['cost']); if (getFeesFromTrades) { const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); + const tradeFeeCost = this.safeNumber (tradeFee, 'cost'); if (tradeFeeCost !== undefined) { feeCost = this.sum (feeCost, tradeFeeCost); } @@ -1321,16 +1320,6 @@ module.exports = class upbit extends Exchange { return this.parseOrder (response); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetDepositsCoinAddresses (params); diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vaultoro.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vaultoro.js deleted file mode 100644 index abc1ba387..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vaultoro.js +++ /dev/null @@ -1,203 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); - -// --------------------------------------------------------------------------- - -module.exports = class vaultoro extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'vaultoro', - 'name': 'Vaultoro', - 'countries': [ 'CH' ], - 'rateLimit': 1000, - 'version': '1', - 'has': { - 'CORS': true, - 'fetchMarkets': true, - 'fetchOrderBook': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'fetchTrades': true, - 'fetchTicker': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg', - 'api': 'https://api.vaultoro.com', - 'www': 'https://www.vaultoro.com', - 'doc': 'https://api.vaultoro.com', - }, - 'commonCurrencies': { - 'GLD': 'Gold', - }, - 'api': { - 'public': { - 'get': [ - 'bidandask', - 'buyorders', - 'latest', - 'latesttrades', - 'markets', - 'orderbook', - 'sellorders', - 'transactions/day', - 'transactions/hour', - 'transactions/month', - ], - }, - 'private': { - 'get': [ - 'balance', - 'mytrades', - 'orders', - ], - 'post': [ - 'buy/{symbol}/{type}', - 'cancel/{id}', - 'sell/{symbol}/{type}', - 'withdraw', - ], - }, - }, - }); - } - - async fetchMarkets (params = {}) { - const result = []; - const response = await this.publicGetMarkets (params); - const market = this.safeValue (response, 'data'); - const baseId = this.safeString (market, 'MarketCurrency'); - const quoteId = this.safeString (market, 'BaseCurrency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const id = this.safeString (market, 'MarketName'); - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'active': undefined, - 'precision': this.precision, - 'limits': this.limits, - }); - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetBalance (params); - const balances = this.safeValue (response, 'data'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency_code'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'cash'); - account['used'] = this.safeFloat (balance, 'reserved'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetOrderbook (params); - const orderbook = { - 'bids': response['data'][0]['b'], - 'asks': response['data'][1]['s'], - }; - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'Gold_Price', 'Gold_Amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'Time')); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const price = this.safeFloat (trade, 'Gold_Price'); - const amount = this.safeFloat (trade, 'Gold_Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } - return { - 'id': undefined, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': undefined, - 'side': undefined, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const response = await this.publicGetTransactionsDay (params); - return this.parseTrades (response, market, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const method = 'privatePost' + this.capitalize (side) + 'SymbolType'; - const request = { - 'symbol': market['quoteId'].toLowerCase (), - 'type': type, - 'gld': amount, - 'price': price || 1, - }; - const response = await this[method] (this.extend (request, params)); - return { - 'info': response, - 'id': response['data']['Order_ID'], - }; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - return await this.privatePostCancelId (this.extend (request, params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/'; - if (api === 'public') { - url += path; - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce (); - url += this.version + '/' + this.implodeParams (path, params); - const query = this.extend ({ - 'nonce': nonce, - 'apikey': this.apiKey, - }, this.omit (params, this.extractParams (path))); - url += '?' + this.urlencode (query); - headers = { - 'Content-Type': 'application/json', - 'X-Signature': this.hmac (this.encode (url), this.encode (this.secret)), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vcc.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vcc.js index bd3a9602d..5b182adcb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vcc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/vcc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, OrderNotFound, InvalidOrder, BadRequest, AuthenticationError, RateLimitExceeded, RequestTimeout, BadSymbol, AddressPending, PermissionDenied, InsufficientFunds } = require ('./base/errors'); const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -196,15 +197,15 @@ module.exports = class vcc extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, 'min'), + 'min': this.safeNumber (amountLimits, 'min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (priceLimits, 'min'), + 'min': this.safeNumber (priceLimits, 'min'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (costLimits, 'min'), + 'min': this.safeNumber (costLimits, 'min'), 'max': undefined, }, }, @@ -251,12 +252,12 @@ module.exports = class vcc extends Exchange { 'code': code, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': this.safeInteger (currency, 'decimal'), 'limits': { 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw'), - 'max': this.safeFloat (currency, 'max_withdraw'), + 'min': this.safeNumber (currency, 'min_withdraw'), + 'max': this.safeNumber (currency, 'max_withdraw'), }, }, }; @@ -279,8 +280,8 @@ module.exports = class vcc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } @@ -306,11 +307,11 @@ module.exports = class vcc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (data, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -328,11 +329,11 @@ module.exports = class vcc extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -421,10 +422,10 @@ module.exports = class vcc extends Exchange { // } // const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); - const open = this.safeFloat (ticker, 'open_price'); - const last = this.safeFloat (ticker, 'last_price'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); + const open = this.safeNumber (ticker, 'open_price'); + const last = this.safeNumber (ticker, 'last_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -441,11 +442,11 @@ module.exports = class vcc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -559,17 +560,17 @@ module.exports = class vcc extends Exchange { } market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'base_volume', 'quantity'); - let cost = this.safeFloat2 (trade, 'quote_volume', 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'base_volume', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber2 (trade, 'quote_volume', 'amount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const side = this.safeString2 (trade, 'type', 'trade_type'); const id = this.safeString2 (trade, 'trade_id', 'id'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -754,7 +755,7 @@ module.exports = class vcc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -762,7 +763,7 @@ module.exports = class vcc extends Exchange { const txid = this.safeString (transaction, 'transaction_id'); const tag = this.safeString (transaction, 'destination_tag'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1007,46 +1008,27 @@ module.exports = class vcc extends Exchange { const marketId = baseId + '_' + quoteId; market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'executed_quantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - let cost = this.safeFloat (order, 'ceiling'); + const cost = this.safeNumber (order, 'ceiling'); const id = this.safeString (order, 'id'); - let average = undefined; - let price = this.safeFloat (order, 'price'); - // in case of market order - if (!price) { - price = this.safeFloat (order, 'executed_price'); - average = price; - } - let remaining = this.safeFloat (order, 'remaining'); - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if (filled !== undefined) { - if ((amount !== undefined) && (remaining === undefined)) { - remaining = Math.max (0, amount - filled); - } - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((average === undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'executed_price'); + const remaining = this.safeNumber (order, 'remaining'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'trade_type'); const fee = { 'currency': market['quote'], - 'cost': this.safeFloat (order, 'fee'), - 'rate': this.safeFloat (order, 'fee_rate'), + 'cost': this.safeNumber (order, 'fee'), + 'rate': this.safeNumber (order, 'fee_rate'), }; let lastTradeTimestamp = undefined; if (updated !== created) { lastTradeTimestamp = updated; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': id, 'timestamp': created, @@ -1068,7 +1050,7 @@ module.exports = class vcc extends Exchange { 'fee': fee, 'trades': undefined, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/wavesexchange.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/wavesexchange.js index 139780062..bd422c073 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/wavesexchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/wavesexchange.js @@ -565,13 +565,13 @@ module.exports = class wavesexchange extends Exchange { symbol = market['symbol']; } const data = this.safeValue (ticker, 'data', {}); - const last = this.safeFloat (data, 'lastPrice'); - const low = this.safeFloat (data, 'low'); - const high = this.safeFloat (data, 'high'); - const vwap = this.safeFloat (data, 'weightedAveragePrice'); - const baseVolume = this.safeFloat (data, 'volume'); - const quoteVolume = this.safeFloat (data, 'quoteVolume'); - const open = this.safeValue (data, 'firstPrice'); + const last = this.safeNumber (data, 'lastPrice'); + const low = this.safeNumber (data, 'low'); + const high = this.safeNumber (data, 'high'); + const vwap = this.safeNumber (data, 'weightedAveragePrice'); + const baseVolume = this.safeNumber (data, 'volume'); + const quoteVolume = this.safeNumber (data, 'quoteVolume'); + const open = this.safeNumber (data, 'firstPrice'); let change = undefined; let average = undefined; let percentage = undefined; @@ -725,11 +725,11 @@ module.exports = class wavesexchange extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.parse8601 (this.safeString (data, 'time')), - this.safeFloat (data, 'open'), - this.safeFloat (data, 'high'), - this.safeFloat (data, 'low'), - this.safeFloat (data, 'close'), - this.safeFloat (data, 'volume', 0), + this.safeNumber (data, 'open'), + this.safeNumber (data, 'high'), + this.safeNumber (data, 'low'), + this.safeNumber (data, 'close'), + this.safeNumber (data, 'volume', 0), ]; } @@ -944,7 +944,7 @@ module.exports = class wavesexchange extends Exchange { } if (matcherFee === undefined) { const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8); - const rate = this.safeFloat (rates, matcherFeeAssetId); + const rate = this.safeNumber (rates, matcherFeeAssetId); const code = this.safeCurrencyCode (matcherFeeAssetId); const currency = this.currency (code); const newPrecison = Math.pow (10, wavesPrecision - currency['precision']); @@ -1354,7 +1354,7 @@ module.exports = class wavesexchange extends Exchange { const issueTransaction = this.safeValue (entry, 'issueTransaction'); const decimals = this.safeInteger (issueTransaction, 'decimals'); const currencyId = this.safeString (entry, 'assetId'); - const balance = this.safeFloat (entry, 'balance'); + const balance = this.safeNumber (entry, 'balance'); let code = undefined; if (currencyId in this.currencies_by_id) { code = this.safeCurrencyCode (currencyId); @@ -1384,7 +1384,7 @@ module.exports = class wavesexchange extends Exchange { if (!(code in result)) { result[code] = this.account (); } - const amount = this.safeFloat (reservedBalance, currencyId); + const amount = this.safeNumber (reservedBalance, currencyId); result[code]['used'] = this.currencyFromPrecision (code, amount); } const wavesRequest = { @@ -1397,7 +1397,7 @@ module.exports = class wavesexchange extends Exchange { // "balance": 909085978 // } result['WAVES'] = this.safeValue (result, 'WAVES', {}); - result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeFloat (wavesTotal, 'balance')); + result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeNumber (wavesTotal, 'balance')); const codes = Object.keys (result); for (let i = 0; i < codes.length; i++) { const code = codes[i]; @@ -1489,8 +1489,8 @@ module.exports = class wavesexchange extends Exchange { const datetime = this.safeString (data, 'timestamp'); const timestamp = this.parse8601 (datetime); const id = this.safeString (data, 'id'); - const price = this.safeFloat (data, 'price'); - const amount = this.safeFloat (data, 'amount'); + const price = this.safeNumber (data, 'price'); + const amount = this.safeNumber (data, 'amount'); const order1 = this.safeValue (data, 'order1'); const order2 = this.safeValue (data, 'order2'); let order = undefined; @@ -1514,7 +1514,7 @@ module.exports = class wavesexchange extends Exchange { cost = price * amount; } const fee = { - 'cost': this.safeFloat (data, 'fee'), + 'cost': this.safeNumber (data, 'fee'), 'currency': this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES')), }; return { @@ -1596,7 +1596,7 @@ module.exports = class wavesexchange extends Exchange { const withdrawAddress = await this.privateGetWithdrawAddressesCurrencyAddress (withdrawAddressRequest); const currency = this.safeValue (withdrawAddress, 'currency'); const allowedAmount = this.safeValue (currency, 'allowed_amount'); - const minimum = this.safeFloat (allowedAmount, 'min'); + const minimum = this.safeNumber (allowedAmount, 'min'); if (amount <= minimum) { throw new BadRequest (this.id + ' ' + code + ' withdraw failed, amount ' + amount.toString () + ' must be greater than the minimum allowed amount of ' + minimum.toString ()); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/whitebit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/whitebit.js index 9e4418141..769cd5b8b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/whitebit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/whitebit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeNotAvailable, ExchangeError, DDoSProtection, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,7 +165,7 @@ module.exports = class whitebit extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -172,7 +173,7 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minTotal'), + 'min': this.safeNumber (market, 'minTotal'), 'max': undefined, }, }, @@ -237,8 +238,8 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -250,8 +251,8 @@ module.exports = class whitebit extends Exchange { const response = await this.publicV2GetFee (params); const fees = this.safeValue (response, 'result'); return { - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), }; } @@ -321,8 +322,8 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let change = undefined; if (percentage !== undefined) { change = this.numberToString (percentage * 0.01); @@ -331,22 +332,22 @@ module.exports = class whitebit extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'deal'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'deal'), 'info': ticker, }; } @@ -514,8 +515,11 @@ module.exports = class whitebit extends Exchange { } else { timestamp = parseInt (timestamp * 1000); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'volume'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'volume'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const id = this.safeString2 (trade, 'id', 'tradeId'); let side = this.safeString (trade, 'type'); if (side === undefined) { @@ -526,10 +530,6 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined && price !== undefined) { - cost = amount * price; - } return { 'info': trade, 'timestamp': timestamp, @@ -599,11 +599,11 @@ module.exports = class whitebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 5), // volume ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xbtce.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xbtce.js index e0d137f67..c8cabae42 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xbtce.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xbtce.js @@ -152,14 +152,13 @@ module.exports = class xbtce extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'FreeAmount'), - 'used': this.safeFloat (balance, 'LockedAmount'), - 'total': this.safeFloat (balance, 'Amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'FreeAmount'); + account['used'] = this.safeString (balance, 'LockedAmount'); + account['total'] = this.safeString (balance, 'Amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -271,11 +270,11 @@ module.exports = class xbtce extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeInteger (ohlcv, 'Timestamp'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xena.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xena.js index 2facd429b..e55a5332b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xena.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/xena.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, InsufficientFunds, InvalidAddress, BadSymbol, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class xena extends Exchange { describe () { @@ -277,8 +278,8 @@ module.exports = class xena extends Exchange { 'price': pricePrecision, 'amount': 0, }; - const maxCost = this.safeFloat (market, 'maxOrderQty'); - const minCost = this.safeFloat (market, 'minOrderQuantity'); + const maxCost = this.safeNumber (market, 'maxOrderQty'); + const minCost = this.safeNumber (market, 'minOrderQuantity'); const limits = { 'amount': { 'min': undefined, @@ -363,7 +364,7 @@ module.exports = class xena extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (withdraw, 'commission'), + 'fee': this.safeNumber (withdraw, 'commission'), 'precision': precision, 'limits': { 'amount': { @@ -379,7 +380,7 @@ module.exports = class xena extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'minAmount'), + 'min': this.safeNumber (withdraw, 'minAmount'), 'max': undefined, }, }, @@ -407,8 +408,8 @@ module.exports = class xena extends Exchange { const timestamp = this.milliseconds (); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPx'); - const open = this.safeFloat (ticker, 'firstPx'); + const last = this.safeNumber (ticker, 'lastPx'); + const open = this.safeNumber (ticker, 'firstPx'); let percentage = undefined; let change = undefined; let average = undefined; @@ -419,18 +420,18 @@ module.exports = class xena extends Exchange { percentage = change / open * 100; } } - const buyVolume = this.safeFloat (ticker, 'buyVolume'); - const sellVolume = this.safeFloat (ticker, 'sellVolume'); + const buyVolume = this.safeNumber (ticker, 'buyVolume'); + const sellVolume = this.safeNumber (ticker, 'sellVolume'); const baseVolume = this.sum (buyVolume, sellVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPx'), - 'low': this.safeFloat (ticker, 'lowPx'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'highPx'), + 'low': this.safeNumber (ticker, 'lowPx'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -607,11 +608,11 @@ module.exports = class xena extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onHold'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onHold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTrade (trade, market = undefined) { @@ -665,20 +666,17 @@ module.exports = class xena extends Exchange { const orderId = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat2 (trade, 'lastPx', 'mdEntryPx'); - const amount = this.safeFloat2 (trade, 'lastQty', 'mdEntrySize'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'lastPx', 'mdEntryPx'); + const amountString = this.safeString2 (trade, 'lastQty', 'mdEntrySize'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (trade, 'commRate'); + const feeRate = this.safeNumber (trade, 'commRate'); fee = { 'cost': feeCost, 'rate': feeRate, @@ -793,15 +791,15 @@ module.exports = class xena extends Exchange { // const transactTime = this.safeInteger (ohlcv, 'transactTime'); const timestamp = parseInt (transactTime / 1000000); - const buyVolume = this.safeFloat (ohlcv, 'buyVolume'); - const sellVolume = this.safeFloat (ohlcv, 'sellVolume'); + const buyVolume = this.safeNumber (ohlcv, 'buyVolume'); + const sellVolume = this.safeNumber (ohlcv, 'sellVolume'); const volume = this.sum (buyVolume, sellVolume); return [ timestamp, - this.safeFloat (ohlcv, 'firstPx'), - this.safeFloat (ohlcv, 'highPx'), - this.safeFloat (ohlcv, 'lowPx'), - this.safeFloat (ohlcv, 'lastPx'), + this.safeNumber (ohlcv, 'firstPx'), + this.safeNumber (ohlcv, 'highPx'), + this.safeNumber (ohlcv, 'lowPx'), + this.safeNumber (ohlcv, 'lastPx'), volume, ]; } @@ -926,11 +924,10 @@ module.exports = class xena extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); - let cost = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); let side = this.safeStringLower (order, 'side'); if (side === '1') { side = 'buy'; @@ -947,12 +944,7 @@ module.exports = class xena extends Exchange { } else if (type === '4') { type = 'stop-limit'; } - if (cost === undefined) { - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -967,14 +959,14 @@ module.exports = class xena extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1027,7 +1019,7 @@ module.exports = class xena extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if ((type === 'stop') || (type === 'stop-limit')) { - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPx param for order type ' + type); } @@ -1106,12 +1098,12 @@ module.exports = class xena extends Exchange { if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); } - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx !== undefined) { request['stopPx'] = this.priceToPrecision (symbol, stopPx); params = this.omit (params, 'stopPx'); } - const capPrice = this.safeFloat (params, 'capPrice'); + const capPrice = this.safeNumber (params, 'capPrice'); if (capPrice !== undefined) { request['capPrice'] = this.priceToPrecision (symbol, capPrice); params = this.omit (params, 'capPrice'); @@ -1466,7 +1458,7 @@ module.exports = class xena extends Exchange { const address = this.safeString (transaction, 'address'); const addressFrom = undefined; const addressTo = address; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const fee = undefined; return { @@ -1563,7 +1555,7 @@ module.exports = class xena extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'kind')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); @@ -1575,11 +1567,11 @@ module.exports = class xena extends Exchange { timestamp = parseInt (timestamp / 1000000); } const fee = { - 'cost': this.safeFloat (item, 'commission'), + 'cost': this.safeNumber (item, 'commission'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/yobit.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/yobit.js index 0ab100f68..82d86ea71 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/yobit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/yobit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError, RateLimitExceeded } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -138,6 +139,7 @@ module.exports = class yobit extends Exchange { 'NAV': 'NavajoCoin', 'NBT': 'NiceBytes', 'OMG': 'OMGame', + 'ONX': 'Onix', 'PAC': '$PAC', 'PLAY': 'PlayCoin', 'PIVX': 'Darknet', @@ -236,15 +238,33 @@ module.exports = class yobit extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['total'] = this.safeFloat (total, currencyId); + account['free'] = this.safeString (free, currencyId); + account['total'] = this.safeString (total, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615856752, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":10000, + // "min_amount":0.0001, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.2, + // "fee_buyer":0.2, + // "fee_seller":0.2 + // }, + // }, + // } + // const markets = this.safeValue (response, 'pairs'); const keys = Object.keys (markets); const result = []; @@ -262,15 +282,15 @@ module.exports = class yobit extends Exchange { 'price': this.safeInteger (market, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }; const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }; const costLimits = { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }; const limits = { 'amount': amountLimits, @@ -279,6 +299,7 @@ module.exports = class yobit extends Exchange { }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -287,7 +308,7 @@ module.exports = class yobit extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -363,16 +384,16 @@ module.exports = class yobit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -381,9 +402,9 @@ module.exports = class yobit extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -432,15 +453,18 @@ module.exports = class yobit extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const order = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const type = 'limit'; // all trades are still limit trades let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -455,12 +479,6 @@ module.exports = class yobit extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, 'taker'); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': order, @@ -522,8 +540,8 @@ module.exports = class yobit extends Exchange { id = this.safeString (response['return'], 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (response['return'], 'received', 0.0); + remaining = this.safeNumber (response['return'], 'remains', amount); } const timestamp = this.milliseconds (); return { @@ -573,21 +591,13 @@ module.exports = class yobit extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp_created'); const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const remaining = this.safeFloat (order, 'amount'); - const amount = this.safeFloat (order, 'start_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - cost = price * filled; - } - } + const remaining = this.safeNumber (order, 'amount'); + const amount = this.safeNumber (order, 'start_amount'); + const price = this.safeNumber (order, 'rate'); const fee = undefined; const type = 'limit'; const side = this.safeString (order, 'type'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -601,16 +611,15 @@ module.exports = class yobit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zaif.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zaif.js index 2c6454a05..a94f9dddb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zaif.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zaif.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -127,6 +128,27 @@ module.exports = class zaif extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetCurrencyPairsAll (params); + // + // [ + // { + // "aux_unit_point": 0, + // "item_japanese": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3", + // "aux_unit_step": 5.0, + // "description": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3\u30fb\u65e5\u672c\u5186\u306e\u53d6\u5f15\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059", + // "item_unit_min": 0.001, + // "event_number": 0, + // "currency_pair": "btc_jpy", + // "is_token": false, + // "aux_unit_min": 5.0, + // "aux_japanese": "\u65e5\u672c\u5186", + // "id": 1, + // "item_unit_step": 0.0001, + // "name": "BTC/JPY", + // "seq": 0, + // "title": "BTC/JPY" + // } + // ] + // const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -137,8 +159,8 @@ module.exports = class zaif extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': -Math.log10 (market['item_unit_step']), - 'price': market['aux_unit_point'], + 'amount': -Math.log10 (this.safeNumber (market, 'item_unit_step')), + 'price': this.safeInteger (market, 'aux_unit_point'), }; const fees = this.safeValue (this.options['fees'], symbol, this.fees['trading']); const taker = fees['taker']; @@ -156,11 +178,11 @@ module.exports = class zaif extends Exchange { 'maker': maker, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'item_unit_min'), + 'min': this.safeNumber (market, 'item_unit_min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'aux_unit_min'), + 'min': this.safeNumber (market, 'aux_unit_min'), 'max': undefined, }, 'cost': { @@ -192,7 +214,7 @@ module.exports = class zaif extends Exchange { }; if ('deposit' in balances) { if (currencyId in balances['deposit']) { - account['total'] = this.safeFloat (balances['deposit'], currencyId); + account['total'] = this.safeNumber (balances['deposit'], currencyId); account['used'] = account['total'] - account['free']; } } @@ -217,22 +239,22 @@ module.exports = class zaif extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.milliseconds (); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -253,14 +275,11 @@ module.exports = class zaif extends Exchange { side = (side === 'bid') ? 'buy' : 'sell'; const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString2 (trade, 'id', 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); return { @@ -338,16 +357,10 @@ module.exports = class zaif extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp'); const marketId = this.safeString (order, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -361,7 +374,7 @@ module.exports = class zaif extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': undefined, 'remaining': undefined, @@ -369,7 +382,7 @@ module.exports = class zaif extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zb.js b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zb.js index 1f8f61cdf..29bea651d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zb.js +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/zb.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadRequest, ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, OrderNotFound, ExchangeNotAvailable, DDoSProtection, InvalidOrder, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89,8 +90,8 @@ module.exports = class zb extends Exchange { 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg', 'api': { - 'public': 'http://api.zb.cn/data', // no https for public API - 'private': 'https://trade.zb.cn/api', + 'public': 'https://api.zb.today/data', + 'private': 'https://trade.zb.today/api', }, 'www': 'https://www.zb.com', 'doc': 'https://www.zb.com/i/developer', @@ -205,6 +206,16 @@ module.exports = class zb extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetMarkets (params); + // + // { + // "zb_qc":{ + // "amountScale":2, + // "minAmount":0.01, + // "minSize":5, + // "priceScale":4, + // }, + // } + // const keys = Object.keys (markets); const result = []; for (let i = 0; i < keys.length; i++) { @@ -268,11 +279,11 @@ module.exports = class zb extends Exchange { const account = this.account (); const currencyId = this.safeString (balance, 'key'); const code = this.safeCurrencyCode (currencyId); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'freez'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'freez'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -321,18 +332,6 @@ module.exports = class zb extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetGetPayinAddress (params); @@ -439,16 +438,16 @@ module.exports = class zb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -458,12 +457,23 @@ module.exports = class zb extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; } + parseOHLCV (ohlcv, market = undefined) { + return [ + this.safeInteger (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + ]; + } + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -488,14 +498,12 @@ module.exports = class zb extends Exchange { let side = this.safeString (trade, 'trade_type'); side = (side === 'bid') ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const costString = Precise.stringMul (priceString, amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (costString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -674,23 +682,13 @@ module.exports = class zb extends Exchange { const timestamp = this.safeInteger (order, 'trade_date'); const marketId = this.safeString (order, 'currency'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'trade_amount'); - const amount = this.safeFloat (order, 'total_amount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'trade_money'); - let average = undefined; + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'trade_amount'); + const amount = this.safeNumber (order, 'total_amount'); + const cost = this.safeNumber (order, 'trade_money'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((cost !== undefined) && (filled !== undefined) && (filled > 0)) { - average = cost / filled; - } const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fees'); + const feeCost = this.safeNumber (order, 'fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -705,7 +703,7 @@ module.exports = class zb extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -719,15 +717,15 @@ module.exports = class zb extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -790,7 +788,7 @@ module.exports = class zb extends Exchange { // const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'hash'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let timestamp = this.parse8601 (this.safeString (transaction, 'submit_time')); timestamp = this.safeInteger (transaction, 'submitTime', timestamp); let address = this.safeString2 (transaction, 'toAddress', 'address'); @@ -810,7 +808,7 @@ module.exports = class zb extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -843,7 +841,7 @@ module.exports = class zb extends Exchange { if (password === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires exchange.password or a safePwd parameter'); } - const fees = this.safeFloat (params, 'fees'); + const fees = this.safeNumber (params, 'fees'); if (fees === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires a fees parameter'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/package.json b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/package.json index a5305f19f..8e0bd3de4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/package.json +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/package.json @@ -1,27 +1,27 @@ { - "_from": "ccxt@1.42.77", - "_id": "ccxt@1.42.77", + "_from": "ccxt@1.47.49", + "_id": "ccxt@1.47.49", "_inBundle": false, - "_integrity": "sha512-vPaw8G3hr9iq1iJ59EHuA6iqjufgK6dNC7MjT3qV8YQbpEJoD2ynoFwfl1hbuvlyKlFjiOa3gHwhRV64UacBDQ==", + "_integrity": "sha512-aGjOGKX/wfStwD24dH7FweP2ktdbZBjhgLxkipFVaewnjsftyiuzCCikMS7IvSRON/aAMG0oqKUdVHL382BFMA==", "_location": "/ccxt", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "ccxt@1.42.77", + "raw": "ccxt@1.47.49", "name": "ccxt", "escapedName": "ccxt", - "rawSpec": "1.42.77", + "rawSpec": "1.47.49", "saveSpec": null, - "fetchSpec": "1.42.77" + "fetchSpec": "1.47.49" }, "_requiredBy": [ "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.42.77.tgz", - "_shasum": "8ab5f8e7190854e163da6d4fcf44530794d0a21c", - "_spec": "ccxt@1.42.77", + "_resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.47.49.tgz", + "_shasum": "ef9c41b5573b85d3b83cf1292d0aa891c4d5b6bc", + "_spec": "ccxt@1.47.49", "_where": "C:\\Superalgos\\Projects\\Superalgos\\TS\\Bot-Modules\\Sensor-Bot\\Exchange-Raw-Data", "author": { "name": "Igor Kroitor", @@ -543,7 +543,9 @@ "equos.io", "EQUOS", "ndax.io", - "NDAX" + "NDAX", + "ascendex.com", + "AscendEX" ], "license": "MIT", "main": "./ccxt.js", @@ -587,5 +589,5 @@ }, "types": "./ccxt.d.ts", "unpkg": "dist/ccxt.browser.js", - "version": "1.42.77" + "version": "1.47.49" } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/package-lock.json b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/package-lock.json index 976144cc2..cd3bb8d9e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/package-lock.json +++ b/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/package-lock.json @@ -3,9 +3,9 @@ "lockfileVersion": 1, "dependencies": { "ccxt": { - "version": "1.42.77", - "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.42.77.tgz", - "integrity": "sha512-vPaw8G3hr9iq1iJ59EHuA6iqjufgK6dNC7MjT3qV8YQbpEJoD2ynoFwfl1hbuvlyKlFjiOa3gHwhRV64UacBDQ==" + "version": "1.47.49", + "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.47.49.tgz", + "integrity": "sha512-aGjOGKX/wfStwD24dH7FweP2ktdbZBjhgLxkipFVaewnjsftyiuzCCikMS7IvSRON/aAMG0oqKUdVHL382BFMA==" } } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/CONTRIBUTING.md b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/CONTRIBUTING.md index 1d3ff05d1..7ff3d7ae6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/CONTRIBUTING.md +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/CONTRIBUTING.md @@ -261,7 +261,7 @@ These files containing derived exchange classes are transpiled from JS into PHP: These PHP base classes and files are not transpiled: -- `php/base/*` +- `php/Exchange.php php/ExchangeError.php php/Precise.php ... #### Typescript @@ -385,7 +385,7 @@ async fetchTicker (symbol, params = {}) { #### Parsing Symbols -When sending requests to the exchange unified symbols have to be _"converted"_ to exchange-specific market-`id`s like shown above. The same is true on the other side – when receiving an exchange response it has an exchange-specific market-`id` inside it that has to be _"converted back"_ to a unified CCXT symbol. +When sending requests to the exchange unified symbols have to be _"converted"_ to exchange-specific market-`id`s like shown above. The same is true on the other end – when receiving an exchange response it has an exchange-specific market-`id` inside it that has to be _"converted back"_ to a unified CCXT symbol. **We don't put exchange-specific market-`id`s in unified structures directly!** We can't freely interchange symbols with ids! There is a significant difference between an *exchange-specific market-ids* and *unified symbols*! This is explained in the Manual, here: @@ -444,7 +444,7 @@ In JavaScript, dictionary keys can be accessed in two notations: Both work almost identically, and one is implicitly converted to another upon executing the JavaScript code. -While the above does work in JavaScript, it will not work in Python or PHP. In most languages, associative dictionary keys are not treated in the same way as properties. Therefore, in Python `object.key` is not the same as `object['key']`. In PHP `$object->key` is not the same as `$object['key']` as well. Languages that differentiate between associative keys and properties use different notations for the two. +While the above does work in JavaScript, **it will not work in Python or PHP**. In most languages, associative dictionary keys are not treated in the same way as properties. Therefore, in Python `object.key` is not the same as `object['key']`. In PHP `$object->key` is not the same as `$object['key']` as well. Languages that differentiate between associative keys and properties use different notations for the two. To keep the code transpileable, please, remember this simple rule: *always use the single-quoted string key notation `object['key']` for accessing all associative dictionary keys in all languages everywhere throughout this library!* @@ -572,7 +572,7 @@ The `hmac()` method also supports `'base64'` for the `digest` argument. This is #### Timestamps -**All timestamps throughout all unified structures within this library are integer timestamp _in milliseconds_!** +**All timestamps throughout all unified structures within this library are integer UTC timestamps _in milliseconds_!** In order to convert to milliseconds timestamps, CCXT implements the following methods: diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/README.md b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/README.md index 3f8dfeea4..7ec80167e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/README.md +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/README.md @@ -1,6 +1,6 @@ # CCXT – CryptoCurrency eXchange Trading Library -[![Build Status](https://travis-ci.com/ccxt/ccxt.svg?branch=master)](https://travis-ci.com/ccxt/ccxt) [![npm](https://img.shields.io/npm/v/ccxt.svg)](https://npmjs.com/package/ccxt) [![PyPI](https://img.shields.io/pypi/v/ccxt.svg)](https://pypi.python.org/pypi/ccxt) [![NPM Downloads](https://img.shields.io/npm/dy/ccxt.svg)](https://www.npmjs.com/package/ccxt) [![Discord](https://img.shields.io/discord/690203284119617602?logo=discord&logoColor=white)](https://discord.gg/dhzSKYU) [![Supported Exchanges](https://img.shields.io/badge/exchanges-126-blue.svg)](https://github.com/ccxt/ccxt/wiki/Exchange-Markets) [![Open Collective](https://opencollective.com/ccxt/backers/badge.svg)](https://opencollective.com/ccxt) +[![Build Status](https://travis-ci.com/ccxt/ccxt.svg?branch=master)](https://travis-ci.com/ccxt/ccxt) [![npm](https://img.shields.io/npm/v/ccxt.svg)](https://npmjs.com/package/ccxt) [![PyPI](https://img.shields.io/pypi/v/ccxt.svg)](https://pypi.python.org/pypi/ccxt) [![NPM Downloads](https://img.shields.io/npm/dy/ccxt.svg)](https://www.npmjs.com/package/ccxt) [![Discord](https://img.shields.io/discord/690203284119617602?logo=discord&logoColor=white)](https://discord.gg/dhzSKYU) [![Supported Exchanges](https://img.shields.io/badge/exchanges-121-blue.svg)](https://github.com/ccxt/ccxt/wiki/Exchange-Markets) [![Open Collective](https://opencollective.com/ccxt/backers/badge.svg)](https://opencollective.com/ccxt) [![Twitter Follow](https://img.shields.io/twitter/follow/ccxt_official.svg?style=social&label=CCXT)](https://twitter.com/ccxt_official) A JavaScript / Python / PHP library for cryptocurrency trading and e-commerce with support for many bitcoin/ether/altcoin exchange markets and merchant APIs. @@ -25,10 +25,10 @@ Current feature list: ## See Also -- [![Quadency](https://user-images.githubusercontent.com/1294454/69334382-a0618100-0c6b-11ea-9ba9-40aa97440cfa.png)](https://quadency.com?utm_source=ccxt)  **[Quadency](https://quadency.com?utm_source=ccxt)** — trading automation terminal for leading exchanges with streaming APIs + Python IDE. - [![TabTrader](https://user-images.githubusercontent.com/1294454/66755907-9c3e8880-eea1-11e9-846e-0bff349ceb87.png)](https://tab-trader.com/?utm_source=ccxt)  **[TabTrader](https://tab-trader.com/?utm_source=ccxt)** — trading on all exchanges in one app. Avaliable on [Android](https://play.google.com/store/apps/details?id=com.tabtrader.android&referrer=utm_source%3Dccxt) and [iOS](https://itunes.apple.com/app/apple-store/id1095716562?mt=8). - [![Pionex](https://user-images.githubusercontent.com/1294454/106112806-c2ec0580-615e-11eb-870c-0b7aef021db2.png)](https://www.pionex.com/en-US/sign?r=8wSFCbNk&utm_source=ad&utm_medium=banner&utm_campaign=ccxt-2)  **[Pionex](https://www.pionex.com/en-US/sign?r=8wSFCbNk&utm_source=ad&utm_medium=banner&utm_campaign=ccxt-2)** — 6 grid bots, spot-futures arb bot, smart trade and DCA bots. Free for [Android](https://play.google.com/store/apps/details?id=com.pionex.client&referrer=utm_source%3Dccxt) and [iOS](https://apps.apple.com/us/app/pionex/id1485348891?pt=ccxt&ct=inline)! - [![AAX](https://user-images.githubusercontent.com/1294454/106509642-ef957980-64de-11eb-92e0-8323cda7874e.png)](https://www.aaxpro.com/en-US/ad-sign-up/?utm_source=ccxt&utm_medium=one-liner&utm_campaign=futures)  **[AAX](https://www.aaxpro.com/en-US/ad-sign-up/?utm_source=ccxt&utm_medium=one-liner&utm_campaign=futures)** — trade bitcoin futures with fees as low as 0.02% and up to 100x leverage! +- [![Freqtrade](https://user-images.githubusercontent.com/1294454/114340585-8e35fa80-9b60-11eb-860f-4379125e2db6.png)](https://www.freqtrade.io)  **[Freqtrade](https://www.freqtrade.io)** — leading opensource cryptocurrency algorithmic trading software! ## Certified Cryptocurrency Exchanges @@ -52,13 +52,13 @@ Current feature list: ## Supported Cryptocurrency Exchange Markets -The CCXT library currently supports the following 126 cryptocurrency exchange markets and trading APIs: +The CCXT library currently supports the following 121 cryptocurrency exchange markets and trading APIs: | logo | id | name | ver | doc | certified | pro | |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|-----------------------------------------------------------------------------------------|:---:|:-------------------------------------------------------------------------------------------:|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------| | [![aax](https://user-images.githubusercontent.com/1294454/104140087-a27f2580-53c0-11eb-87c1-5d9e81208fe9.jpg)](https://www.aaxpro.com/invite/sign-up?inviteCode=JXGm5Fy7R2MB) | aax | [AAX](https://www.aaxpro.com/invite/sign-up?inviteCode=JXGm5Fy7R2MB) | 2 | [API](https://www.aaxpro.com/apidoc/index.html) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | -| [![acx](https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg)](https://acx.io) | acx | [ACX](https://acx.io) | 2 | [API](https://acx.io/documents/api_v2) | | | | [![aofex](https://user-images.githubusercontent.com/51840849/77670271-056d1080-6f97-11ea-9ac2-4268e9ed0c1f.jpg)](https://aofex.com/#/register?key=9763840) | aofex | [AOFEX](https://aofex.com/#/register?key=9763840) | * | [API](https://aofex.zendesk.com/hc/en-us/sections/360005576574-API) | | | +| [![ascendex](https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg)](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | ascendex | [AscendEX](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | 1 | [API](https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation) | | | | [![bequant](https://user-images.githubusercontent.com/1294454/55248342-a75dfe00-525a-11e9-8aa2-05e9dca943c6.jpg)](https://bequant.io) | bequant | [Bequant](https://bequant.io) | 2 | [API](https://api.bequant.io/) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bibox](https://user-images.githubusercontent.com/51840849/77257418-3262b000-6c85-11ea-8fb8-20bdf20b3592.jpg)](https://w2.bibox365.com/login/register?invite_code=05Kj3I) | bibox | [Bibox](https://w2.bibox365.com/login/register?invite_code=05Kj3I) | 1 | [API](https://biboxcom.github.io/en/) | | | | [![bigone](https://user-images.githubusercontent.com/1294454/69354403-1d532180-0c91-11ea-88ed-44c06cefdf87.jpg)](https://b1.run/users/new?code=D3LLBVFT) | bigone | [BigONE](https://b1.run/users/new?code=D3LLBVFT) | 3 | [API](https://open.big.one/docs/api.html) | | | @@ -76,7 +76,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bithumb](https://user-images.githubusercontent.com/1294454/30597177-ea800172-9d5e-11e7-804c-b9d4fa9b56b0.jpg)](https://www.bithumb.com) | bithumb | [Bithumb](https://www.bithumb.com) | * | [API](https://apidocs.bithumb.com) | | | | [![bitkk](https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg)](https://www.bitkk.com) | bitkk | [bitkk](https://www.bitkk.com) | 1 | [API](https://www.bitkk.com/i/developer) | | | | [![bitmart](https://user-images.githubusercontent.com/1294454/61835713-a2662f80-ae85-11e9-9d00-6442919701fd.jpg)](http://www.bitmart.com/?r=rQCFLh) | bitmart | [BitMart](http://www.bitmart.com/?r=rQCFLh) | 1 | [API](https://developer-pro.bitmart.com/) | | | -| [![bitmax](https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg)](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | bitmax | [BitMax](https://bitmax.io/#/register?inviteCode=EL6BXBQM) | 1 | [API](https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation) | | | | [![bitmex](https://user-images.githubusercontent.com/1294454/27766319-f653c6e6-5ed4-11e7-933d-f0bc3699ae8f.jpg)](https://www.bitmex.com/register/upZpOX) | bitmex | [BitMEX](https://www.bitmex.com/register/upZpOX) | 1 | [API](https://www.bitmex.com/app/apiOverview) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bitpanda](https://user-images.githubusercontent.com/51840849/87591171-9a377d80-c6f0-11ea-94ac-97a126eac3bc.jpg)](https://www.bitpanda.com/en/pro) | bitpanda | [Bitpanda Pro](https://www.bitpanda.com/en/pro) | 1 | [API](https://developers.bitpanda.com/exchange/) | | | | [![bitso](https://user-images.githubusercontent.com/51840849/87295554-11f98280-c50e-11ea-80d6-15b3bafa8cbf.jpg)](https://bitso.com/?ref=itej) | bitso | [Bitso](https://bitso.com/?ref=itej) | 3 | [API](https://bitso.com/api_info) | | | @@ -84,7 +83,7 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bitstamp1](https://user-images.githubusercontent.com/1294454/27786377-8c8ab57e-5fe9-11e7-8ea4-2b05b6bcceec.jpg)](https://www.bitstamp.net) | bitstamp1 | [Bitstamp](https://www.bitstamp.net) | 1 | [API](https://www.bitstamp.net/api) | | | | [![bittrex](https://user-images.githubusercontent.com/51840849/87153921-edf53180-c2c0-11ea-96b9-f2a9a95a455b.jpg)](https://bittrex.com/Account/Register?referralCode=1ZE-G0G-M3B) | bittrex | [Bittrex](https://bittrex.com/Account/Register?referralCode=1ZE-G0G-M3B) | 3 | [API](https://bittrex.github.io/api/v3) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![bitvavo](https://user-images.githubusercontent.com/1294454/83165440-2f1cf200-a116-11ea-9046-a255d09fb2ed.jpg)](https://bitvavo.com/?a=24F34952F7) | bitvavo | [Bitvavo](https://bitvavo.com/?a=24F34952F7) | 2 | [API](https://docs.bitvavo.com/) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![bitz](https://user-images.githubusercontent.com/51840849/87443304-fec5e000-c5fd-11ea-98f8-ba8e67f7eaff.jpg)](https://u.bitz.com/register?invite_code=1429193) | bitz | [Bit-Z](https://u.bitz.com/register?invite_code=1429193) | 2 | [API](https://apidoc.bitz.com/en/) | | | +| [![bitz](https://user-images.githubusercontent.com/51840849/87443304-fec5e000-c5fd-11ea-98f8-ba8e67f7eaff.jpg)](https://u.bitz.com/register?invite_code=1429193) | bitz | [Bit-Z](https://u.bitz.com/register?invite_code=1429193) | 2 | [API](https://apidocv2.bitz.plus/en/) | | | | [![bl3p](https://user-images.githubusercontent.com/1294454/28501752-60c21b82-6feb-11e7-818b-055ee6d0e754.jpg)](https://bl3p.eu) | bl3p | [BL3P](https://bl3p.eu) | 1 | [API](https://github.com/BitonicNL/bl3p-api/tree/master/docs) | | | | [![bleutrade](https://user-images.githubusercontent.com/1294454/30303000-b602dbe6-976d-11e7-956d-36c5049c01e7.jpg)](https://bleutrade.com) | bleutrade | [Bleutrade](https://bleutrade.com) | * | [API](https://app.swaggerhub.com/apis-docs/bleu/white-label/3.0.0) | | | | [![braziliex](https://user-images.githubusercontent.com/1294454/34703593-c4498674-f504-11e7-8d14-ff8e44fb78c1.jpg)](https://braziliex.com/?ref=5FE61AB6F6D67DA885BC98BA27223465) | braziliex | [Braziliex](https://braziliex.com/?ref=5FE61AB6F6D67DA885BC98BA27223465) | * | [API](https://braziliex.com/exchange/api.php) | | | @@ -99,7 +98,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![bytetrade](https://user-images.githubusercontent.com/1294454/67288762-2f04a600-f4e6-11e9-9fd6-c60641919491.jpg)](https://www.byte-trade.com) | bytetrade | [ByteTrade](https://www.byte-trade.com) | * | [API](https://docs.byte-trade.com/#description) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | | [![cdax](https://user-images.githubusercontent.com/1294454/102157692-fd406280-3e90-11eb-8d46-4511b617cd17.jpg)](https://cdax.io/invite?invite_code=esc74) | cdax | [CDAX](https://cdax.io/invite?invite_code=esc74) | 1 | [API](https://github.com/cloudapidoc/API_Docs) | | | | [![cex](https://user-images.githubusercontent.com/1294454/27766442-8ddc33b0-5ed8-11e7-8b98-f786aef0f3c9.jpg)](https://cex.io/r/0/up105393824/0/) | cex | [CEX.IO](https://cex.io/r/0/up105393824/0/) | * | [API](https://cex.io/cex-api) | | | -| [![chilebit](https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg)](https://chilebit.net) | chilebit | [ChileBit](https://chilebit.net) | 1 | [API](https://blinktrade.com/docs) | | | | [![coinbase](https://user-images.githubusercontent.com/1294454/40811661-b6eceae2-653a-11e8-829e-10bfadb078cf.jpg)](https://www.coinbase.com/join/58cbe25a355148797479dbd2) | coinbase | [Coinbase](https://www.coinbase.com/join/58cbe25a355148797479dbd2) | 2 | [API](https://developers.coinbase.com/api/v2) | | | | [![coinbaseprime](https://user-images.githubusercontent.com/1294454/44539184-29f26e00-a70c-11e8-868f-e907fc236a7c.jpg)](https://prime.coinbase.com) | coinbaseprime | [Coinbase Prime](https://prime.coinbase.com) | * | [API](https://docs.prime.coinbase.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![coinbasepro](https://user-images.githubusercontent.com/1294454/41764625-63b7ffde-760a-11e8-996d-a6328fa9347a.jpg)](https://pro.coinbase.com/) | coinbasepro | [Coinbase Pro](https://pro.coinbase.com/) | * | [API](https://docs.pro.coinbase.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | @@ -118,7 +116,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![delta](https://user-images.githubusercontent.com/1294454/99450025-3be60a00-2931-11eb-9302-f4fd8d8589aa.jpg)](https://www.delta.exchange/app/signup/?code=IULYNB) | delta | [Delta Exchange](https://www.delta.exchange/app/signup/?code=IULYNB) | 2 | [API](https://docs.delta.exchange) | | | | [![deribit](https://user-images.githubusercontent.com/1294454/41933112-9e2dd65a-798b-11e8-8440-5bab2959fcb8.jpg)](https://www.deribit.com/reg-1189.4038) | deribit | [Deribit](https://www.deribit.com/reg-1189.4038) | 2 | [API](https://docs.deribit.com/v2) | | | | [![digifinex](https://user-images.githubusercontent.com/51840849/87443315-01283a00-c5fe-11ea-8628-c2a0feaf07ac.jpg)](https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp) | digifinex | [DigiFinex](https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp) | 3 | [API](https://docs.digifinex.com) | | | -| [![dsx](https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg)](https://dsxglobal.com) | dsx | [DSX](https://dsxglobal.com) | 3 | [API](https://dsxglobal.com/developers/publicApi) | | | | [![equos](https://user-images.githubusercontent.com/1294454/107758499-05edd180-6d38-11eb-9e09-0b69602a7a15.jpg)](https://equos.io?referredByCode=zpa8kij4ouvBFup3) | equos | [EQUOS](https://equos.io?referredByCode=zpa8kij4ouvBFup3) | * | [API](https://developer.equos.io) | | | | [![eterbase](https://user-images.githubusercontent.com/1294454/82067900-faeb0f80-96d9-11ea-9f22-0071cfcb9871.jpg)](https://eterbase.exchange/invite/1wjjh4Pe) | eterbase | [Eterbase](https://eterbase.exchange/invite/1wjjh4Pe) | 1 | [API](https://developers.eterbase.exchange) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | | [![exmo](https://user-images.githubusercontent.com/1294454/27766491-1b0ea956-5eda-11e7-9225-40d67b481b8d.jpg)](https://exmo.me/?ref=131685) | exmo | [EXMO](https://exmo.me/?ref=131685) | 1.1 | [API](https://exmo.me/en/api_doc?ref=131685) | | | @@ -133,10 +130,9 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![gopax](https://user-images.githubusercontent.com/1294454/102897212-ae8a5e00-4478-11eb-9bab-91507c643900.jpg)](https://www.gopax.co.kr) | gopax | [GOPAX](https://www.gopax.co.kr) | 1 | [API](https://gopax.github.io/API/index.en.html) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![hbtc](https://user-images.githubusercontent.com/51840849/80134449-70663300-85a7-11ea-8942-e204cdeaab5d.jpg)](https://www.hbtc.com/register/O2S8NS) | hbtc | [HBTC](https://www.hbtc.com/register/O2S8NS) | 1 | [API](https://github.com/bhexopen/BHEX-OpenApi/tree/master/doc) | | | | [![hitbtc](https://user-images.githubusercontent.com/1294454/27766555-8eaec20e-5edc-11e7-9c5b-6dc69fc42f5e.jpg)](https://hitbtc.com/?ref_id=5a5d39a65d466) | hitbtc | [HitBTC](https://hitbtc.com/?ref_id=5a5d39a65d466) | 2 | [API](https://api.hitbtc.com) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![hollaex](https://user-images.githubusercontent.com/1294454/75841031-ca375180-5ddd-11ea-8417-b975674c23cb.jpg)](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | hollaex | [HollaEx](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | 1 | [API](https://apidocs.hollaex.com) | | | +| [![hollaex](https://user-images.githubusercontent.com/1294454/75841031-ca375180-5ddd-11ea-8417-b975674c23cb.jpg)](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | hollaex | [HollaEx](https://pro.hollaex.com/signup?affiliation_code=QSWA6G) | 2 | [API](https://apidocs.hollaex.com) | | | | [![huobijp](https://user-images.githubusercontent.com/1294454/85734211-85755480-b705-11ea-8b35-0b7f1db33a2f.jpg)](https://www.huobi.co.jp/register/?invite_code=znnq3) | huobijp | [Huobi Japan](https://www.huobi.co.jp/register/?invite_code=znnq3) | 1 | [API](https://api-doc.huobi.co.jp) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![huobipro](https://user-images.githubusercontent.com/1294454/76137448-22748a80-604e-11ea-8069-6e389271911d.jpg)](https://www.huobi.com/en-us/topic/invited/?invite_code=rwrd3) | huobipro | [Huobi Pro](https://www.huobi.com/en-us/topic/invited/?invite_code=rwrd3) | 1 | [API](https://huobiapi.github.io/docs/spot/v1/cn/) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![ice3x](https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg)](https://ice3x.com?ref=14341802) | ice3x | [ICE3X](https://ice3x.com?ref=14341802) | 1 | [API](https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017) | | | | [![idex](https://user-images.githubusercontent.com/51840849/94481303-2f222100-01e0-11eb-97dd-bc14c5943a86.jpg)](https://idex.io) | idex | [IDEX](https://idex.io) | 2 | [API](https://docs.idex.io/) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | | [![independentreserve](https://user-images.githubusercontent.com/51840849/87182090-1e9e9080-c2ec-11ea-8e49-563db9a38f37.jpg)](https://www.independentreserve.com) | independentreserve | [Independent Reserve](https://www.independentreserve.com) | * | [API](https://www.independentreserve.com/API) | | | | [![indodax](https://user-images.githubusercontent.com/51840849/87070508-9358c880-c221-11ea-8dc5-5391afbbb422.jpg)](https://indodax.com/ref/testbitcoincoid/1) | indodax | [INDODAX](https://indodax.com/ref/testbitcoincoid/1) | 2.0 | [API](https://github.com/btcid/indodax-official-api-docs) | | | @@ -172,7 +168,6 @@ The CCXT library currently supports the following 126 cryptocurrency exchange ma | [![tidex](https://user-images.githubusercontent.com/1294454/30781780-03149dc4-a12e-11e7-82bb-313b269d24d4.jpg)](https://tidex.com/exchange/?ref=57f5638d9cd7) | tidex | [Tidex](https://tidex.com/exchange/?ref=57f5638d9cd7) | 3 | [API](https://tidex.com/exchange/public-api) | | | | [![timex](https://user-images.githubusercontent.com/1294454/70423869-6839ab00-1a7f-11ea-8f94-13ae72c31115.jpg)](https://timex.io/?refcode=1x27vNkTbP1uwkCck) | timex | [TimeX](https://timex.io/?refcode=1x27vNkTbP1uwkCck) | 1 | [API](https://docs.timex.io) | | | | [![upbit](https://user-images.githubusercontent.com/1294454/49245610-eeaabe00-f423-11e8-9cba-4b0aed794799.jpg)](https://upbit.com) | upbit | [Upbit](https://upbit.com) | 1 | [API](https://docs.upbit.com/docs/%EC%9A%94%EC%B2%AD-%EC%88%98-%EC%A0%9C%ED%95%9C) | | [![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro) | -| [![vaultoro](https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg)](https://www.vaultoro.com) | vaultoro | [Vaultoro](https://www.vaultoro.com) | 1 | [API](https://api.vaultoro.com) | | | | [![vbtc](https://user-images.githubusercontent.com/1294454/27991481-1f53d1d8-6481-11e7-884e-21d17e7939db.jpg)](https://vbtc.exchange) | vbtc | [VBTC](https://vbtc.exchange) | 1 | [API](https://blinktrade.com/docs) | | | | [![vcc](https://user-images.githubusercontent.com/1294454/100545356-8427f500-326c-11eb-9539-7d338242d61b.jpg)](https://vcc.exchange?ref=l4xhrH) | vcc | [VCC Exchange](https://vcc.exchange?ref=l4xhrH) | 3 | [API](https://vcc.exchange/api) | | | | [![wavesexchange](https://user-images.githubusercontent.com/1294454/84547058-5fb27d80-ad0b-11ea-8711-78ac8b3c7f31.jpg)](https://waves.exchange) | wavesexchange | [Waves.Exchange](https://waves.exchange) | * | [API](https://docs.waves.exchange) | [![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification) | | @@ -229,13 +224,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.42.77/dist/ccxt.browser.js -* unpkg: https://unpkg.com/ccxt@1.42.77/dist/ccxt.browser.js +* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.47.49/dist/ccxt.browser.js +* unpkg: https://unpkg.com/ccxt@1.47.49/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/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/export-exchanges.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/export-exchanges.js index 580d2cb2c..24ee4806f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/export-exchanges.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/export-exchanges.js @@ -195,7 +195,6 @@ function createMarkdownTable (array, markdownMethod, centeredColumns) { // const columns = underline.split ('|') - for (const i of centeredColumns) { columns[i] = ':' + columns[i].slice (1, columns[i].length - 1) + ':' } @@ -219,51 +218,45 @@ function exportSupportedAndCertifiedExchanges (exchanges, { allExchangesPaths, c const exchangesNotListedInDocs = [ 'hitbtc2' ] const arrayOfExchanges = values (exchanges) + const numExchanges = arrayOfExchanges.length - if (allExchangesPaths) { - + if (allExchangesPaths && numExchanges) { const supportedExchangesMarkdownTable = createMarkdownTable (arrayOfExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , numExchanges = arrayOfExchanges.length , beginning = "The CCXT library currently supports the following " , ending = " cryptocurrency exchange markets and trading APIs:\n\n" , totalString = beginning + numExchanges + ending , allExchangesReplacement = totalString + supportedExchangesMarkdownTable + "$1" , allExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\| logo[^`]+\\|([\n][\n]|[\n]$|$)", 'm') - for (const path of allExchangesPaths) { logExportExchanges (path, allExchangesRegex, allExchangesReplacement) } } - if (proExchangesPaths) { - - const proExchanges = arrayOfExchanges.filter (exchange => exchange.pro) - , proExchangesMarkdownTable = createMarkdownTable (proExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , numExchanges = proExchanges.length + const proExchanges = arrayOfExchanges.filter (exchange => exchange.pro) + const numProExchanges = proExchanges.length + if (proExchangesPaths && numProExchanges) { + const proExchangesMarkdownTable = createMarkdownTable (proExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) , beginning = "The CCXT Pro library currently supports the following " , ending = " cryptocurrency exchange markets and WebSocket trading APIs:\n\n" - , totalString = beginning + numExchanges + ending + , totalString = beginning + numProExchanges + ending , proExchangesReplacement = totalString + proExchangesMarkdownTable + "$1" , proExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\|[^`]+\\|([\n][\n]|[\n]$|$)", 'm') - for (const path of proExchangesPaths) { logExportExchanges (path, proExchangesRegex, proExchangesReplacement) } } - if (certifiedExchangesPaths) { - const certifiedExchanges = arrayOfExchanges.filter (exchange => exchange.certified) - , certifiedExchangesMarkdownTable = createMarkdownTable (certifiedExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) - , certifiedExchangesReplacement = '$1' + certifiedExchangesMarkdownTable + "\n" - , certifiedExchangesRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm') - + const certifiedExchanges = arrayOfExchanges.filter (exchange => exchange.certified) + if (certifiedExchangesPaths && certifiedExchanges.length) { + const certifiedExchangesMarkdownTable = createMarkdownTable (certifiedExchanges, createMarkdownListOfExchanges, [ 3, 4 ]) + , certifiedExchangesReplacement = '$1' + certifiedExchangesMarkdownTable + "\n" + , certifiedExchangesRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm') for (const path of certifiedExchangesPaths) { logExportExchanges (path, certifiedExchangesRegex, certifiedExchangesReplacement) } } if (exchangesByCountriesPaths) { - const exchangesByCountriesMarkdownTable = createMarkdownTable (arrayOfExchanges, createMarkdownListOfExchangesByCountries, [ 4, 5 ]) const result = "# Exchanges By Country\n\nThe ccxt library currently supports the following cryptocurrency exchange markets and trading APIs:\n\n" + exchangesByCountriesMarkdownTable + "\n\n" for (const path of exchangesByCountriesPaths) { @@ -385,7 +378,7 @@ function exportEverything () { replacement: "exchanges = [\n" + " '" + ids.join ("',\n '") + "'," + "\n]", }, { - file: './php/base/Exchange.php', + file: './php/Exchange.php', regex: /public static \$exchanges \= array\s*\([^\)]+\)/, replacement: "public static $exchanges = array(\n '" + ids.join ("',\n '") + "',\n )", }, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/transpile.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/transpile.js index 948a34c0f..233d15e6c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/transpile.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/build/transpile.js @@ -34,6 +34,7 @@ class Transpiler { [ /\.safeIntegerProduct2\s/g, '.safe_integer_product_2'], [ /\.safeTimestamp2\s/g, '.safe_timestamp_2'], [ /\.safeString2\s/g, '.safe_string_2'], + [ /\.safeNumber2\s/g, '.safe_number_2'], [ /\.safeStringLower2\s/g, '.safe_string_lower_2'], [ /\.safeStringUpper2\s/g, '.safe_string_upper_2'], [ /\.safeValue2\s/g, '.safe_value_2'], @@ -195,6 +196,10 @@ class Transpiler { [ /Number\.MAX_SAFE_INTEGER/g, 'float(\'inf\')'], [ /function\s*(\w+\s*\([^)]+\))\s*{/g, 'def $1:'], [ /assert\s*\((.+)\);/g, 'assert $1'], + [ /Precise\.stringAdd\s/g, 'Precise.string_add' ], + [ /Precise\.stringMul\s/g, 'Precise.string_mul' ], + [ /Precise\.stringDiv\s/g, 'Precise.string_div' ], + [ /Precise\.stringSub\s/g, 'Precise.string_sub' ], // insert common regexes in the middle (critical) ].concat (this.getCommonRegexes ()).concat ([ @@ -227,7 +232,7 @@ class Transpiler { [ /for\s+\(([a-zA-Z0-9_]+)\s*=\s*([^\;\s]+\s*)\;[^\<\>\=]+(?:\<=|\>=|<|>)\s*(.*)\s*\;[^\)]+\)\s*{/g, 'for $1 in range($2, $3):'], [ /\s\|\|\s/g, ' or ' ], [ /\s\&\&\s/g, ' and ' ], - [ /\!([^\='"])/g, 'not $1'], + [ /\!([^\s\='"])/g, 'not $1'], [ /\.push\s*\(([\s\S]+?)\);/g, '.append($1);' ], [ /^(\s*}\s*$)+/gm, '' ], [ /\;(\s+?\/\/.+?)/g, '$1' ], @@ -243,9 +248,6 @@ class Transpiler { [ /parseFloat\s*/g, 'float'], [ /parseInt\s*/g, 'int'], [ /self\[([^\]+]+)\]/g, 'getattr(self, $1)' ], - [ /([^\s]+)\.slice \(([^\,\)]+)\,\s?([^\)]+)\)/g, '$1[$2:$3]' ], - [ /([^\s]+)\.slice \(([^\)\:]+)\)/g, '$1[$2:]' ], - [ /([^\s(:]+)\.length/g, 'len($1)' ], [ /Math\.floor\s*\(([^\)]+)\)/g, 'int(math.floor($1))' ], [ /Math\.abs\s*\(([^\)]+)\)/g, 'abs($1)' ], [ /Math\.pow\s*\(([^\)]+)\)/g, 'math.pow($1)' ], @@ -253,6 +255,9 @@ class Transpiler { [ /Math\.ceil\s*\(([^\)]+)\)/g, 'int(math.ceil($1))' ], [ /Math\.log/g, 'math.log' ], [ /([a-zA-Z0-9_\.]*\([^\)]+\)|[^\s]+)\s+\?\s*([^\:]+)\s+\:\s*([^\n]+)/g, '$2 if $1 else $3'], + [ /([^\s]+)\.slice \(([^\,\)]+)\,\s?([^\)]+)\)/g, '$1[$2:$3]' ], + [ /([^\s]+)\.slice \(([^\)\:]+)\)/g, '$1[$2:]' ], + [ /([^\s(:]+)\.length/g, 'len($1)' ], [ /(^|\s)\/\//g, '$1#' ], [ /([^\n\s]) #/g, '$1 #' ], // PEP8 E261 [ /\.indexOf/g, '.find'], @@ -336,6 +341,10 @@ class Transpiler { [ /(\w+)\.shift\s*\(\)/g, 'array_shift($1)' ], [ /(\w+)\.pop\s*\(\)/g, 'array_pop($1)' ], [ /Number\.MAX_SAFE_INTEGER/g, 'PHP_INT_MAX' ], + [ /Precise\.stringAdd\s/g, 'Precise::string_add' ], + [ /Precise\.stringDiv\s/g, 'Precise::string_div' ], + [ /Precise\.stringMul\s/g, 'Precise::string_mul' ], + [ /Precise\.stringSub\s/g, 'Precise::string_sub' ], // insert common regexes in the middle (critical) ].concat (this.getCommonRegexes ()).concat ([ @@ -404,6 +413,7 @@ class Transpiler { [ /([^\(\s]+)\s+%\s+([^\s\,\;\)]+)/g, 'fmod($1, $2)' ], [ /\(([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\>\=\s*0\)/g, '(mb_strpos($1, $2) !== false)' ], [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\>\=\s*0/g, 'mb_strpos($1, $2) !== false' ], + [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)\s*\<\s*0/g, 'mb_strpos($1, $2) === false' ], [ /([^\s\(]+)\.indexOf\s*\(([^\)]+)\)/g, 'mb_strpos($1, $2)' ], [ /\(([^\s\(]+)\sin\s([^\)]+)\)/g, '(is_array($2) && array_key_exists($1, $2))' ], [ /([^\s]+)\.join\s*\(\s*([^\)]+?)\s*\)/g, 'implode($2, $1)' ], @@ -578,6 +588,9 @@ class Transpiler { precisionImports.push ('from ccxt.base.decimal_to_precision import ' + constant) } } + if (bodyAsString.match (/[\s(]Precise/)) { + precisionImports.push ('from ccxt.base.precise import Precise') + } header = header.concat (libraries, errorImports, precisionImports) @@ -633,7 +646,13 @@ class Transpiler { } } - header = header.concat (errorImports) + const precisionImports = [] + + if (async && bodyAsString.match (/[\s(]Precise/)) { + precisionImports.push ('use \\ccxt\\Precise;') + } + + header = header.concat (errorImports).concat (precisionImports) methods = methods.concat (this.getPHPBaseMethods ()) @@ -1179,7 +1198,7 @@ class Transpiler { function phpMakeErrorClassFile (name, parent) { const useClause = "\nuse " + parent + ";\n" - const requireClause = "\nrequire_once PATH_TO_CCXT_BASE . '" + parent + ".php';\n" + const requireClause = "\nrequire_once PATH_TO_CCXT . '" + parent + ".php';\n" const phpBody = [ '; - createLimitOrder (symbol: string, side: Order['side'], amount: number, price?: number, params?: Params): Promise; + createLimitOrder (symbol: string, side: Order['side'], amount: number, price: number, params?: Params): Promise; + createLimitBuyOrder (symbol: string, amount: number, price: number, params?: Params): Promise; + createLimitSellOrder (symbol: string, amount: number, price: number, params?: Params): Promise; createMarketOrder (symbol: string, side: Order['side'], amount: number, price?: number, params?: Params): Promise; createOrder (symbol: string, type: Order['type'], side: Order['side'], amount: number, price?: number, params?: Params): Promise; decode (str: string): string; @@ -423,8 +425,8 @@ declare module 'ccxt' { /* tslint:disable */ export class aax extends Exchange {} - export class acx extends Exchange {} export class aofex extends Exchange {} + export class ascendex extends Exchange {} export class bequant extends hitbtc {} export class bibox extends Exchange {} export class bigone extends Exchange {} @@ -442,7 +444,6 @@ declare module 'ccxt' { export class bithumb extends Exchange {} export class bitkk extends zb {} export class bitmart extends Exchange {} - export class bitmax extends Exchange {} export class bitmex extends Exchange {} export class bitpanda extends Exchange {} export class bitso extends Exchange {} @@ -465,7 +466,6 @@ declare module 'ccxt' { export class bytetrade extends Exchange {} export class cdax extends huobipro {} export class cex extends Exchange {} - export class chilebit extends foxbit {} export class coinbase extends Exchange {} export class coinbaseprime extends coinbasepro {} export class coinbasepro extends Exchange {} @@ -484,7 +484,6 @@ declare module 'ccxt' { export class delta extends Exchange {} export class deribit extends Exchange {} export class digifinex extends Exchange {} - export class dsx extends Exchange {} export class equos extends Exchange {} export class eterbase extends Exchange {} export class exmo extends Exchange {} @@ -502,14 +501,13 @@ declare module 'ccxt' { export class hollaex extends Exchange {} export class huobijp extends huobipro {} export class huobipro extends Exchange {} - export class ice3x extends Exchange {} export class idex extends Exchange {} export class independentreserve extends Exchange {} export class indodax extends Exchange {} export class itbit extends Exchange {} export class kraken extends Exchange {} export class kucoin extends Exchange {} - export class kuna extends acx {} + export class kuna extends Exchange {} export class lakebtc extends Exchange {} export class latoken extends Exchange {} export class lbank extends Exchange {} @@ -538,7 +536,6 @@ declare module 'ccxt' { export class tidex extends Exchange {} export class timex extends Exchange {} export class upbit extends Exchange {} - export class vaultoro extends Exchange {} export class vbtc extends foxbit {} export class vcc extends Exchange {} export class wavesexchange extends Exchange {} @@ -553,8 +550,8 @@ declare module 'ccxt' { export type ExchangeId = | 'aax' - | 'acx' | 'aofex' + | 'ascendex' | 'bequant' | 'bibox' | 'bigone' @@ -572,7 +569,6 @@ declare module 'ccxt' { | 'bithumb' | 'bitkk' | 'bitmart' - | 'bitmax' | 'bitmex' | 'bitpanda' | 'bitso' @@ -595,7 +591,6 @@ declare module 'ccxt' { | 'bytetrade' | 'cdax' | 'cex' - | 'chilebit' | 'coinbase' | 'coinbaseprime' | 'coinbasepro' @@ -614,7 +609,6 @@ declare module 'ccxt' { | 'delta' | 'deribit' | 'digifinex' - | 'dsx' | 'equos' | 'eterbase' | 'exmo' @@ -632,7 +626,6 @@ declare module 'ccxt' { | 'hollaex' | 'huobijp' | 'huobipro' - | 'ice3x' | 'idex' | 'independentreserve' | 'indodax' @@ -668,7 +661,6 @@ declare module 'ccxt' { | 'tidex' | 'timex' | 'upbit' - | 'vaultoro' | 'vbtc' | 'vcc' | 'wavesexchange' diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/ccxt.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/ccxt.js index 1d5c72642..27dc35101 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/ccxt.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/ccxt.js @@ -35,7 +35,7 @@ const Exchange = require ('./js/base/Exchange') //----------------------------------------------------------------------------- // this is updated by vss.js when building -const version = '1.42.77' +const version = '1.47.49' Exchange.ccxtVersion = version @@ -43,8 +43,8 @@ Exchange.ccxtVersion = version const exchanges = { 'aax': require ('./js/aax.js'), - 'acx': require ('./js/acx.js'), 'aofex': require ('./js/aofex.js'), + 'ascendex': require ('./js/ascendex.js'), 'bequant': require ('./js/bequant.js'), 'bibox': require ('./js/bibox.js'), 'bigone': require ('./js/bigone.js'), @@ -62,7 +62,6 @@ const exchanges = { 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitmart': require ('./js/bitmart.js'), - 'bitmax': require ('./js/bitmax.js'), 'bitmex': require ('./js/bitmex.js'), 'bitpanda': require ('./js/bitpanda.js'), 'bitso': require ('./js/bitso.js'), @@ -85,7 +84,6 @@ const exchanges = { 'bytetrade': require ('./js/bytetrade.js'), 'cdax': require ('./js/cdax.js'), 'cex': require ('./js/cex.js'), - 'chilebit': require ('./js/chilebit.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), @@ -104,7 +102,6 @@ const exchanges = { 'delta': require ('./js/delta.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), - 'dsx': require ('./js/dsx.js'), 'equos': require ('./js/equos.js'), 'eterbase': require ('./js/eterbase.js'), 'exmo': require ('./js/exmo.js'), @@ -122,7 +119,6 @@ const exchanges = { 'hollaex': require ('./js/hollaex.js'), 'huobijp': require ('./js/huobijp.js'), 'huobipro': require ('./js/huobipro.js'), - 'ice3x': require ('./js/ice3x.js'), 'idex': require ('./js/idex.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), @@ -158,7 +154,6 @@ const exchanges = { 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'upbit': require ('./js/upbit.js'), - 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'vcc': require ('./js/vcc.js'), 'wavesexchange': require ('./js/wavesexchange.js'), diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/dist/ccxt.browser.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/dist/ccxt.browser.js index e8b439fb1..334681baa 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/dist/ccxt.browser.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/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.42.77' +const version = '1.47.49' Exchange.ccxtVersion = version @@ -51,8 +51,8 @@ Exchange.ccxtVersion = version const exchanges = { 'aax': require ('./js/aax.js'), - 'acx': require ('./js/acx.js'), 'aofex': require ('./js/aofex.js'), + 'ascendex': require ('./js/ascendex.js'), 'bequant': require ('./js/bequant.js'), 'bibox': require ('./js/bibox.js'), 'bigone': require ('./js/bigone.js'), @@ -70,7 +70,6 @@ const exchanges = { 'bithumb': require ('./js/bithumb.js'), 'bitkk': require ('./js/bitkk.js'), 'bitmart': require ('./js/bitmart.js'), - 'bitmax': require ('./js/bitmax.js'), 'bitmex': require ('./js/bitmex.js'), 'bitpanda': require ('./js/bitpanda.js'), 'bitso': require ('./js/bitso.js'), @@ -93,7 +92,6 @@ const exchanges = { 'bytetrade': require ('./js/bytetrade.js'), 'cdax': require ('./js/cdax.js'), 'cex': require ('./js/cex.js'), - 'chilebit': require ('./js/chilebit.js'), 'coinbase': require ('./js/coinbase.js'), 'coinbaseprime': require ('./js/coinbaseprime.js'), 'coinbasepro': require ('./js/coinbasepro.js'), @@ -112,7 +110,6 @@ const exchanges = { 'delta': require ('./js/delta.js'), 'deribit': require ('./js/deribit.js'), 'digifinex': require ('./js/digifinex.js'), - 'dsx': require ('./js/dsx.js'), 'equos': require ('./js/equos.js'), 'eterbase': require ('./js/eterbase.js'), 'exmo': require ('./js/exmo.js'), @@ -130,7 +127,6 @@ const exchanges = { 'hollaex': require ('./js/hollaex.js'), 'huobijp': require ('./js/huobijp.js'), 'huobipro': require ('./js/huobipro.js'), - 'ice3x': require ('./js/ice3x.js'), 'idex': require ('./js/idex.js'), 'independentreserve': require ('./js/independentreserve.js'), 'indodax': require ('./js/indodax.js'), @@ -166,7 +162,6 @@ const exchanges = { 'tidex': require ('./js/tidex.js'), 'timex': require ('./js/timex.js'), 'upbit': require ('./js/upbit.js'), - 'vaultoro': require ('./js/vaultoro.js'), 'vbtc': require ('./js/vbtc.js'), 'vcc': require ('./js/vcc.js'), 'wavesexchange': require ('./js/wavesexchange.js'), @@ -184,7 +179,7 @@ module.exports = Object.assign ({ version, Exchange, 'exchanges': Object.keys (e //----------------------------------------------------------------------------- -},{"./js/aax.js":3,"./js/acx.js":4,"./js/aofex.js":5,"./js/base/Exchange":6,"./js/base/errors":8,"./js/base/functions":9,"./js/bequant.js":20,"./js/bibox.js":21,"./js/bigone.js":22,"./js/binance.js":23,"./js/binanceus.js":24,"./js/bit2c.js":25,"./js/bitbank.js":26,"./js/bitbay.js":27,"./js/bitcoincom.js":28,"./js/bitfinex.js":29,"./js/bitfinex2.js":30,"./js/bitflyer.js":31,"./js/bitforex.js":32,"./js/bitget.js":33,"./js/bithumb.js":34,"./js/bitkk.js":35,"./js/bitmart.js":36,"./js/bitmax.js":37,"./js/bitmex.js":38,"./js/bitpanda.js":39,"./js/bitso.js":40,"./js/bitstamp.js":41,"./js/bitstamp1.js":42,"./js/bittrex.js":43,"./js/bitvavo.js":44,"./js/bitz.js":45,"./js/bl3p.js":46,"./js/bleutrade.js":47,"./js/braziliex.js":48,"./js/btcalpha.js":49,"./js/btcbox.js":50,"./js/btcmarkets.js":51,"./js/btctradeua.js":52,"./js/btcturk.js":53,"./js/buda.js":54,"./js/bw.js":55,"./js/bybit.js":56,"./js/bytetrade.js":57,"./js/cdax.js":58,"./js/cex.js":59,"./js/chilebit.js":60,"./js/coinbase.js":61,"./js/coinbaseprime.js":62,"./js/coinbasepro.js":63,"./js/coincheck.js":64,"./js/coinegg.js":65,"./js/coinex.js":66,"./js/coinfalcon.js":67,"./js/coinfloor.js":68,"./js/coingi.js":69,"./js/coinmarketcap.js":70,"./js/coinmate.js":71,"./js/coinone.js":72,"./js/coinspot.js":73,"./js/crex24.js":74,"./js/currencycom.js":75,"./js/delta.js":76,"./js/deribit.js":77,"./js/digifinex.js":78,"./js/dsx.js":79,"./js/equos.js":80,"./js/eterbase.js":81,"./js/exmo.js":82,"./js/exx.js":83,"./js/fcoin.js":84,"./js/fcoinjp.js":85,"./js/flowbtc.js":86,"./js/foxbit.js":87,"./js/ftx.js":88,"./js/gateio.js":89,"./js/gemini.js":90,"./js/gopax.js":91,"./js/hbtc.js":92,"./js/hitbtc.js":93,"./js/hollaex.js":94,"./js/huobijp.js":95,"./js/huobipro.js":96,"./js/ice3x.js":97,"./js/idex.js":98,"./js/independentreserve.js":99,"./js/indodax.js":100,"./js/itbit.js":101,"./js/kraken.js":102,"./js/kucoin.js":103,"./js/kuna.js":104,"./js/lakebtc.js":105,"./js/latoken.js":106,"./js/lbank.js":107,"./js/liquid.js":108,"./js/luno.js":109,"./js/lykke.js":110,"./js/mercado.js":111,"./js/mixcoins.js":112,"./js/ndax.js":113,"./js/novadax.js":114,"./js/oceanex.js":115,"./js/okcoin.js":116,"./js/okex.js":117,"./js/paymium.js":118,"./js/phemex.js":119,"./js/poloniex.js":120,"./js/probit.js":121,"./js/qtrade.js":122,"./js/rightbtc.js":123,"./js/ripio.js":124,"./js/southxchange.js":125,"./js/stex.js":166,"./js/surbitcoin.js":167,"./js/therock.js":168,"./js/tidebit.js":169,"./js/tidex.js":170,"./js/timex.js":171,"./js/upbit.js":172,"./js/vaultoro.js":173,"./js/vbtc.js":174,"./js/vcc.js":175,"./js/wavesexchange.js":176,"./js/whitebit.js":177,"./js/xbtce.js":178,"./js/xena.js":179,"./js/yobit.js":180,"./js/zaif.js":181,"./js/zb.js":182}],3:[function(require,module,exports){ +},{"./js/aax.js":3,"./js/aofex.js":4,"./js/ascendex.js":5,"./js/base/Exchange":6,"./js/base/errors":9,"./js/base/functions":10,"./js/bequant.js":21,"./js/bibox.js":22,"./js/bigone.js":23,"./js/binance.js":24,"./js/binanceus.js":25,"./js/bit2c.js":26,"./js/bitbank.js":27,"./js/bitbay.js":28,"./js/bitcoincom.js":29,"./js/bitfinex.js":30,"./js/bitfinex2.js":31,"./js/bitflyer.js":32,"./js/bitforex.js":33,"./js/bitget.js":34,"./js/bithumb.js":35,"./js/bitkk.js":36,"./js/bitmart.js":37,"./js/bitmex.js":38,"./js/bitpanda.js":39,"./js/bitso.js":40,"./js/bitstamp.js":41,"./js/bitstamp1.js":42,"./js/bittrex.js":43,"./js/bitvavo.js":44,"./js/bitz.js":45,"./js/bl3p.js":46,"./js/bleutrade.js":47,"./js/braziliex.js":48,"./js/btcalpha.js":49,"./js/btcbox.js":50,"./js/btcmarkets.js":51,"./js/btctradeua.js":52,"./js/btcturk.js":53,"./js/buda.js":54,"./js/bw.js":55,"./js/bybit.js":56,"./js/bytetrade.js":57,"./js/cdax.js":58,"./js/cex.js":59,"./js/coinbase.js":60,"./js/coinbaseprime.js":61,"./js/coinbasepro.js":62,"./js/coincheck.js":63,"./js/coinegg.js":64,"./js/coinex.js":65,"./js/coinfalcon.js":66,"./js/coinfloor.js":67,"./js/coingi.js":68,"./js/coinmarketcap.js":69,"./js/coinmate.js":70,"./js/coinone.js":71,"./js/coinspot.js":72,"./js/crex24.js":73,"./js/currencycom.js":74,"./js/delta.js":75,"./js/deribit.js":76,"./js/digifinex.js":77,"./js/equos.js":78,"./js/eterbase.js":79,"./js/exmo.js":80,"./js/exx.js":81,"./js/fcoin.js":82,"./js/fcoinjp.js":83,"./js/flowbtc.js":84,"./js/foxbit.js":85,"./js/ftx.js":86,"./js/gateio.js":87,"./js/gemini.js":88,"./js/gopax.js":89,"./js/hbtc.js":90,"./js/hitbtc.js":91,"./js/hollaex.js":92,"./js/huobijp.js":93,"./js/huobipro.js":94,"./js/idex.js":95,"./js/independentreserve.js":96,"./js/indodax.js":97,"./js/itbit.js":98,"./js/kraken.js":99,"./js/kucoin.js":100,"./js/kuna.js":101,"./js/lakebtc.js":102,"./js/latoken.js":103,"./js/lbank.js":104,"./js/liquid.js":105,"./js/luno.js":106,"./js/lykke.js":107,"./js/mercado.js":108,"./js/mixcoins.js":109,"./js/ndax.js":110,"./js/novadax.js":111,"./js/oceanex.js":112,"./js/okcoin.js":113,"./js/okex.js":114,"./js/paymium.js":115,"./js/phemex.js":116,"./js/poloniex.js":117,"./js/probit.js":118,"./js/qtrade.js":119,"./js/rightbtc.js":120,"./js/ripio.js":121,"./js/southxchange.js":122,"./js/stex.js":163,"./js/surbitcoin.js":164,"./js/therock.js":165,"./js/tidebit.js":166,"./js/tidex.js":167,"./js/timex.js":168,"./js/upbit.js":169,"./js/vbtc.js":170,"./js/vcc.js":171,"./js/wavesexchange.js":172,"./js/whitebit.js":173,"./js/xbtce.js":174,"./js/xena.js":175,"./js/yobit.js":176,"./js/zaif.js":177,"./js/zb.js":178}],3:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -192,6 +187,7 @@ module.exports = Object.assign ({ version, Exchange, 'exchanges': Object.keys (e const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, ExchangeNotAvailable, OrderNotFound, InvalidOrder, CancelPending, RateLimitExceeded, InsufficientFunds, BadRequest, BadSymbol, PermissionDenied } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -222,6 +218,7 @@ module.exports = class aax extends Exchange { 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, + 'fetchStatus': true, 'fetchTicker': 'emulated', 'fetchTickers': true, 'fetchTrades': true, @@ -420,6 +417,37 @@ module.exports = class aax extends Exchange { }); } + async fetchStatus (params = {}) { + const response = await this.publicGetAnnouncementMaintenance (params); + // + // { + // "code": 1, + // "data": { + // "startTime":"2020-06-25T02:15:00.000Z", + // "endTime":"2020-06-25T02:45:00.000Z", + // "description":"Spot Trading :UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45),Futures Trading: UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45).We apologize for any inconvenience caused. Thank you for your patience and understanding.Should you have any enquiries, please do not hesitate our live chat support or via email at cs@aax.com." + // }, + // "message":"success", + // "ts":1593043237000 + // } + // + const data = this.safeValue (response, 'data', {}); + const timestamp = this.milliseconds (); + const startTime = this.parse8601 (this.safeString (data, 'startTime')); + const endTime = this.parse8601 (this.safeString (data, 'endTime')); + const update = { + 'updated': this.safeInteger (response, 'ts', timestamp), + }; + if (endTime !== undefined) { + const startTimeIsOk = (startTime === undefined) ? true : (timestamp < startTime); + const isOk = (timestamp > endTime) || startTimeIsOk; + update['eta'] = endTime; + update['status'] = isOk ? 'ok' : 'maintenance'; + } + this.status = this.extend (this.status, update); + return this.status; + } + async fetchMarkets (params = {}) { const response = await this.publicGetInstruments (params); // @@ -505,8 +533,8 @@ module.exports = class aax extends Exchange { const quote = this.safeCurrencyCode (quoteId); const status = this.safeString (market, 'status'); const active = (status === 'enable'); - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); const type = this.safeString (market, 'type'); let inverse = undefined; let linear = undefined; @@ -524,8 +552,8 @@ module.exports = class aax extends Exchange { symbol = base + '/' + quote; } const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; result.push ({ 'id': id, @@ -583,8 +611,8 @@ module.exports = class aax extends Exchange { const timestamp = this.safeInteger (ticker, 't'); const marketId = this.safeString (ticker, 's'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'c'); - const open = this.safeFloat (ticker, 'o'); + const last = this.safeNumber (ticker, 'c'); + const open = this.safeNumber (ticker, 'o'); let change = undefined; let percentage = undefined; let average = undefined; @@ -595,13 +623,13 @@ module.exports = class aax extends Exchange { } average = this.sum (last, open) / 2; } - const quoteVolume = this.safeFloat (ticker, 'v'); + const quoteVolume = this.safeNumber (ticker, 'v'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'h'), - 'low': this.safeFloat (ticker, 'l'), + 'high': this.safeNumber (ticker, 'h'), + 'low': this.safeNumber (ticker, 'l'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -748,8 +776,8 @@ module.exports = class aax extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let price = this.safeFloat2 (trade, 'p', 'filledPrice'); - const amount = this.safeFloat2 (trade, 'q', 'filledQty'); + let priceString = this.safeString2 (trade, 'p', 'filledPrice'); + const amountString = this.safeString2 (trade, 'q', 'filledQty'); const orderId = this.safeString (trade, 'orderID'); const isTaker = this.safeValue (trade, 'taker'); let takerOrMaker = undefined; @@ -763,17 +791,15 @@ module.exports = class aax extends Exchange { side = 'sell'; } if (side === undefined) { - side = (price > 0) ? 'buy' : 'sell'; - } - side = (price > 0) ? 'buy' : 'sell'; - price = Math.abs (price); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; + side = (priceString[0] === '-') ? 'sell' : 'buy'; } + priceString = (priceString[0] === '-') ? priceString.slice (1) : priceString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderType = this.parseOrderType (this.safeString (trade, 'orderType')); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -841,11 +867,11 @@ module.exports = class aax extends Exchange { // return [ this.safeTimestamp (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -930,12 +956,12 @@ module.exports = class aax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'unavailable'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'unavailable'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -963,7 +989,7 @@ module.exports = class aax extends Exchange { request['clOrdID'] = clientOrderId; params = this.omit (params, [ 'clOrdID', 'clientOrderId' ]); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { if ((orderType === 'STOP-LIMIT') || (orderType === 'STOP')) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for ' + orderType + ' orders'); @@ -1081,7 +1107,7 @@ module.exports = class aax extends Exchange { // 'price': this.priceToPrecision (symbol, price), // 'stopPrice': this.priceToPrecision (symbol, stopPrice), }; - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1718,15 +1744,18 @@ module.exports = class aax extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const price = this.safeFloat (order, 'price'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const price = this.safeNumber (order, 'price'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'Post-Only'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeString (order, 'leavesQty'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + let remaining = this.safeNumber (order, 'leavesQty'); + if ((filled === 0) && (remaining === 0)) { + remaining = undefined; + } let cost = undefined; let lastTradeTimestamp = undefined; if (filled !== undefined) { @@ -1741,7 +1770,7 @@ module.exports = class aax extends Exchange { } } let fee = undefined; - const feeCost = this.safeFloat (order, 'commission'); + const feeCost = this.safeNumber (order, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -1970,496 +1999,7 @@ module.exports = class aax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],4:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { InsufficientFunds, OrderNotFound } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class acx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'acx', - 'name': 'ACX', - 'countries': [ 'AU' ], - 'rateLimit': 1000, - 'version': 'v2', - 'has': { - 'cancelOrder': true, - 'CORS': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchMarkets': true, - 'fetchOHLCV': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTime': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '12h': '720', - '1d': '1440', - '3d': '4320', - '1w': '10080', - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg', - 'extension': '.json', - 'api': 'https://acx.io/api', - 'www': 'https://acx.io', - 'doc': 'https://acx.io/documents/api_v2', - }, - 'api': { - 'public': { - 'get': [ - 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. - 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator - 'k', // Get OHLC(k line) of specific market - 'markets', // Get all available markets - 'order_book', // Get the order book of specified market - 'order_book/{market}', - 'tickers', // Get ticker of all markets - 'tickers/{market}', // Get ticker of specific market - 'timestamp', // Get server current time, in seconds since Unix epoch - 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. - 'trades/{market}', - ], - }, - 'private': { - 'get': [ - 'members/me', // Get your profile and accounts info - 'deposits', // Get your deposits history - 'deposit', // Get details of specific deposit - 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. - 'orders', // Get your orders, results is paginated - 'order', // Get information of specified order - 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. - 'withdraws', // Get your cryptocurrency withdraws - 'withdraw', // Get your cryptocurrency withdraw - ], - 'post': [ - 'orders', // Create a Sell/Buy order - 'orders/multi', // Create multiple sell/buy orders - 'orders/clear', // Cancel all my orders - 'order/delete', // Cancel an order - 'withdraw', // Create a withdraw - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': false, - 'percentage': true, - 'maker': 0.2 / 100, - 'taker': 0.2 / 100, - }, - 'funding': { - 'tierBased': false, - 'percentage': true, - 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account. - }, - }, - 'commonCurrencies': { - 'PLA': 'Plair', - }, - 'exceptions': { - '2002': InsufficientFunds, - '2003': OrderNotFound, - }, - }); - } - - async fetchMarkets (params = {}) { - const markets = await this.publicGetMarkets (params); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = market['id']; - const symbol = market['name']; - let baseId = this.safeString (market, 'base_unit'); - let quoteId = this.safeString (market, 'quote_unit'); - if ((baseId === undefined) || (quoteId === undefined)) { - const ids = symbol.split ('/'); - baseId = ids[0].toLowerCase (); - quoteId = ids[1].toLowerCase (); - } - let base = baseId.toUpperCase (); - let quote = quoteId.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - // todo: find out their undocumented precision and limits - const precision = { - 'amount': 8, - 'price': 8, - }; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'precision': precision, - 'info': market, - 'active': undefined, - 'limits': this.limits, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetMembersMe (params); - const balances = this.safeValue (response, 'accounts'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 300 - } - const orderbook = await this.publicGetDepth (this.extend (request, params)); - const timestamp = this.safeTimestamp (orderbook, 'timestamp'); - return this.parseOrderBook (orderbook, timestamp); - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.safeTimestamp (ticker, 'at'); - ticker = ticker['ticker']; - let symbol = undefined; - if (market) { - symbol = market['symbol']; - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetTickers (params); - const ids = Object.keys (response); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let market = undefined; - let symbol = id; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } else { - let base = id.slice (0, 3); - let quote = id.slice (3, 6); - base = base.toUpperCase (); - quote = quote.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - symbol = base + '/' + quote; - } - result[symbol] = this.parseTicker (response[id], market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTickersMarket (this.extend (request, params)); - return this.parseTicker (response, market); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const id = this.safeString (trade, 'tid'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': undefined, - 'side': undefined, - 'order': undefined, - 'takerOrMaker': undefined, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), - 'cost': this.safeFloat (trade, 'funds'), - 'fee': undefined, - }; - } - - async fetchTime (params = {}) { - const response = await this.publicGetTimestamp (params); - // - // 1594911427 - // - return response * 1000; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - return [ - this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (limit === undefined) { - limit = 500; // default is 30 - } - const request = { - 'market': market['id'], - 'period': this.timeframes[timeframe], - 'limit': limit, - }; - if (since !== undefined) { - request['timestamp'] = parseInt (since / 1000); - } - const response = await this.publicGetK (this.extend (request, params)); - return this.parseOHLCVs (response, market, timeframe, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'done': 'closed', - 'wait': 'open', - 'cancel': 'canceled', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - const marketId = this.safeString (order, 'market'); - const symbol = this.safeSymbol (marketId, market); - const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const status = this.parseOrderStatus (this.safeString (order, 'state')); - const type = this.safeString (order, 'type'); - const side = this.safeString (order, 'side'); - const id = this.safeString (order, 'id'); - return { - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': this.safeFloat (order, 'price'), - 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'volume'), - 'filled': this.safeFloat (order, 'executed_volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'trades': undefined, - 'fee': undefined, - 'info': order, - 'cost': undefined, - 'average': undefined, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': parseInt (id), - }; - const response = await this.privateGetOrder (this.extend (request, params)); - return this.parseOrder (response); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'market': this.marketId (symbol), - 'side': side, - 'volume': amount.toString (), - 'ord_type': type, - }; - if (type === 'limit') { - request['price'] = price.toString (); - } - const response = await this.privatePostOrders (this.extend (request, params)); - const marketId = this.safeValue (response, 'market'); - const market = this.safeValue (this.markets_by_id, marketId); - return this.parseOrder (response, market); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - const response = await this.privatePostOrderDelete (this.extend (request, params)); - const order = this.parseOrder (response); - const status = order['status']; - if (status === 'closed' || status === 'canceled') { - throw new OrderNotFound (this.id + ' ' + this.json (order)); - } - return order; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - // they have XRP but no docs on memo/tag - const request = { - 'currency': currency['id'], - 'sum': amount, - 'address': address, - }; - const response = await this.privatePostWithdraw (this.extend (request, params)); - // withdrawal response is undocumented - return { - 'info': response, - 'id': undefined, - }; - } - - nonce () { - return this.milliseconds (); - } - - encodeParams (params) { - if ('orders' in params) { - const orders = params['orders']; - let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); - for (let i = 0; i < orders.length; i++) { - const order = orders[i]; - const keys = Object.keys (order); - for (let k = 0; k < keys.length; k++) { - const key = keys[k]; - const value = order[key]; - query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); - } - } - return query; - } - return this.urlencode (this.keysort (params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let request = '/api/' + this.version + '/' + this.implodeParams (path, params); - if ('extension' in this.urls) { - request += this.urls['extension']; - } - const query = this.omit (params, this.extractParams (path)); - let url = this.urls['api'] + request; - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce ().toString (); - const query = this.encodeParams (this.extend ({ - 'access_key': this.apiKey, - 'tonce': nonce, - }, params)); - const auth = method + '|' + request + '|' + query; - const signed = this.hmac (this.encode (auth), this.encode (this.secret)); - const suffix = query + '&signature=' + signed; - if (method === 'GET') { - url += '?' + suffix; - } else { - body = suffix; - headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; - } - if (code === 400) { - const error = this.safeValue (response, 'error'); - const errorCode = this.safeString (error, 'code'); - const feedback = this.id + ' ' + this.json (response); - this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); - // fallback to default error handler - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],5:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],4:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -2467,6 +2007,7 @@ module.exports = class acx extends Exchange { const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, BadSymbol, InvalidOrder, PermissionDenied, InvalidAddress, AuthenticationError, InvalidNonce, BadRequest, InsufficientFunds, OrderNotFound } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -2655,8 +2196,8 @@ module.exports = class aofex extends Exchange { const symbol = base + '/' + quote; const numericId = this.safeInteger (market, 'id'); const precision = this.safeValue (precisions, id, {}); - const makerFee = this.safeFloat (market, 'maker_fee'); - const takerFee = this.safeFloat (market, 'taker_fee'); + const makerFee = this.safeNumber (market, 'maker_fee'); + const takerFee = this.safeNumber (market, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -2674,12 +2215,12 @@ module.exports = class aofex extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -2707,11 +2248,11 @@ module.exports = class aofex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -2790,11 +2331,11 @@ module.exports = class aofex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -2817,8 +2358,8 @@ module.exports = class aofex extends Exchange { return { 'info': response, 'symbol': symbol, - 'maker': this.safeFloat (result, 'fromFee'), - 'taker': this.safeFloat (result, 'toFee'), + 'maker': this.safeNumber (result, 'fromFee'), + 'taker': this.safeNumber (result, 'toFee'), }; } @@ -2875,8 +2416,8 @@ module.exports = class aofex extends Exchange { if (market) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); let change = undefined; if (symbol !== undefined) { change = parseFloat (this.priceToPrecision (symbol, last - open)); @@ -2885,8 +2426,8 @@ module.exports = class aofex extends Exchange { } const average = this.sum (last, open) / 2; const percentage = change / open * 100; - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); let vwap = this.vwap (baseVolume, quoteVolume); if (vwap !== undefined) { vwap = parseFloat (this.priceToPrecision (symbol, vwap)); @@ -2895,8 +2436,8 @@ module.exports = class aofex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -3014,13 +2555,15 @@ module.exports = class aofex extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'number'); - let cost = this.safeFloat (trade, 'total_price'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'number'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total_price'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -3164,21 +2707,21 @@ module.exports = class aofex extends Exchange { const orderType = this.safeString (order, 'type'); const type = (orderType === '2') ? 'limit' : 'market'; const side = this.safeString (order, 'side'); - // const amount = this.safeFloat (order, 'number'); - // const price = this.safeFloat (order, 'price'); + // const amount = this.safeNumber (order, 'number'); + // const price = this.safeNumber (order, 'price'); let cost = undefined; let price = undefined; let amount = undefined; let average = undefined; - const number = this.safeFloat (order, 'number'); - const totalPrice = this.safeFloat (order, 'total_price'); + const number = this.safeNumber (order, 'number'); + const totalPrice = this.safeNumber (order, 'total_price'); if (type === 'limit') { amount = number; - price = this.safeFloat (order, 'price'); + price = this.safeNumber (order, 'price'); } else { - average = this.safeFloat (order, 'deal_price'); + average = this.safeNumber (order, 'deal_price'); if (side === 'buy') { - amount = this.safeFloat (order, 'deal_number'); + amount = this.safeNumber (order, 'deal_number'); } else { amount = number; } @@ -3561,7 +3104,1693 @@ module.exports = class aofex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],6:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],5:[function(require,module,exports){ +'use strict'; + +// --------------------------------------------------------------------------- + +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); + +// --------------------------------------------------------------------------- + +module.exports = class ascendex extends Exchange { + describe () { + return this.deepExtend (super.describe (), { + 'id': 'ascendex', + 'name': 'AscendEX', + 'countries': [ 'SG', 'CN' ], // Singapore, China + 'rateLimit': 500, + // new metainfo interface + 'has': { + 'CORS': false, + 'fetchMarkets': true, + 'fetchCurrencies': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchOHLCV': true, + 'fetchTrades': true, + 'fetchAccounts': true, + 'fetchBalance': true, + 'createOrder': true, + 'cancelOrder': true, + 'cancelAllOrders': true, + 'fetchDepositAddress': true, + 'fetchTransactions': true, + 'fetchDeposits': true, + 'fetchWithdrawals': true, + 'fetchOrder': true, + 'fetchOrders': true, + 'fetchOpenOrders': true, + 'fetchClosedOrders': true, + }, + 'timeframes': { + '1m': '1', + '5m': '5', + '15m': '15', + '30m': '30', + '1h': '60', + '2h': '120', + '4h': '240', + '6h': '360', + '12h': '720', + '1d': '1d', + '1w': '1w', + '1M': '1m', + }, + 'version': 'v1', + 'urls': { + 'logo': 'https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg', + 'api': 'https://ascendex.com', + 'test': 'https://bitmax-test.io', + 'www': 'https://ascendex.com', + 'doc': [ + 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', + ], + 'fees': 'https://ascendex.com/en/feerate/transactionfee-traderate', + 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', + }, + 'api': { + 'public': { + 'get': [ + 'assets', + 'products', + 'ticker', + 'barhist/info', + 'barhist', + 'depth', + 'trades', + 'cash/assets', // not documented + 'cash/products', // not documented + 'margin/assets', // not documented + 'margin/products', // not documented + 'futures/collateral', + 'futures/contracts', + 'futures/ref-px', + 'futures/market-data', + 'futures/funding-rates', + ], + }, + 'accountCategory': { + 'get': [ + 'balance', + 'order/open', + 'order/status', + 'order/hist/current', + 'risk', + ], + 'post': [ + 'order', + 'order/batch', + ], + 'delete': [ + 'order', + 'order/all', + 'order/batch', + ], + }, + 'accountGroup': { + 'get': [ + 'cash/balance', + 'margin/balance', + 'margin/risk', + 'transfer', + 'futures/collateral-balance', + 'futures/position', + 'futures/risk', + 'futures/funding-payments', + 'order/hist', + ], + 'post': [ + 'futures/transfer/deposit', + 'futures/transfer/withdraw', + ], + }, + 'private': { + 'get': [ + 'info', + 'wallet/transactions', + 'wallet/deposit/address', // not documented + ], + }, + }, + 'fees': { + 'trading': { + 'feeSide': 'get', + 'tierBased': true, + 'percentage': true, + 'taker': 0.002, + 'maker': 0.002, + }, + }, + 'precisionMode': TICK_SIZE, + 'options': { + 'account-category': 'cash', // 'cash'/'margin'/'futures' + 'account-group': undefined, + 'fetchClosedOrders': { + 'method': 'accountGroupGetOrderHist', // 'accountGroupGetAccountCategoryOrderHistCurrent' + }, + }, + 'exceptions': { + 'exact': { + // not documented + '1900': BadRequest, // {"code":1900,"message":"Invalid Http Request Input"} + '2100': AuthenticationError, // {"code":2100,"message":"ApiKeyFailure"} + '5002': BadSymbol, // {"code":5002,"message":"Invalid Symbol"} + '6001': BadSymbol, // {"code":6001,"message":"Trading is disabled on symbol."} + '6010': InsufficientFunds, // {'code': 6010, 'message': 'Not enough balance.'} + '60060': InvalidOrder, // { 'code': 60060, 'message': 'The order is already filled or canceled.' } + '600503': InvalidOrder, // {"code":600503,"message":"Notional is too small."} + // documented + '100001': BadRequest, // INVALID_HTTP_INPUT Http request is invalid + '100002': BadRequest, // DATA_NOT_AVAILABLE Some required data is missing + '100003': BadRequest, // KEY_CONFLICT The same key exists already + '100004': BadRequest, // INVALID_REQUEST_DATA The HTTP request contains invalid field or argument + '100005': BadRequest, // INVALID_WS_REQUEST_DATA Websocket request contains invalid field or argument + '100006': BadRequest, // INVALID_ARGUMENT The arugment is invalid + '100007': BadRequest, // ENCRYPTION_ERROR Something wrong with data encryption + '100008': BadSymbol, // SYMBOL_ERROR Symbol does not exist or not valid for the request + '100009': AuthenticationError, // AUTHORIZATION_NEEDED Authorization is require for the API access or request + '100010': BadRequest, // INVALID_OPERATION The action is invalid or not allowed for the account + '100011': BadRequest, // INVALID_TIMESTAMP Not a valid timestamp + '100012': BadRequest, // INVALID_STR_FORMAT String format does not + '100013': BadRequest, // INVALID_NUM_FORMAT Invalid number input + '100101': ExchangeError, // UNKNOWN_ERROR Some unknown error + '150001': BadRequest, // INVALID_JSON_FORMAT Require a valid json object + '200001': AuthenticationError, // AUTHENTICATION_FAILED Authorization failed + '200002': ExchangeError, // TOO_MANY_ATTEMPTS Tried and failed too many times + '200003': ExchangeError, // ACCOUNT_NOT_FOUND Account not exist + '200004': ExchangeError, // ACCOUNT_NOT_SETUP Account not setup properly + '200005': ExchangeError, // ACCOUNT_ALREADY_EXIST Account already exist + '200006': ExchangeError, // ACCOUNT_ERROR Some error related with error + '200007': ExchangeError, // CODE_NOT_FOUND + '200008': ExchangeError, // CODE_EXPIRED Code expired + '200009': ExchangeError, // CODE_MISMATCH Code does not match + '200010': AuthenticationError, // PASSWORD_ERROR Wrong assword + '200011': ExchangeError, // CODE_GEN_FAILED Do not generate required code promptly + '200012': ExchangeError, // FAKE_COKE_VERIFY + '200013': ExchangeError, // SECURITY_ALERT Provide security alert message + '200014': PermissionDenied, // RESTRICTED_ACCOUNT Account is restricted for certain activity, such as trading, or withdraw. + '200015': PermissionDenied, // PERMISSION_DENIED No enough permission for the operation + '300001': InvalidOrder, // INVALID_PRICE Order price is invalid + '300002': InvalidOrder, // INVALID_QTY Order size is invalid + '300003': InvalidOrder, // INVALID_SIDE Order side is invalid + '300004': InvalidOrder, // INVALID_NOTIONAL Notional is too small or too large + '300005': InvalidOrder, // INVALID_TYPE Order typs is invalid + '300006': InvalidOrder, // INVALID_ORDER_ID Order id is invalid + '300007': InvalidOrder, // INVALID_TIME_IN_FORCE Time In Force in order request is invalid + '300008': InvalidOrder, // INVALID_ORDER_PARAMETER Some order parameter is invalid + '300009': InvalidOrder, // TRADING_VIOLATION Trading violation on account or asset + '300011': InsufficientFunds, // INVALID_BALANCE No enough account or asset balance for the trading + '300012': BadSymbol, // INVALID_PRODUCT Not a valid product supported by exchange + '300013': InvalidOrder, // INVALID_BATCH_ORDER Some or all orders are invalid in batch order request + '300020': InvalidOrder, // TRADING_RESTRICTED There is some trading restriction on account or asset + '300021': InvalidOrder, // TRADING_DISABLED Trading is disabled on account or asset + '300031': InvalidOrder, // NO_MARKET_PRICE No market price for market type order trading + '310001': InsufficientFunds, // INVALID_MARGIN_BALANCE No enough margin balance + '310002': InvalidOrder, // INVALID_MARGIN_ACCOUNT Not a valid account for margin trading + '310003': InvalidOrder, // MARGIN_TOO_RISKY Leverage is too high + '310004': BadSymbol, // INVALID_MARGIN_ASSET This asset does not support margin trading + '310005': InvalidOrder, // INVALID_REFERENCE_PRICE There is no valid reference price + '510001': ExchangeError, // SERVER_ERROR Something wrong with server. + '900001': ExchangeError, // HUMAN_CHALLENGE Human change do not pass + }, + 'broad': {}, + }, + 'commonCurrencies': { + 'BOND': 'BONDED', + 'BTCBEAR': 'BEAR', + 'BTCBULL': 'BULL', + }, + }); + } + + getAccount (params = {}) { + // get current or provided bitmax sub-account + const account = this.safeValue (params, 'account', this.options['account']); + return account.toLowerCase ().capitalize (); + } + + async fetchCurrencies (params = {}) { + const assets = await this.publicGetAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode" : "LTCBULL", + // "assetName" : "3X Long LTC Token", + // "precisionScale" : 9, + // "nativeScale" : 4, + // "withdrawalFee" : "0.2", + // "minWithdrawalAmt" : "1.0", + // "status" : "Normal" + // }, + // ] + // } + // + const margin = await this.publicGetMarginAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode":"BTT", + // "borrowAssetCode":"BTT-B", + // "interestAssetCode":"BTT-I", + // "nativeScale":0, + // "numConfirmations":1, + // "withdrawFee":"100.0", + // "minWithdrawalAmt":"1000.0", + // "statusCode":"Normal", + // "statusMessage":"", + // "interestRate":"0.001" + // } + // ] + // } + // + const cash = await this.publicGetCashAssets (params); + // + // { + // "code":0, + // "data":[ + // { + // "assetCode":"LTCBULL", + // "nativeScale":4, + // "numConfirmations":20, + // "withdrawFee":"0.2", + // "minWithdrawalAmt":"1.0", + // "statusCode":"Normal", + // "statusMessage":"" + // } + // ] + // } + // + const assetsData = this.safeValue (assets, 'data', []); + const marginData = this.safeValue (margin, 'data', []); + const cashData = this.safeValue (cash, 'data', []); + const assetsById = this.indexBy (assetsData, 'assetCode'); + const marginById = this.indexBy (marginData, 'assetCode'); + const cashById = this.indexBy (cashData, 'assetCode'); + const dataById = this.deepExtend (assetsById, marginById, cashById); + const ids = Object.keys (dataById); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + const currency = dataById[id]; + const code = this.safeCurrencyCode (id); + const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); + // why would the exchange API have different names for the same field + const fee = this.safeNumber2 (currency, 'withdrawFee', 'withdrawalFee'); + const status = this.safeString2 (currency, 'status', 'statusCode'); + const active = (status === 'Normal'); + const margin = ('borrowAssetCode' in currency); + result[code] = { + 'id': id, + 'code': code, + 'info': currency, + 'type': undefined, + 'margin': margin, + 'name': this.safeString (currency, 'assetName'), + 'active': active, + 'fee': fee, + 'precision': precision, + 'limits': { + 'amount': { + 'min': Math.pow (10, -precision), + 'max': undefined, + }, + 'price': { + 'min': Math.pow (10, -precision), + 'max': undefined, + }, + 'cost': { + 'min': undefined, + 'max': undefined, + }, + 'withdraw': { + 'min': this.safeNumber (currency, 'minWithdrawalAmt'), + 'max': undefined, + }, + }, + }; + } + return result; + } + + async fetchMarkets (params = {}) { + const products = await this.publicGetProducts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"LBA/BTC", + // "baseAsset":"LBA", + // "quoteAsset":"BTC", + // "status":"Normal", + // "minNotional":"0.000625", + // "maxNotional":"6.25", + // "marginTradable":false, + // "commissionType":"Quote", + // "commissionReserveRate":"0.001", + // "tickSize":"0.000000001", + // "lotSize":"1" + // }, + // ] + // } + // + const cash = await this.publicGetCashProducts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"QTUM/BTC", + // "domain":"BTC", + // "tradingStartTime":1569506400000, + // "collapseDecimals":"0.0001,0.000001,0.00000001", + // "minQty":"0.000000001", + // "maxQty":"1000000000", + // "minNotional":"0.000625", + // "maxNotional":"12.5", + // "statusCode":"Normal", + // "statusMessage":"", + // "tickSize":"0.00000001", + // "useTick":false, + // "lotSize":"0.1", + // "useLot":false, + // "commissionType":"Quote", + // "commissionReserveRate":"0.001", + // "qtyScale":1, + // "priceScale":8, + // "notionalScale":4 + // } + // ] + // } + // + const futures = await this.publicGetFuturesContracts (params); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"BTC-PERP", + // "tradingStartTime":1579701600000, + // "collapseDecimals":"1,0.1,0.01", + // "minQty":"0.000000001", + // "maxQty":"1000000000", + // "minNotional":"5", + // "maxNotional":"1000000", + // "statusCode":"Normal", + // "statusMessage":"", + // "tickSize":"0.25", + // "lotSize":"0.0001", + // "priceScale":2, + // "qtyScale":4, + // "notionalScale":2 + // } + // ] + // } + // + const productsData = this.safeValue (products, 'data', []); + const productsById = this.indexBy (productsData, 'symbol'); + const cashData = this.safeValue (cash, 'data', []); + const futuresData = this.safeValue (futures, 'data', []); + const cashAndFuturesData = this.arrayConcat (cashData, futuresData); + const cashAndFuturesById = this.indexBy (cashAndFuturesData, 'symbol'); + const dataById = this.deepExtend (productsById, cashAndFuturesById); + const ids = Object.keys (dataById); + const result = []; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + const market = dataById[id]; + const baseId = this.safeString (market, 'baseAsset'); + const quoteId = this.safeString (market, 'quoteAsset'); + const base = this.safeCurrencyCode (baseId); + const quote = this.safeCurrencyCode (quoteId); + const precision = { + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), + }; + const status = this.safeString (market, 'status'); + const active = (status === 'Normal'); + const type = ('useLot' in market) ? 'spot' : 'future'; + const spot = (type === 'spot'); + const future = (type === 'future'); + let symbol = id; + if (!future) { + symbol = base + '/' + quote; + } + result.push ({ + 'id': id, + 'symbol': symbol, + 'base': base, + 'quote': quote, + 'baseId': baseId, + 'quoteId': quoteId, + 'info': market, + 'type': type, + 'spot': spot, + 'future': future, + 'active': active, + 'precision': precision, + 'limits': { + 'amount': { + 'min': this.safeNumber (market, 'minQty'), + 'max': this.safeNumber (market, 'maxQty'), + }, + 'price': { + 'min': this.safeNumber (market, 'tickSize'), + 'max': undefined, + }, + 'cost': { + 'min': this.safeNumber (market, 'minNotional'), + 'max': this.safeNumber (market, 'maxNotional'), + }, + }, + }); + } + return result; + } + + async fetchAccounts (params = {}) { + let accountGroup = this.safeString (this.options, 'account-group'); + let response = undefined; + if (accountGroup === undefined) { + response = await this.privateGetInfo (params); + // + // { + // "code":0, + // "data":{ + // "email":"igor.kroitor@gmail.com", + // "accountGroup":8, + // "viewPermission":true, + // "tradePermission":true, + // "transferPermission":true, + // "cashAccount":["cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda"], + // "marginAccount":["martXoh1v1N3EMQC5FDtSj5VHso8aI2Z"], + // "futuresAccount":["futc9r7UmFJAyBY2rE3beA2JFxav2XFF"], + // "userUID":"U6491137460" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + accountGroup = this.safeString (data, 'accountGroup'); + this.options['account-group'] = accountGroup; + } + return [ + { + 'id': accountGroup, + 'type': undefined, + 'currency': undefined, + 'info': response, + }, + ]; + } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchBalance', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeString (account, 'id'); + const request = { + 'account-group': accountGroup, + }; + let method = 'accountCategoryGetBalance'; + if (accountCategory === 'futures') { + method = 'accountGroupGetFuturesCollateralBalance'; + } else { + request['account-category'] = accountCategory; + } + const response = await this[method] (this.extend (request, params)); + // + // cash + // + // { + // 'code': 0, + // 'data': [ + // { + // 'asset': 'BCHSV', + // 'totalBalance': '64.298000048', + // 'availableBalance': '64.298000048', + // }, + // ] + // } + // + // margin + // + // { + // 'code': 0, + // 'data': [ + // { + // 'asset': 'BCHSV', + // 'totalBalance': '64.298000048', + // 'availableBalance': '64.298000048', + // 'borrowed': '0', + // 'interest': '0', + // }, + // ] + // } + // + // futures + // + // { + // "code":0, + // "data":[ + // {"asset":"BTC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"9456.59"}, + // {"asset":"ETH","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"235.95"}, + // {"asset":"USDT","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"}, + // {"asset":"USDC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00035"}, + // {"asset":"PAX","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00045"}, + // {"asset":"USDTR","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"} + // ] + // } + // + const result = { 'info': response }; + const balances = this.safeValue (response, 'data', []); + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); + const account = this.account (); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async fetchOrderBook (symbol, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + const response = await this.publicGetDepth (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "m":"depth-snapshot", + // "symbol":"BTC-PERP", + // "data":{ + // "ts":1590223998202, + // "seqnum":115444921, + // "asks":[ + // ["9207.5","18.2383"], + // ["9207.75","18.8235"], + // ["9208","10.7873"], + // ], + // "bids":[ + // ["9207.25","0.4009"], + // ["9207","0.003"], + // ["9206.5","0.003"], + // ] + // } + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const orderbook = this.safeValue (data, 'data', {}); + const timestamp = this.safeInteger (orderbook, 'ts'); + const result = this.parseOrderBook (orderbook, timestamp); + result['nonce'] = this.safeInteger (orderbook, 'seqnum'); + return result; + } + + parseTicker (ticker, market = undefined) { + // + // { + // "symbol":"QTUM/BTC", + // "open":"0.00016537", + // "close":"0.00019077", + // "high":"0.000192", + // "low":"0.00016537", + // "volume":"846.6", + // "ask":["0.00018698","26.2"], + // "bid":["0.00018408","503.7"], + // "type":"spot" + // } + // + const timestamp = undefined; + const marketId = this.safeString (ticker, 'symbol'); + let symbol = undefined; + if (marketId in this.markets_by_id) { + market = this.markets_by_id[marketId]; + } else if (marketId !== undefined) { + const type = this.safeString (ticker, 'type'); + if (type === 'spot') { + const [ baseId, quoteId ] = marketId.split ('/'); + const base = this.safeCurrencyCode (baseId); + const quote = this.safeCurrencyCode (quoteId); + symbol = base + '/' + quote; + } + } + if ((symbol === undefined) && (market !== undefined)) { + symbol = market['symbol']; + } + const close = this.safeNumber (ticker, 'close'); + const bid = this.safeValue (ticker, 'bid', []); + const ask = this.safeValue (ticker, 'ask', []); + const open = this.safeNumber (ticker, 'open'); + let change = undefined; + let percentage = undefined; + let average = undefined; + if ((open !== undefined) && (close !== undefined)) { + change = close - open; + if (open > 0) { + percentage = change / open * 100; + } + average = this.sum (open, close) / 2; + } + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 0), + 'bidVolume': this.safeNumber (bid, 1), + 'ask': this.safeNumber (ask, 0), + 'askVolume': this.safeNumber (ask, 1), + 'vwap': undefined, + 'open': open, + 'close': close, + 'last': close, + 'previousClose': undefined, // previous day close + 'change': change, + 'percentage': percentage, + 'average': average, + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + const response = await this.publicGetTicker (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "symbol":"BTC-PERP", // or "BTC/USDT" + // "open":"9073", + // "close":"9185.75", + // "high":"9185.75", + // "low":"9185.75", + // "volume":"576.8334", + // "ask":["9185.75","15.5863"], + // "bid":["9185.5","0.003"], + // "type":"derivatives", // or "spot" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + return this.parseTicker (data, market); + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (symbols !== undefined) { + const marketIds = this.marketIds (symbols); + request['symbol'] = marketIds.join (','); + } + const response = await this.publicGetTicker (this.extend (request, params)); + // + // { + // "code":0, + // "data":[ + // { + // "symbol":"QTUM/BTC", + // "open":"0.00016537", + // "close":"0.00019077", + // "high":"0.000192", + // "low":"0.00016537", + // "volume":"846.6", + // "ask":["0.00018698","26.2"], + // "bid":["0.00018408","503.7"], + // "type":"spot" + // } + // ] + // } + // + const data = this.safeValue (response, 'data', []); + return this.parseTickers (data, symbols); + } + + parseOHLCV (ohlcv, market = undefined) { + // + // { + // "m":"bar", + // "s":"BTC/USDT", + // "data":{ + // "i":"1", + // "ts":1590228000000, + // "o":"9139.59", + // "c":"9131.94", + // "h":"9139.99", + // "l":"9121.71", + // "v":"25.20648" + // } + // } + // + const data = this.safeValue (ohlcv, 'data', {}); + return [ + this.safeInteger (data, 'ts'), + this.safeNumber (data, 'o'), + this.safeNumber (data, 'h'), + this.safeNumber (data, 'l'), + this.safeNumber (data, 'c'), + this.safeNumber (data, 'v'), + ]; + } + + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + 'interval': this.timeframes[timeframe], + }; + // if since and limit are not specified + // the exchange will return just 1 last candle by default + const duration = this.parseTimeframe (timeframe); + const options = this.safeValue (this.options, 'fetchOHLCV', {}); + const defaultLimit = this.safeInteger (options, 'limit', 500); + if (since !== undefined) { + request['from'] = since; + if (limit === undefined) { + limit = defaultLimit; + } else { + limit = Math.min (limit, defaultLimit); + } + request['to'] = this.sum (since, limit * duration * 1000, 1); + } else if (limit !== undefined) { + request['n'] = limit; // max 500 + } + const response = await this.publicGetBarhist (this.extend (request, params)); + // + // { + // "code":0, + // "data":[ + // { + // "m":"bar", + // "s":"BTC/USDT", + // "data":{ + // "i":"1", + // "ts":1590228000000, + // "o":"9139.59", + // "c":"9131.94", + // "h":"9139.99", + // "l":"9121.71", + // "v":"25.20648" + // } + // } + // ] + // } + // + const data = this.safeValue (response, 'data', []); + return this.parseOHLCVs (data, market, timeframe, since, limit); + } + + parseTrade (trade, market = undefined) { + // + // public fetchTrades + // + // { + // "p":"9128.5", // price + // "q":"0.0030", // quantity + // "ts":1590229002385, // timestamp + // "bm":false, // if true, the buyer is the market maker, we only use this field to "define the side" of a public trade + // "seqnum":180143985289898554 + // } + // + const timestamp = this.safeInteger (trade, 'ts'); + const priceString = this.safeString2 (trade, 'price', 'p'); + const amountString = this.safeString (trade, 'q'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const buyerIsMaker = this.safeValue (trade, 'bm', false); + const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; + const side = buyerIsMaker ? 'buy' : 'sell'; + let symbol = undefined; + if ((symbol === undefined) && (market !== undefined)) { + symbol = market['symbol']; + } + return { + 'info': trade, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'symbol': symbol, + 'id': undefined, + 'order': undefined, + 'type': undefined, + 'takerOrMaker': makerOrTaker, + 'side': side, + 'price': price, + 'amount': amount, + 'cost': cost, + 'fee': undefined, + }; + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'symbol': market['id'], + }; + if (limit !== undefined) { + request['n'] = limit; // max 100 + } + const response = await this.publicGetTrades (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "m":"trades", + // "symbol":"BTC-PERP", + // "data":[ + // {"p":"9128.5","q":"0.0030","ts":1590229002385,"bm":false,"seqnum":180143985289898554}, + // {"p":"9129","q":"0.0030","ts":1590229002642,"bm":false,"seqnum":180143985289898587}, + // {"p":"9129.5","q":"0.0030","ts":1590229021306,"bm":false,"seqnum":180143985289899043} + // ] + // } + // } + // + const records = this.safeValue (response, 'data', []); + const trades = this.safeValue (records, 'data', []); + return this.parseTrades (trades, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'PendingNew': 'open', + 'New': 'open', + 'PartiallyFilled': 'open', + 'Filled': 'closed', + 'Canceled': 'canceled', + 'Rejected': 'rejected', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + // + // createOrder + // + // { + // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", + // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", + // "orderType": "Market", + // "symbol": "BTC/USDT", + // "timestamp": 1573576916201 + // } + // + // fetchOrder, fetchOpenOrders, fetchClosedOrders + // + // { + // "symbol": "BTC/USDT", + // "price": "8131.22", + // "orderQty": "0.00082", + // "orderType": "Market", + // "avgPx": "7392.02", + // "cumFee": "0.005152238", + // "cumFilledQty": "0.00082", + // "errorCode": "", + // "feeAsset": "USDT", + // "lastExecTime": 1575953151764, + // "orderId": "a16eee20b6750866943712zWEDdAjt3", + // "seqNum": 2623469, + // "side": "Buy", + // "status": "Filled", + // "stopPrice": "", + // "execInst": "NULL_VAL" + // } + // + // { + // "ac": "FUTURES", + // "accountId": "testabcdefg", + // "avgPx": "0", + // "cumFee": "0", + // "cumQty": "0", + // "errorCode": "NULL_VAL", + // "execInst": "NULL_VAL", + // "feeAsset": "USDT", + // "lastExecTime": 1584072844085, + // "orderId": "r170d21956dd5450276356bbtcpKa74", + // "orderQty": "1.1499", + // "orderType": "Limit", + // "price": "4000", + // "sendingTime": 1584072841033, + // "seqNum": 24105338, + // "side": "Buy", + // "status": "Canceled", + // "stopPrice": "", + // "symbol": "BTC-PERP" + // }, + // + const status = this.parseOrderStatus (this.safeString (order, 'status')); + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '/'); + const timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); + const lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const average = this.safeNumber (order, 'avgPx'); + const filled = this.safeNumber2 (order, 'cumFilledQty', 'cumQty'); + const id = this.safeString (order, 'orderId'); + let clientOrderId = this.safeString (order, 'id'); + if (clientOrderId !== undefined) { + if (clientOrderId.length < 1) { + clientOrderId = undefined; + } + } + const type = this.safeStringLower (order, 'orderType'); + const side = this.safeStringLower (order, 'side'); + const feeCost = this.safeNumber (order, 'cumFee'); + let fee = undefined; + if (feeCost !== undefined) { + const feeCurrencyId = this.safeString (order, 'feeAsset'); + const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); + fee = { + 'cost': feeCost, + 'currency': feeCurrencyCode, + }; + } + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ + 'info': order, + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': lastTradeTimestamp, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': price, + 'stopPrice': stopPrice, + 'amount': amount, + 'cost': undefined, + 'average': average, + 'filled': filled, + 'remaining': undefined, + 'status': status, + 'fee': fee, + 'trades': undefined, + }); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const market = this.market (symbol); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'createOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'symbol': market['id'], + 'time': this.milliseconds (), + 'orderQty': this.amountToPrecision (symbol, amount), + 'orderType': type, // "limit", "market", "stop_market", "stop_limit" + 'side': side, // "buy" or "sell" + // 'orderPrice': this.priceToPrecision (symbol, price), + // 'stopPrice': this.priceToPrecision (symbol, stopPrice), // required for stop orders + // 'postOnly': 'false', // 'false', 'true' + // 'timeInForce': 'GTC', // GTC, IOC, FOK + // 'respInst': 'ACK', // ACK, 'ACCEPT, DONE + }; + if (clientOrderId !== undefined) { + request['id'] = clientOrderId; + params = this.omit (params, [ 'clientOrderId', 'id' ]); + } + if ((type === 'limit') || (type === 'stop_limit')) { + request['orderPrice'] = this.priceToPrecision (symbol, price); + } + if ((type === 'stop_limit') || (type === 'stop_market')) { + const stopPrice = this.safeNumber (params, 'stopPrice'); + if (stopPrice === undefined) { + throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); + } else { + request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); + params = this.omit (params, 'stopPrice'); + } + } + const response = await this.accountCategoryPostOrder (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "ac": "MARGIN", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "action": "place-order", + // "info": { + // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", + // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", + // "orderType": "Market", + // "symbol": "BTC/USDT", + // "timestamp": 1573576916201 + // }, + // "status": "Ack" + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const info = this.safeValue (data, 'info', {}); + return this.parseOrder (info, market); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'orderId': id, + }; + const response = await this.accountCategoryGetOrderStatus (this.extend (request, params)); + // + // { + // "code": 0, + // "accountCategory": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "data": [ + // { + // "symbol": "BTC/USDT", + // "price": "8131.22", + // "orderQty": "0.00082", + // "orderType": "Market", + // "avgPx": "7392.02", + // "cumFee": "0.005152238", + // "cumFilledQty": "0.00082", + // "errorCode": "", + // "feeAsset": "USDT", + // "lastExecTime": 1575953151764, + // "orderId": "a16eee20b6750866943712zWEDdAjt3", + // "seqNum": 2623469, + // "side": "Buy", + // "status": "Filled", + // "stopPrice": "", + // "execInst": "NULL_VAL" + // } + // ] + // } + // + const data = this.safeValue (response, 'data', {}); + return this.parseOrder (data); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + } + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'fetchOpenOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + }; + const response = await this.accountCategoryGetOrderOpen (this.extend (request, params)); + // + // { + // "ac": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "code": 0, + // "data": [ + // { + // "avgPx": "0", // Average filled price of the order + // "cumFee": "0", // cumulative fee paid for this order + // "cumFilledQty": "0", // cumulative filled quantity + // "errorCode": "", // error code; could be empty + // "feeAsset": "USDT", // fee asset + // "lastExecTime": 1576019723550, // The last execution time of the order + // "orderId": "s16ef21882ea0866943712034f36d83", // server provided orderId + // "orderQty": "0.0083", // order quantity + // "orderType": "Limit", // order type + // "price": "7105", // order price + // "seqNum": 8193258, // sequence number + // "side": "Buy", // order side + // "status": "New", // order status on matching engine + // "stopPrice": "", // only available for stop market and stop limit orders; otherwise empty + // "symbol": "BTC/USDT", + // "execInst": "NULL_VAL" // execution instruction + // }, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + if (accountCategory === 'futures') { + return this.parseOrders (data, market, since, limit); + } + // a workaround for https://github.com/ccxt/ccxt/issues/7187 + const orders = []; + for (let i = 0; i < data.length; i++) { + const order = this.parseOrder (data[i], market); + orders.push (order); + } + return this.filterBySymbolSinceLimit (orders, symbol, since, limit); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + } + const defaultAccountCategory = this.safeString (this.options, 'account-category'); + const options = this.safeValue (this.options, 'fetchClosedOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + // 'category': accountCategory, + // 'symbol': market['id'], + // 'orderType': 'market', // optional, string + // 'side': 'buy', // or 'sell', optional, case insensitive. + // 'status': 'Filled', // "Filled", "Canceled", or "Rejected" + // 'startTime': exchange.milliseconds (), + // 'endTime': exchange.milliseconds (), + // 'page': 1, + // 'pageSize': 100, + }; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const method = this.safeValue (options, 'method', 'accountGroupGetOrderHist'); + if (method === 'accountGroupGetOrderHist') { + if (accountCategory !== undefined) { + request['category'] = accountCategory; + } + } else { + request['account-category'] = accountCategory; + } + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['pageSize'] = limit; + } + const response = await this[method] (this.extend (request, params)); + // + // accountCategoryGetOrderHistCurrent + // + // { + // "code":0, + // "accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda", + // "ac":"CASH", + // "data":[ + // { + // "seqNum":15561826728, + // "orderId":"a17294d305c0U6491137460bethu7kw9", + // "symbol":"ETH/USDT", + // "orderType":"Limit", + // "lastExecTime":1591635618200, + // "price":"200", + // "orderQty":"0.1", + // "side":"Buy", + // "status":"Canceled", + // "avgPx":"0", + // "cumFilledQty":"0", + // "stopPrice":"", + // "errorCode":"", + // "cumFee":"0", + // "feeAsset":"USDT", + // "execInst":"NULL_VAL" + // } + // ] + // } + // + // accountGroupGetOrderHist + // + // { + // "code": 0, + // "data": { + // "data": [ + // { + // "ac": "FUTURES", + // "accountId": "testabcdefg", + // "avgPx": "0", + // "cumFee": "0", + // "cumQty": "0", + // "errorCode": "NULL_VAL", + // "execInst": "NULL_VAL", + // "feeAsset": "USDT", + // "lastExecTime": 1584072844085, + // "orderId": "r170d21956dd5450276356bbtcpKa74", + // "orderQty": "1.1499", + // "orderType": "Limit", + // "price": "4000", + // "sendingTime": 1584072841033, + // "seqNum": 24105338, + // "side": "Buy", + // "status": "Canceled", + // "stopPrice": "", + // "symbol": "BTC-PERP" + // }, + // ], + // "hasNext": False, + // "limit": 500, + // "page": 1, + // "pageSize": 20 + // } + // } + // + let data = this.safeValue (response, 'data'); + const isArray = Array.isArray (data); + if (!isArray) { + data = this.safeValue (data, 'data', []); + } + return this.parseOrders (data, market, since, limit); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument'); + } + await this.loadMarkets (); + await this.loadAccounts (); + const market = this.market (symbol); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'cancelOrder', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'symbol': market['id'], + 'time': this.milliseconds (), + 'id': 'foobar', + }; + if (clientOrderId === undefined) { + request['orderId'] = id; + } else { + request['id'] = clientOrderId; + params = this.omit (params, [ 'clientOrderId', 'id' ]); + } + const response = await this.accountCategoryDeleteOrder (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "ac": "CASH", + // "action": "cancel-order", + // "status": "Ack", + // "info": { + // "id": "wv8QGquoeamhssvQBeHOHGQCGlcBjj23", + // "orderId": "16e6198afb4s8bXHbAwwoqDo2ebc19dc", + // "orderType": "", // could be empty + // "symbol": "ETH/USDT", + // "timestamp": 1573594877822 + // } + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const info = this.safeValue (data, 'info', {}); + return this.parseOrder (info, market); + } + + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + await this.loadAccounts (); + const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); + const options = this.safeValue (this.options, 'cancelAllOrders', {}); + let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); + accountCategory = this.safeString (params, 'account-category', accountCategory); + params = this.omit (params, 'account-category'); + const account = this.safeValue (this.accounts, 0, {}); + const accountGroup = this.safeValue (account, 'id'); + const request = { + 'account-group': accountGroup, + 'account-category': accountCategory, + 'time': this.milliseconds (), + }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.accountCategoryDeleteOrderAll (this.extend (request, params)); + // + // { + // "code": 0, + // "data": { + // "ac": "CASH", + // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", + // "action": "cancel-all", + // "info": { + // "id": "2bmYvi7lyTrneMzpcJcf2D7Pe9V1P9wy", + // "orderId": "", + // "orderType": "NULL_VAL", + // "symbol": "", + // "timestamp": 1574118495462 + // }, + // "status": "Ack" + // } + // } + // + return response; + } + + parseDepositAddress (depositAddress, currency = undefined) { + // + // { + // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // destTag: "", + // tagType: "", + // tagId: "", + // chainName: "ERC20", + // numConfirmations: 20, + // withdrawalFee: 1, + // nativeScale: 4, + // tips: [] + // } + // + const address = this.safeString (depositAddress, 'address'); + const tagId = this.safeString (depositAddress, 'tagId'); + const tag = this.safeString (depositAddress, tagId); + this.checkAddress (address); + const code = (currency === undefined) ? undefined : currency['code']; + return { + 'currency': code, + 'address': address, + 'tag': tag, + 'info': depositAddress, + }; + } + + async fetchDepositAddress (code, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const chainName = this.safeString (params, 'chainName'); + params = this.omit (params, 'chainName'); + const request = { + 'asset': currency['id'], + }; + const response = await this.privateGetWalletDepositAddress (this.extend (request, params)); + // + // { + // "code":0, + // "data":{ + // "asset":"USDT", + // "assetName":"Tether", + // "address":[ + // { + // "address":"1N22odLHXnLPCjC8kwBJPTayarr9RtPod6", + // "destTag":"", + // "tagType":"", + // "tagId":"", + // "chainName":"Omni", + // "numConfirmations":3, + // "withdrawalFee":4.7, + // "nativeScale":4, + // "tips":[] + // }, + // { + // "address":"0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // "destTag":"", + // "tagType":"", + // "tagId":"", + // "chainName":"ERC20", + // "numConfirmations":20, + // "withdrawalFee":1.0, + // "nativeScale":4, + // "tips":[] + // } + // ] + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const addresses = this.safeValue (data, 'address', []); + const numAddresses = addresses.length; + let address = undefined; + if (numAddresses > 1) { + const addressesByChainName = this.indexBy (addresses, 'chainName'); + if (chainName === undefined) { + const chainNames = Object.keys (addressesByChainName); + const chains = chainNames.join (', '); + throw new ArgumentsRequired (this.id + ' fetchDepositAddress returned more than one address, a chainName parameter is required, one of ' + chains); + } + address = this.safeValue (addressesByChainName, chainName, {}); + } else { + // first address + address = this.safeValue (addresses, 0, {}); + } + const result = this.parseDepositAddress (address, currency); + return this.extend (result, { + 'info': response, + }); + } + + async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'txType': 'deposit', + }; + return await this.fetchTransactions (code, since, limit, this.extend (request, params)); + } + + async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'txType': 'withdrawal', + }; + return await this.fetchTransactions (code, since, limit, this.extend (request, params)); + } + + async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'asset': currency['id'], + // 'page': 1, + // 'pageSize': 20, + // 'startTs': this.milliseconds (), + // 'endTs': this.milliseconds (), + // 'txType': undefned, // deposit, withdrawal + }; + let currency = undefined; + if (code !== undefined) { + currency = this.currency (code); + request['asset'] = currency['id']; + } + if (since !== undefined) { + request['startTs'] = since; + } + if (limit !== undefined) { + request['pageSize'] = limit; + } + const response = await this.privateGetWalletTransactions (this.extend (request, params)); + // + // { + // code: 0, + // data: { + // data: [ + // { + // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", + // time: 1591606166000, + // asset: "USDT", + // transactionType: "deposit", + // amount: "25", + // commission: "0", + // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", + // status: "pending", + // numConfirmed: 8, + // numConfirmations: 20, + // destAddress: { address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722" } + // } + // ], + // page: 1, + // pageSize: 20, + // hasNext: false + // } + // } + // + const data = this.safeValue (response, 'data', {}); + const transactions = this.safeValue (data, 'data', []); + return this.parseTransactions (transactions, currency, since, limit); + } + + parseTransactionStatus (status) { + const statuses = { + 'reviewing': 'pending', + 'pending': 'pending', + 'confirmed': 'ok', + 'rejected': 'rejected', + }; + return this.safeString (statuses, status, status); + } + + parseTransaction (transaction, currency = undefined) { + // + // { + // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", + // time: 1591606166000, + // asset: "USDT", + // transactionType: "deposit", + // amount: "25", + // commission: "0", + // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", + // status: "pending", + // numConfirmed: 8, + // numConfirmations: 20, + // destAddress: { + // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", + // destTag: "..." // for currencies that have it + // } + // } + // + const id = this.safeString (transaction, 'requestId'); + const amount = this.safeNumber (transaction, 'amount'); + const destAddress = this.safeValue (transaction, 'destAddress', {}); + const address = this.safeString (destAddress, 'address'); + const tag = this.safeString (destAddress, 'destTag'); + const txid = this.safeString (transaction, 'networkTransactionId'); + const type = this.safeString (transaction, 'transactionType'); + const timestamp = this.safeInteger (transaction, 'time'); + const currencyId = this.safeString (transaction, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); + const feeCost = this.safeNumber (transaction, 'commission'); + return { + 'info': transaction, + 'id': id, + 'currency': code, + 'amount': amount, + 'address': address, + 'addressTo': address, + 'addressFrom': undefined, + 'tag': tag, + 'tagTo': tag, + 'tagFrom': undefined, + 'status': status, + 'type': type, + 'updated': undefined, + 'txid': txid, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'fee': { + 'currency': code, + 'cost': feeCost, + }, + }; + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let url = ''; + let query = params; + const accountCategory = (api === 'accountCategory'); + if (accountCategory || (api === 'accountGroup')) { + url += this.implodeParams ('/{account-group}', params); + query = this.omit (params, 'account-group'); + } + const request = this.implodeParams (path, query); + url += '/api/pro/' + this.version; + if (accountCategory) { + url += this.implodeParams ('/{account-category}', query); + query = this.omit (query, 'account-category'); + } + url += '/' + request; + query = this.omit (query, this.extractParams (path)); + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const timestamp = this.milliseconds ().toString (); + const payload = timestamp + '+' + request; + const hmac = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); + headers = { + 'x-auth-key': this.apiKey, + 'x-auth-timestamp': timestamp, + 'x-auth-signature': hmac, + }; + if (method === 'GET') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + headers['Content-Type'] = 'application/json'; + body = this.json (query); + } + } + url = this.urls['api'] + url; + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; // fallback to default error handler + } + // + // {'code': 6010, 'message': 'Not enough balance.'} + // {'code': 60060, 'message': 'The order is already filled or canceled.'} + // {"code":2100,"message":"ApiKeyFailure"} + // {"code":300001,"message":"Price is too low from market price.","reason":"INVALID_PRICE","accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda","ac":"CASH","action":"place-order","status":"Err","info":{"symbol":"BTC/USDT"}} + // + const code = this.safeString (response, 'code'); + const message = this.safeString (response, 'message'); + const error = (code !== undefined) && (code !== '0'); + if (error || (message !== undefined)) { + const feedback = this.id + ' ' + body; + this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); + this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); + this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); + throw new ExchangeError (feedback); // unknown message + } + } +}; + +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],6:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -3608,6 +4837,7 @@ const { // eslint-disable-line object-curly-newline const { TRUNCATE, ROUND, DECIMAL_PLACES, NO_PADDING } = functions.precisionConstants const BN = require ('../static_dependencies/BN/bn') +const Precise = require ('./Precise') // ---------------------------------------------------------------------------- @@ -3788,6 +5018,11 @@ module.exports = class Exchange { this.minFundingAddressLength = 1 // used in checkAddress this.substituteCommonCurrencyCodes = true // reserved + this.quoteJsonNumbers = true // treat numbers in json as quoted precise strings + this.number = Number // or String (a pointer to a function) + + // whether fees should be summed by currency code + this.reduceFees = true // do not delete this line, it is needed for users to be able to define their own fetchImplementation this.fetchImplementation = defaultFetch @@ -4083,7 +5318,7 @@ module.exports = class Exchange { parseJson (jsonString) { try { if (this.isJsonEncodedObject (jsonString)) { - return JSON.parse (jsonString) + return JSON.parse (this.onJsonResponse (jsonString)) } } catch (e) { // SyntaxError @@ -4162,7 +5397,11 @@ module.exports = class Exchange { } onRestResponse (statusCode, statusText, url, method, responseHeaders, responseBody, requestHeaders, requestBody) { - return responseBody.trim ().replace (/:(\d{15,}),/g, ':"$1",'); + return responseBody.trim () + } + + onJsonResponse (responseBody) { + return this.quoteJsonNumbers ? responseBody.replace (/":([+.0-9eE-]+),/g, '":"$1",') : responseBody; } setMarkets (markets, currencies = undefined) { @@ -4482,8 +5721,8 @@ module.exports = class Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = parseFloat (bidask[priceKey]) - const amount = parseFloat (bidask[amountKey]) + const price = this.safeNumber (bidask, priceKey) + const amount = this.safeNumber (bidask, amountKey) return [ price, amount ] } @@ -4509,7 +5748,7 @@ module.exports = class Exchange { } } - parseBalance (balance) { + parseBalance (balance, legacy = true) { const codes = Object.keys (this.omit (balance, [ 'info', 'free', 'used', 'total' ])); @@ -4521,20 +5760,34 @@ module.exports = class Exchange { const code = codes[i] if (balance[code].total === undefined) { if (balance[code].free !== undefined && balance[code].used !== undefined) { - balance[code].total = this.sum (balance[code].free, balance[code].used) + if (legacy) { + balance[code].total = this.sum (balance[code].free, balance[code].used) + } else { + balance[code].total = Precise.stringAdd (balance[code].free, balance[code].used) + } } } if (balance[code].free === undefined) { if (balance[code].total !== undefined && balance[code].used !== undefined) { - balance[code].free = this.sum (balance[code].total, -balance[code].used) + if (legacy) { + balance[code].free = this.sum (balance[code].total, -balance[code].used) + } else { + balance[code].free = Precise.stringSub (balance[code].total, balance[code].used) + } } } if (balance[code].used === undefined) { if (balance[code].total !== undefined && balance[code].free !== undefined) { - balance[code].used = this.sum (balance[code].total, -balance[code].free) + if (legacy) { + balance[code].used = this.sum (balance[code].total, -balance[code].free) + } else { + balance[code].used = Precise.stringSub (balance[code].total, balance[code].free) + } } } - + balance[code].free = this.parseNumber (balance[code].free) + balance[code].used = this.parseNumber (balance[code].used) + balance[code].total = this.parseNumber (balance[code].total) balance.free[code] = balance[code].free balance.used[code] = balance[code].used balance.total[code] = balance[code].total @@ -4543,6 +5796,10 @@ module.exports = class Exchange { return balance } + async fetchBalance (params = {}) { + throw new NotSupported (this.id + ' fetchBalance not supported yet') + } + async fetchPartialBalance (part, params = {}) { const balance = await this.fetchBalance (params) return balance[part] @@ -4652,11 +5909,27 @@ module.exports = class Exchange { return indexed ? indexBy (result, key) : result } + parseTickers (tickers, symbols = undefined) { + const result = []; + for (let i = 0; i < tickers.length; i++) { + result.push (this.parseTicker (tickers[i])); + } + return this.filterByArray (result, 'symbol', symbols); + } + + parseDepositAddresses (addresses, codes = undefined) { + let result = []; + for (let i = 0; i < addresses.length; i++) { + const address = this.parseDepositAddress (addresses[i]); + result.push (address); + } + if (codes) { + result = this.filterByArray (result, 'currency', codes); + } + return this.indexBy (result, 'currency'); + } + parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (trades)) { - // throw new ExchangeError (this.id + ' parseTrades expected an array in the trades argument, but got ' + typeof trades); - // } let result = Object.values (trades || []).map ((trade) => this.extend (this.parseTrade (trade, market), params)) result = sortBy (result, 'timestamp') const symbol = (market !== undefined) ? market['symbol'] : undefined @@ -4665,10 +5938,6 @@ module.exports = class Exchange { } parseTransactions (transactions, currency = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (transactions)) { - // throw new ExchangeError (this.id + ' parseTransactions expected an array in the transactions argument, but got ' + typeof transactions); - // } let result = Object.values (transactions || []).map ((transaction) => this.extend (this.parseTransaction (transaction, currency), params)) result = this.sortBy (result, 'timestamp'); const code = (currency !== undefined) ? currency['code'] : undefined; @@ -4676,6 +5945,14 @@ module.exports = class Exchange { return this.filterByCurrencySinceLimit (result, code, since, limit, tail); } + parseTransfers (transfers, currency = undefined, since = undefined, limit = undefined, params = {}) { + let result = Object.values (transfers || []).map ((transfer) => this.extend (this.parseTransfer (transfer, currency), params)) + result = this.sortBy (result, 'timestamp'); + const code = (currency !== undefined) ? currency['code'] : undefined; + const tail = since === undefined; + return this.filterByCurrencySinceLimit (result, code, since, limit, tail); + } + parseLedger (data, currency = undefined, since = undefined, limit = undefined, params = {}) { let result = []; const array = Object.values (data || []); @@ -4820,19 +6097,19 @@ module.exports = class Exchange { return this.createOrder (symbol, ...args) } - createLimitOrder (symbol, side, amount, price = undefined, params = {}) { + createLimitOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'limit', side, amount, price, params) } - createMarketOrder (symbol, side, amount, price = undefined, params = {}) { + createMarketOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'market', side, amount, price, params) } - createLimitBuyOrder (symbol, amount, price = undefined, params = {}) { + createLimitBuyOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'buy', amount, price, params) } - createLimitSellOrder (symbol, amount, price = undefined, params = {}) { + createLimitSellOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'sell', amount, price, params) } @@ -4865,15 +6142,43 @@ module.exports = class Exchange { } calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol] - const rate = market[takerOrMaker] - const cost = parseFloat (this.costToPrecision (symbol, amount * price)) + const market = this.markets[symbol]; + const feeSide = this.safeString (market, 'feeSide', 'quote'); + let key = 'quote'; + let cost = undefined; + if (feeSide === 'quote') { + // the fee is always in quote currency + cost = amount * price; + } else if (feeSide === 'base') { + // the fee is always in base currency + cost = amount; + } else if (feeSide === 'get') { + // the fee is always in the currency you get + cost = amount; + if (side === 'sell') { + cost *= price; + } else { + key = 'base'; + } + } else if (feeSide === 'give') { + // the fee is always in the currency you give + cost = amount; + if (side === 'buy') { + cost *= price; + } else { + key = 'base'; + } + } + const rate = market[takerOrMaker]; + if (cost !== undefined) { + cost *= rate; + } return { 'type': takerOrMaker, - 'currency': market['quote'], + 'currency': market[key], 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, rate * cost)), - } + 'cost': cost, + }; } checkRequiredDependencies () { @@ -4957,6 +6262,25 @@ module.exports = class Exchange { return new BN (a).pow (new BN (b)) } + reduceFeesByCurrency (fees) { + const reduced = {}; + for (let i = 0; i < fees.length; i++) { + const fee = fees[i]; + const feeCurrencyCode = this.safeValue (fee, 'currency'); + if (feeCurrencyCode !== undefined) { + if (feeCurrencyCode in reduced) { + reduced[feeCurrencyCode]['cost'] = this.sum (reduced[feeCurrencyCode]['cost'], fee['cost']); + } else { + reduced[feeCurrencyCode] = { + 'cost': fee['cost'], + 'currency': feeCurrencyCode, + }; + } + } + } + return Object.values (reduced); + } + safeOrder (order) { // Cost // Remaining @@ -4965,70 +6289,295 @@ module.exports = class Exchange { // Amount // Filled // - // First we try to calculate filled from the trades - const parseFilled = order['filled'] === undefined; - const parseCost = order['cost'] === undefined; - if (parseFilled) { - order['filled'] = 0 - } - if (parseCost) { - order['cost'] = 0 - } - if (parseFilled || parseCost) { - if (Array.isArray (order['trades'])) { - for (let i = 0; i < order['trades'].length; i++) { - const trade = order['trades'][i] - if (parseFilled) { - order['filled'] = this.sum (order['filled'], trade['amount']) + // first we try to calculate the order fields from the trades + let amount = this.safeValue (order, 'amount'); + let remaining = this.safeValue (order, 'remaining'); + let filled = this.safeValue (order, 'filled'); + let cost = this.safeValue (order, 'cost'); + let average = this.safeValue (order, 'average'); + let price = this.safeValue (order, 'price'); + let lastTradeTimeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); + const parseFilled = (filled === undefined); + const parseCost = (cost === undefined); + const parseLastTradeTimeTimestamp = (lastTradeTimeTimestamp === undefined); + const parseFee = this.safeValue (order, 'fee') === undefined; + const parseFees = this.safeValue (order, 'fees') === undefined; + const shouldParseFees = parseFee || parseFees; + const fees = shouldParseFees ? [] : undefined; + if (parseFilled || parseCost || shouldParseFees) { + const trades = this.safeValue (order, 'trades'); + if (trades !== undefined) { + if (parseFilled) { + filled = 0; + } + if (parseCost) { + cost = 0; + } + for (let i = 0; i < trades.length; i++) { + const trade = trades[i]; + const tradeAmount = this.safeValue (trade, 'amount'); + if (parseFilled && (tradeAmount !== undefined)) { + filled = this.sum (filled, tradeAmount); } - if (parseCost) { - order['cost'] = this.sum (order['cost'], trade['cost']) + const tradeCost = this.safeValue (trade, 'cost'); + if (parseCost && (tradeCost !== undefined)) { + cost = this.sum (cost, tradeCost); + } + const tradeTimestamp = this.safeValue (trade, 'timestamp'); + if (parseLastTradeTimeTimestamp && (tradeTimestamp !== undefined)) { + if (lastTradeTimeTimestamp === undefined) { + lastTradeTimeTimestamp = tradeTimestamp; + } else { + lastTradeTimeTimestamp = Math.max (lastTradeTimeTimestamp, tradeTimestamp); + } + } + if (shouldParseFees) { + const tradeFees = this.safeValue (trade, 'fees'); + if (tradeFees !== undefined) { + for (let j = 0; j < tradeFees.length; j++) { + const tradeFee = tradeFees[j]; + fees.push (this.extend ({}, tradeFee)); + } + } else { + const tradeFee = this.safeValue (trade, 'fee'); + if (tradeFee !== undefined) { + fees.push (this.extend ({}, tradeFee)); + } + } } } } } - // We ensure amount = filled + remaining - if (order['amount'] === undefined) { - if (order['filled'] !== undefined && order['remaining'] !== undefined) { - order['amount'] = this.sum (order['filled'], order['remaining']) + if (shouldParseFees) { + const reducedFees = this.reduceFees ? this.reduceFeesByCurrency (fees) : fees; + const reducedLength = reducedFees.length; + if (!parseFee && (reducedLength === 0)) { + reducedFees.push (order['fee']); + } + if (parseFees) { + order['fees'] = reducedFees; + } + if (parseFee && (reducedLength === 1)) { + order['fee'] = reducedFees[0]; } } - if (order['filled'] === undefined) { - if (order['amount'] !== undefined && order['remaining'] !== undefined) { - order['filled'] = Math.max (this.sum (order['amount'], -order['remaining']), 0) + if (amount === undefined) { + // ensure amount = filled + remaining + if (filled !== undefined && remaining !== undefined) { + amount = this.sum (filled, remaining); + } else if (this.safeString (order, 'status') === 'closed') { + amount = filled; } } - if (order['remaining'] === undefined) { - if (order['amount'] !== undefined && order['filled'] !== undefined) { - order['remaining'] = Math.max (this.sum (order['amount'], -order['filled']), 0) + if (filled === undefined) { + if (amount !== undefined && remaining !== undefined) { + filled = Math.max (this.sum (amount, -remaining), 0); } } - // We ensure that the average field is calculated correctly - if (order['average'] === undefined) { - if (order['filled'] !== undefined && order['cost'] !== undefined && order['cost'] > 0) { - order['average'] = order['filled'] / order['cost'] + if (remaining === undefined) { + if (amount !== undefined && filled !== undefined) { + remaining = Math.max (this.sum (amount, -filled), 0); } } - // We also ensure the cost field is calculated correctly - const costPriceExists = (order['average'] !== undefined) || (order['price'] !== undefined) - if ((order['filled'] !== undefined) && costPriceExists) { - let costPrice = undefined; - if (order['average'] === undefined) { - costPrice = order['price'] - } else { - costPrice = order['average'] + // ensure that the average field is calculated correctly + if (average === undefined) { + if ((filled !== undefined) && (cost !== undefined) && (cost > 0)) { + average = cost / filled; } - order['cost'] = costPrice * order['filled'] } - // We add support for market orders - if (order['price'] === undefined && order['type'] === 'market') { - order['price'] = order['average'] + // also ensure the cost field is calculated correctly + const costPriceExists = (average !== undefined) || (price !== undefined); + if (parseCost && (filled !== undefined) && costPriceExists) { + cost = (average === undefined) ? (price * filled) : (average * filled); } - return order + // support for market orders + const orderType = this.safeValue (order, 'type'); + const emptyPrice = (price === undefined) || (price === 0.0); + if (emptyPrice && (orderType === 'market')) { + price = average; + } + return this.extend (order, { + 'lastTradeTimestamp': lastTradeTimeTimestamp, + 'price': price, + 'amount': amount, + 'cost': cost, + 'average': average, + 'filled': filled, + 'remaining': remaining, + }); + } + + parseNumber (value, d = undefined) { + if (value === undefined) { + return d + } else { + try { + return this.number (value) + } catch (e) { + return d + } + } + } + + safeNumber (object, key, d = undefined) { + const value = this.safeString (object, key) + return this.parseNumber (value, d) + } + + safeNumber2 (object, key1, key2, d = undefined) { + const value = this.safeString2 (object, key1, key2) + return this.parseNumber (value, d) } } -},{"../static_dependencies/BN/bn":126,"./errors":8,"./functions":9}],7:[function(require,module,exports){ +},{"../static_dependencies/BN/bn":123,"./Precise":7,"./errors":9,"./functions":10}],7:[function(require,module,exports){ +'use strict' + +const BN = require ('../static_dependencies/BN/bn') + +class Precise { + constructor (number, decimals = 0) { + const isBN = number instanceof BN + const isString = typeof number === 'string' + if (!(isBN || isString)) { + throw new Error ('Precise initiated with something other than a string or BN') + } + if (isBN) { + this.integer = number + this.decimals = decimals + } else { + if (decimals) { + throw new Error ('Cannot set decimals when initializing with a string') + } + let modifier = 0 + number = number.toLowerCase () + if (number.indexOf ('e') > -1) { + [ number, modifier ] = number.split ('e') + modifier = parseInt (modifier) + } + const decimalIndex = number.indexOf ('.') + this.decimals = (decimalIndex > -1) ? number.length - decimalIndex - 1 : 0 + const integerString = number.replace ('.', '') + this.integer = new BN (integerString) + this.decimals = this.decimals - modifier + } + this.base = 10 + this.reduce () + } + + mul (other) { + // other must be another instance of Precise + const integerResult = this.integer.mul (other.integer) + return new Precise (integerResult, this.decimals + other.decimals) + } + + div (other, precision = 18) { + const distance = precision - this.decimals + other.decimals + let numerator + if (distance === 0) { + numerator = this.integer + } else if (distance < 0) { + const exponent = new BN (this.base).pow (new BN (-distance)) + numerator = this.integer.div (exponent) + } else { + const exponent = new BN (this.base).pow (new BN (distance)) + numerator = this.integer.mul (exponent) + } + const result = numerator.div (other.integer) + return new Precise (result, precision) + } + + add (other) { + if (this.decimals === other.decimals) { + const integerResult = this.integer.add (other.integer) + return new Precise (integerResult, this.decimals) + } else { + const [ smaller, bigger ] = + (this.decimals > other.decimals) ? [ other, this ] : [ this, other ] + const exponent = new BN (bigger.decimals - smaller.decimals) + const normalised = smaller.integer.mul (new BN (this.base).pow (exponent)) + const result = normalised.add (bigger.integer) + return new Precise (result, bigger.decimals) + } + } + + sub (other) { + const negative = new Precise (other.integer.neg (), other.decimals) + return this.add (negative) + } + + reduce () { + const zero = new BN (0) + if (this.integer.eq (zero)) { + this.decimals = 0 + return this + } + const base = new BN (this.base) + let divmod = this.integer.divmod (base) + while (divmod.mod.eq (zero)) { + this.integer = divmod.div + this.decimals-- + divmod = this.integer.divmod (base) + } + return this + } + + toString () { + const sign = this.integer.negative ? '-' : '' + const integerArray = Array.from (this.integer.abs ().toString (this.base).padStart (this.decimals, '0')) + const index = integerArray.length - this.decimals + let item + if (index === 0) { + // if we are adding to the front + item = '0.' + } else if (this.decimals < 0) { + item = '0'.repeat (-this.decimals) + } else if (this.decimals === 0) { + item = '' + } else { + item = '.' + } + integerArray.splice (index, 0, item) + return sign + integerArray.join ('') + } + + static stringMul (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).mul (new Precise (string2)).toString () + } + + static stringDiv (string1, string2, precision = 18) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).div (new Precise (string2), precision).toString () + } + + static stringAdd (string1, string2) { + if ((string1 === undefined) && (string2 === undefined)) { + return undefined + } + if (string1 === undefined) { + return string2 + } else if (string2 === undefined) { + return string1 + } + return (new Precise (string1)).add (new Precise (string2)).toString () + } + + static stringSub (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).sub (new Precise (string2)).toString () + } +} + +module.exports = Precise; + +},{"../static_dependencies/BN/bn":123}],8:[function(require,module,exports){ 'use strict'; const errorHierarchy = { @@ -5074,7 +6623,7 @@ const errorHierarchy = { module.exports = errorHierarchy; -},{}],8:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ 'use strict'; const errorHierarchy = require ('./errorHierarchy.js') @@ -5131,7 +6680,7 @@ module.exports = subclass ( errorHierarchy ) -},{"./errorHierarchy.js":7}],9:[function(require,module,exports){ +},{"./errorHierarchy.js":8}],10:[function(require,module,exports){ 'use strict'; /* ------------------------------------------------------------------------ */ @@ -5161,7 +6710,7 @@ module.exports = unCamelCasePropertyNames (Object.assign ({} /* ------------------------------------------------------------------------ */ -},{"./functions/crypto":10,"./functions/encode":11,"./functions/generic":12,"./functions/misc":13,"./functions/number":14,"./functions/platform":15,"./functions/string":16,"./functions/throttle":17,"./functions/time":18,"./functions/type":19}],10:[function(require,module,exports){ +},{"./functions/crypto":11,"./functions/encode":12,"./functions/generic":13,"./functions/misc":14,"./functions/number":15,"./functions/platform":16,"./functions/string":17,"./functions/throttle":18,"./functions/time":19,"./functions/type":20}],11:[function(require,module,exports){ 'use strict' /* ------------------------------------------------------------------------ */ @@ -5321,7 +6870,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"../../static_dependencies/BN/bn.js":126,"../../static_dependencies/crypto-js/crypto-js":127,"./../../static_dependencies/elliptic/lib/elliptic":128,"./../../static_dependencies/node-rsa/NodeRSA":146,"./../errors":8,"./encode":11,"./string":16}],11:[function(require,module,exports){ +},{"../../static_dependencies/BN/bn.js":123,"../../static_dependencies/crypto-js/crypto-js":124,"./../../static_dependencies/elliptic/lib/elliptic":125,"./../../static_dependencies/node-rsa/NodeRSA":143,"./../errors":9,"./encode":12,"./string":17}],12:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -5343,7 +6892,6 @@ let base58Encoder = null module.exports = { json: (data, params = undefined) => JSON.stringify (data) - , unjson: JSON.parse , isJsonEncodedObject: object => ( (typeof object === 'string') && @@ -5441,7 +6989,7 @@ module.exports['byteArrayToWordArray'] = byteArrayToWordArray /* ------------------------------------------------------------------------ */ -},{"../../static_dependencies/BN/bn":126,"../../static_dependencies/crypto-js/crypto-js":127,"../../static_dependencies/qs/index":162}],12:[function(require,module,exports){ +},{"../../static_dependencies/BN/bn":123,"../../static_dependencies/crypto-js/crypto-js":124,"../../static_dependencies/qs/index":159}],13:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -5679,7 +7227,7 @@ module.exports = { } -},{"./type":19}],13:[function(require,module,exports){ +},{"./type":20}],14:[function(require,module,exports){ 'use strict'; const { ROUND_UP, ROUND_DOWN } = require ('./number') @@ -5819,7 +7367,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"../errors":8,"./number":14}],14:[function(require,module,exports){ +},{"../errors":9,"./number":15}],15:[function(require,module,exports){ 'use strict' /* ------------------------------------------------------------------------ @@ -6160,7 +7708,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{}],15:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ (function (process){ "use strict"; @@ -6201,7 +7749,7 @@ module.exports = { defaultFetch, } }).call(this,require('_process')) -},{"../../static_dependencies/fetch-ponyfill/fetch-node":144,"_process":210}],16:[function(require,module,exports){ +},{"../../static_dependencies/fetch-ponyfill/fetch-node":141,"_process":206}],17:[function(require,module,exports){ "use strict"; // ---------------------------------------------------------------------------- @@ -6221,7 +7769,7 @@ module.exports = { , strip: s => s.replace(/^\s+|\s+$/g, '') } -},{}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -6287,7 +7835,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{"./time":18}],18:[function(require,module,exports){ +},{"./time":19}],19:[function(require,module,exports){ 'use strict'; /* ------------------------------------------------------------------------ */ @@ -6491,7 +8039,7 @@ module.exports = /* ------------------------------------------------------------------------ */ -},{}],19:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ @@ -6559,7 +8107,7 @@ module.exports = { /* ------------------------------------------------------------------------ */ -},{}],20:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -6593,13 +8141,14 @@ module.exports = class bequant extends hitbtc { } }; -},{"./hitbtc":93}],21:[function(require,module,exports){ +},{"./hitbtc":91}],22:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AccountSuspended, ArgumentsRequired, AuthenticationError, DDoSProtection, ExchangeNotAvailable, InvalidOrder, OrderNotFound, PermissionDenied, InsufficientFunds, BadSymbol, RateLimitExceeded, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -6825,9 +8374,9 @@ module.exports = class bibox extends Exchange { const quote = this.safeCurrencyCode (quoteId); symbol = base + '/' + quote; } - const last = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); - const baseVolume = this.safeFloat2 (ticker, 'vol', 'vol24H'); + const last = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); + const baseVolume = this.safeNumber2 (ticker, 'vol', 'vol24H'); let open = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; @@ -6841,11 +8390,11 @@ module.exports = class bibox extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -6856,7 +8405,7 @@ module.exports = class bibox extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': baseVolume, - 'quoteVolume': this.safeFloat (ticker, 'amount'), + 'quoteVolume': this.safeNumber (ticker, 'amount'), 'info': ticker, }; } @@ -6872,17 +8421,6 @@ module.exports = class bibox extends Exchange { return this.parseTicker (response['result'], market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - const ticker = this.parseTicker (rawTickers[i]); - if ((symbols === undefined) || (this.inArray (ticker['symbol'], symbols))) { - tickers.push (ticker); - } - } - return tickers; - } - async fetchTickers (symbols = undefined, params = {}) { const request = { 'cmd': 'marketAll', @@ -6915,7 +8453,7 @@ module.exports = class bibox extends Exchange { symbol = market['symbol']; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = this.safeString (trade, 'fee_symbol'); if (feeCurrency !== undefined) { if (feeCurrency in this.currencies_by_id) { @@ -6925,12 +8463,11 @@ module.exports = class bibox extends Exchange { } } const feeRate = undefined; // todo: deduce from market if market is defined - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if (feeCost !== undefined) { fee = { 'cost': -feeCost, @@ -6981,7 +8518,7 @@ module.exports = class bibox extends Exchange { request['size'] = limit; // default = 200 } const response = await this.publicGetMdata (this.extend (request, params)); - return this.parseOrderBook (response['result'], this.safeFloat (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); + return this.parseOrderBook (response['result'], this.safeNumber (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); } parseOHLCV (ohlcv, market = undefined) { @@ -6997,11 +8534,11 @@ module.exports = class bibox extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -7093,7 +8630,7 @@ module.exports = class bibox extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw_min'), + 'min': this.safeNumber (currency, 'withdraw_min'), 'max': undefined, }, }, @@ -7225,19 +8762,17 @@ module.exports = class bibox extends Exchange { code = this.currencies_by_id[code]['code']; } const account = this.account (); - let balance = indexed[id]; + const balance = indexed[id]; if (typeof balance === 'string') { - balance = parseFloat (balance); account['free'] = balance; - account['used'] = 0.0; account['total'] = balance; } else { - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -7328,8 +8863,8 @@ module.exports = class bibox extends Exchange { let tag = this.safeString (transaction, 'addr_remark'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'fee'); if (type === 'deposit') { feeCost = 0; tag = undefined; @@ -7437,26 +8972,19 @@ module.exports = class bibox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const type = (order['order_type'] === 1) ? 'market' : 'limit'; - const timestamp = order['createdAt']; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'deal_price'); - const filled = this.safeFloat (order, 'deal_amount'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat2 (order, 'deal_money', 'money'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - cost = price * filled; - } - } - const side = (order['order_side'] === 1) ? 'buy' : 'sell'; + const rawType = this.safeString (order, 'order_type'); + const type = (rawType === '1') ? 'market' : 'limit'; + const timestamp = this.safeInteger (order, 'createdAt'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'deal_price'); + const filled = this.safeNumber (order, 'deal_amount'); + const amount = this.safeNumber (order, 'amount'); + const cost = this.safeNumber2 (order, 'deal_money', 'money'); + const rawSide = this.safeString (order, 'order_side'); + const side = (rawSide === '1') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -7464,8 +8992,7 @@ module.exports = class bibox extends Exchange { 'currency': undefined, }; } - cost = cost ? cost : (parseFloat (price) * filled); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -7483,11 +9010,11 @@ module.exports = class bibox extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -7655,7 +9182,7 @@ module.exports = class bibox extends Exchange { }; const response = await this.privatePostTransfer (request); info[code] = response; - withdrawFees[code] = this.safeFloat (response['result'], 'withdraw_fee'); + withdrawFees[code] = this.safeNumber (response['result'], 'withdraw_fee'); } return { 'info': info, @@ -7725,13 +9252,14 @@ module.exports = class bibox extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],22:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],23:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, OrderNotFound, InsufficientFunds, PermissionDenied, BadRequest, RateLimitExceeded, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -7988,28 +9516,28 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (ticker, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = undefined; - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', {}); const ask = this.safeValue (ticker, 'ask', {}); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 'price'), - 'bidVolume': this.safeFloat (bid, 'quantity'), - 'ask': this.safeFloat (ask, 'price'), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 'price'), + 'bidVolume': this.safeNumber (bid, 'quantity'), + 'ask': this.safeNumber (ask, 'price'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'daily_change'), + 'change': this.safeNumber (ticker, 'daily_change'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -8174,16 +9702,13 @@ module.exports = class bigone extends Exchange { // } // const timestamp = this.parse8601 (this.safeString2 (trade, 'created_at', 'inserted_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } let side = this.safeString (trade, 'side'); const takerSide = this.safeString (trade, 'taker_side'); let takerOrMaker = undefined; @@ -8257,8 +9782,8 @@ module.exports = class bigone extends Exchange { takerCurrencyCode = market['quote']; } } - const makerFeeCost = this.safeFloat (trade, 'maker_fee'); - const takerFeeCost = this.safeFloat (trade, 'taker_fee'); + const makerFeeCost = this.safeNumber (trade, 'maker_fee'); + const takerFeeCost = this.safeNumber (trade, 'taker_fee'); if (makerFeeCost !== undefined) { if (takerFeeCost !== undefined) { result['fees'] = [ @@ -8321,11 +9846,11 @@ module.exports = class bigone extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -8396,11 +9921,11 @@ module.exports = class bigone extends Exchange { const symbol = this.safeString (balance, 'asset_symbol'); const code = this.safeCurrencyCode (symbol); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -8422,13 +9947,9 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (order, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (amount !== undefined && filled !== undefined) { - remaining = Math.max (0, amount - filled); - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); const status = this.parseOrderStatus (this.safeString (order, 'state')); let side = this.safeString (order, 'side'); if (side === 'BID') { @@ -8436,15 +9957,9 @@ module.exports = class bigone extends Exchange { } else { side = 'sell'; } - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'updated_at')); - const average = this.safeFloat (order, 'avg_deal_price'); - return { + const average = this.safeNumber (order, 'avg_deal_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -8459,14 +9974,14 @@ module.exports = class bigone extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -8490,7 +10005,7 @@ module.exports = class bigone extends Exchange { const isStopLimit = (uppercaseType === 'STOP_LIMIT'); const isStopMarket = (uppercaseType === 'STOP_MARKET'); if (isStopLimit || isStopMarket) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price parameter'); } @@ -8829,7 +10344,7 @@ module.exports = class bigone extends Exchange { const currencyId = this.safeString (transaction, 'asset_symbol'); const code = this.safeCurrencyCode (currencyId); const id = this.safeInteger (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const timestamp = this.parse8601 (this.safeString (transaction, 'inserted_at')); const updated = this.parse8601 (this.safeString2 (transaction, 'updated_at', 'completed_at')); @@ -9000,14 +10515,15 @@ module.exports = class bigone extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],23:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],24:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, NotSupported, BadRequest, BadSymbol, AccountSuspended, OrderImmediatelyFillable } = require ('./base/errors'); -const { ROUND, TRUNCATE } = require ('./base/functions/number'); +const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -9050,6 +10566,8 @@ module.exports = class binance extends Exchange { 'fetchTransactions': false, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, + 'fetchTransfers': true, }, 'timeframes': { '1m': '1m', @@ -9198,6 +10716,26 @@ module.exports = class binance extends Exchange { 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/recentRecord', 'apiReferral/kickback/historicalRecord', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccount', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/info', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/recentRecord', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/status', + 'broker/subAccount/depositHist', + 'broker/subAccount/spotSummary', + 'broker/subAccount/marginSummary', + 'broker/subAccount/futuresSummary', + 'broker/rebate/futures/recentRecord', + 'broker/subAccountApi/ipRestriction', + 'broker/universalTransfer', + // v2 not supported yet + // GET /sapi/v2/broker/subAccount/futuresSummary ], 'post': [ 'asset/dust', @@ -9237,11 +10775,30 @@ module.exports = class binance extends Exchange { // leveraged token endpoints 'blvt/subscribe', 'blvt/redeem', - // broker api + // brokerage API 'apiReferral/customization', 'apiReferral/userCustomization', 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/historicalRecord', + 'broker/subAccount', + 'broker/subAccount/margin', + 'broker/subAccount/futures', + 'broker/subAccountApi', + 'broker/subAccountApi/permission', + 'broker/subAccountApi/commission', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/spot', + 'broker/subAccount/bnbBurn/marginInterest', + 'broker/subAccount/blvt', + 'broker/subAccountApi/ipRestriction', + 'broker/subAccountApi/ipRestriction/ipList', + 'broker/universalTransfer', + 'broker/subAccountApi/permission/universalTransfer', + 'broker/subAccountApi/permission/vanillaOptions', ], 'put': [ 'userDataStream', @@ -9252,6 +10809,9 @@ module.exports = class binance extends Exchange { 'margin/order', 'userDataStream', 'userDataStream/isolated', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccountApi/ipRestriction/ipList', ], }, 'wapi': { @@ -9388,6 +10948,8 @@ module.exports = class binance extends Exchange { 'positionSide/dual', 'userTrades', 'income', + 'commissionRate', + 'apiTradingStatus', // broker endpoints 'apiReferral/ifNewUser', 'apiReferral/customization', @@ -9477,6 +11039,7 @@ module.exports = class binance extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.001, @@ -9501,7 +11064,7 @@ module.exports = class binance extends Exchange { 'parseOrderToPrecision': false, // force amounts and costs in parseOrder to precision 'newOrderRespType': { 'market': 'FULL', // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills - 'limit': 'RESULT', // we change it from 'ACK' by default to 'RESULT' + 'limit': 'FULL', // we change it from 'ACK' by default to 'FULL' (returns immediately if limit is not hit) }, 'quoteOrderQty': true, // whether market orders support amounts in quote currency 'broker': { @@ -9510,6 +11073,25 @@ module.exports = class binance extends Exchange { 'future': 'x-xcKtGhcu', 'delivery': 'x-xcKtGhcu', }, + 'fetchPositions': { + 'future': 'fapiPrivateV2GetAccount', // 'fapiPrivateGetPositionRisk' + 'delivery': 'dapiPrivateGetAccount', // 'dapiPrivateGetPositionRisk' + }, + 'accountsByType': { + 'main': 'MAIN', + 'spot': 'MAIN', + 'margin': 'MARGIN', + 'future': 'UMFUTURE', + 'delivery': 'CMFUTURE', + 'mining': 'MINING', + }, + 'typesByAccount': { + 'MAIN': 'spot', + 'MARGIN': 'margin', + 'UMFUTURE': 'future', + 'CMFUTURE': 'delivery', + 'MINING': 'mining', + }, }, // https://binance-docs.github.io/apidocs/spot/en/#error-codes-2 'exceptions': { @@ -9567,6 +11149,8 @@ module.exports = class binance extends Exchange { '-3010': ExchangeError, // {"code":-3010,"msg":"Repay not allowed. Repay amount exceeds borrow amount."} '-3022': AccountSuspended, // You account's trading is banned. '-4028': BadRequest, // {"code":-4028,"msg":"Leverage 100 is not valid"} + '-3020': InsufficientFunds, // {"code":-3020,"msg":"Transfer out amount exceeds max amount."} + '-3041': InsufficientFunds, // {"code":-3041,"msg":"Balance is not enough"} '-5013': InsufficientFunds, // Asset transfer failed: insufficient balance" }, }); @@ -9709,13 +11293,14 @@ module.exports = class binance extends Exchange { let fee = undefined; for (let j = 0; j < networkList.length; j++) { const networkItem = networkList[j]; - const name = this.safeString (networkItem, 'name'); - const withdrawFee = this.safeFloat (networkItem, 'withdrawFee'); + const network = this.safeString (networkItem, 'network'); + // const name = this.safeString (networkItem, 'name'); + const withdrawFee = this.safeNumber (networkItem, 'withdrawFee'); const depositEnable = this.safeValue (networkItem, 'depositEnable'); const withdrawEnable = this.safeValue (networkItem, 'withdrawEnable'); isDepositEnabled = isDepositEnabled || depositEnable; isWithdrawEnabled = isWithdrawEnabled || withdrawEnable; - fees[name] = withdrawFee; + fees[network] = withdrawFee; const isDefault = this.safeValue (networkItem, 'isDefault'); if (isDefault || fee === undefined) { fee = withdrawFee; @@ -9901,7 +11486,7 @@ module.exports = class binance extends Exchange { if (this.options['adjustForTimeDifference']) { await this.loadTimeDifference (); } - const markets = this.safeValue (response, 'symbols'); + const markets = this.safeValue (response, 'symbols', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -9966,10 +11551,10 @@ module.exports = class binance extends Exchange { // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } @@ -9980,47 +11565,26 @@ module.exports = class binance extends Exchange { const stepSize = this.safeString (filter, 'stepSize'); entry['precision']['amount'] = this.precisionFromString (stepSize); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat2 (filter, 'minNotional', 'notional'); + entry['limits']['cost']['min'] = this.safeNumber2 (filter, 'minNotional', 'notional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'spot'); @@ -10191,8 +11755,8 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -10205,13 +11769,13 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['used'] = this.safeFloat (balance, 'initialMargin'); - account['total'] = this.safeFloat2 (balance, 'marginBalance', 'balance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['used'] = this.safeString (balance, 'initialMargin'); + account['total'] = this.safeString2 (balance, 'marginBalance', 'balance'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -10264,36 +11828,36 @@ module.exports = class binance extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'openPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'openPrice'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } async fetchStatus (params = {}) { const response = await this.wapiGetSystemStatus (params); - let status = this.safeValue (response, 'status'); + let status = this.safeString (response, 'status'); if (status !== undefined) { - status = (status === 0) ? 'ok' : 'maintenance'; + status = (status === '0') ? 'ok' : 'maintenance'; this.status = this.extend (this.status, { 'status': status, 'updated': this.milliseconds (), @@ -10322,14 +11886,6 @@ module.exports = class binance extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBidsAsks', 'defaultType', 'spot'); @@ -10384,11 +11940,11 @@ module.exports = class binance extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -10519,8 +12075,11 @@ module.exports = class binance extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -10538,7 +12097,7 @@ module.exports = class binance extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -10551,10 +12110,6 @@ module.exports = class binance extends Exchange { } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } return { 'info': trade, 'timestamp': timestamp, @@ -10673,7 +12228,7 @@ module.exports = class binance extends Exchange { parseOrder (order, market = undefined) { // - // spot + // spot // // { // "symbol": "LTCBTC", @@ -10694,7 +12249,7 @@ module.exports = class binance extends Exchange { // "isWorking": true // } // - // futures + // futures // // { // "symbol": "BTCUSDT", @@ -10712,6 +12267,33 @@ module.exports = class binance extends Exchange { // "updateTime": 1499827319559 // } // + // createOrder with { "newOrderRespType": "FULL" } + // + // { + // "symbol": "BTCUSDT", + // "orderId": 5403233939, + // "orderListId": -1, + // "clientOrderId": "x-R4BD3S825e669e75b6c14f69a2c43e", + // "transactTime": 1617151923742, + // "price": "0.00000000", + // "origQty": "0.00050000", + // "executedQty": "0.00050000", + // "cummulativeQuoteQty": "29.47081500", + // "status": "FILLED", + // "timeInForce": "GTC", + // "type": "MARKET", + // "side": "BUY", + // "fills": [ + // { + // "price": "58941.63000000", + // "qty": "0.00050000", + // "commission": "0.00007050", + // "commissionAsset": "BNB", + // "tradeId": 737466631 + // } + // ] + // } + // const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -10721,80 +12303,26 @@ module.exports = class binance extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); // - Spot/Margin market: cummulativeQuoteQty // - Futures market: cumQuote. // Note this is not the actual cost, since Binance futures uses leverage to calculate margins. - let cost = this.safeFloat2 (order, 'cummulativeQuoteQty', 'cumQuote'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const cost = this.safeNumber2 (order, 'cummulativeQuoteQty', 'cumQuote'); const id = this.safeString (order, 'orderId'); let type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - if (this.options['parseOrderToPrecision']) { - price = parseFloat (this.priceToPrecision (symbol, price)); - } - } - } - } - } else if (type === 'limit_maker') { + if (type === 'limit_maker') { type = 'limit'; } const side = this.safeStringLower (order, 'side'); - let fee = undefined; - let trades = undefined; - const fills = this.safeValue (order, 'fills'); - if (fills !== undefined) { - trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - if (this.options['parseOrderToPrecision']) { - average = parseFloat (this.priceToPrecision (symbol, average)); - } - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const fills = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (fills, market); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -10810,13 +12338,13 @@ module.exports = class binance extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -10863,8 +12391,11 @@ module.exports = class binance extends Exchange { } else { request['newClientOrderId'] = clientOrderId; } - if (market['spot']) { + if ((orderType === 'spot') || (orderType === 'margin')) { request['newOrderRespType'] = this.safeValue (this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills + } else { + // delivery and future + request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK" } // additional required fields depending on the order type let timeInForceIsRequired = false; @@ -10894,7 +12425,7 @@ module.exports = class binance extends Exchange { if (uppercaseType === 'MARKET') { const quoteOrderQty = this.safeValue (this.options, 'quoteOrderQty', false); if (quoteOrderQty) { - const quoteOrderQty = this.safeFloat (params, 'quoteOrderQty'); + const quoteOrderQty = this.safeNumber (params, 'quoteOrderQty'); const precision = market['precision']['price']; if (quoteOrderQty !== undefined) { request['quoteOrderQty'] = this.decimalToPrecision (quoteOrderQty, TRUNCATE, precision, this.precisionMode); @@ -10914,7 +12445,7 @@ module.exports = class binance extends Exchange { } else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) { stopPriceIsRequired = true; quantityIsRequired = true; - if (market['future']) { + if (market['future'] || market['delivery']) { priceIsRequired = true; } } else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) { @@ -10937,7 +12468,7 @@ module.exports = class binance extends Exchange { stopPriceIsRequired = true; } else if (uppercaseType === 'TRAILING_STOP_MARKET') { quantityIsRequired = true; - const callbackRate = this.safeFloat (params, 'callbackRate'); + const callbackRate = this.safeNumber (params, 'callbackRate'); if (callbackRate === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a callbackRate extra param for a ' + type + ' order'); } @@ -10955,7 +12486,7 @@ module.exports = class binance extends Exchange { request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -11171,10 +12702,15 @@ module.exports = class binance extends Exchange { } } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.fetchBalance (params); - const info = this.safeValue (response, 'info', {}); + const defaultType = this.safeString (this.options, 'defaultType', 'future'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + const options = this.safeValue (this.options, 'fetchPositions', {}); + const defaultMethod = (type === 'delivery') ? 'dapiPrivateGetAccount' : 'fapiPrivateV2GetAccount'; + const method = this.safeString (options, type, defaultMethod); + const response = await this[method] (params); // // futures, delivery // @@ -11217,9 +12753,44 @@ module.exports = class binance extends Exchange { // ] // } // - const positions = this.safeValue2 (info, 'positions', 'userAssets', []); - // todo unify parsePosition/parsePositions - return positions; + // fapiPrivateGetPositionRisk, dapiPrivateGetPositionRisk + // + // [ + // { + // symbol: 'XRPUSD_210625', + // positionAmt: '0', + // entryPrice: '0.00000000', + // markPrice: '0.00000000', + // unRealizedProfit: '0.00000000', + // liquidationPrice: '0', + // leverage: '20', + // maxQty: '500000', + // marginType: 'cross', + // isolatedMargin: '0.00000000', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0', + // isolatedWallet: '0' + // }, + // { + // symbol: 'BTCUSD_210326', + // positionAmt: '1', + // entryPrice: '60665.79999885', + // markPrice: '60696.76856843', + // unRealizedProfit: '0.00000084', + // liquidationPrice: '58034.68208092', + // leverage: '20', + // maxQty: '50', + // marginType: 'isolated', + // isolatedMargin: '0.00008345', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0.00164753', + // isolatedWallet: '0.00008261' + // }, + // ] + // + return this.safeValue (response, 'positions', response); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -11357,7 +12928,7 @@ module.exports = class binance extends Exchange { // const fee = { 'currency': earnedCurrency, - 'cost': this.safeFloat (trade, 'serviceChargeAmount'), + 'cost': this.safeNumber (trade, 'serviceChargeAmount'), }; let symbol = undefined; let amount = undefined; @@ -11365,13 +12936,13 @@ module.exports = class binance extends Exchange { let side = undefined; if (tradedCurrencyIsQuote) { symbol = applicantSymbol; - amount = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); - cost = this.safeFloat (trade, 'amount'); + amount = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); + cost = this.safeNumber (trade, 'amount'); side = 'buy'; } else { symbol = tradedCurrency + '/' + earnedCurrency; - amount = this.safeFloat (trade, 'amount'); - cost = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); + amount = this.safeNumber (trade, 'amount'); + cost = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); side = 'sell'; } let price = undefined; @@ -11544,8 +13115,8 @@ module.exports = class binance extends Exchange { } } const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'transactionFee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'transactionFee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -11572,6 +13143,151 @@ module.exports = class binance extends Exchange { }; } + parseTransferStatus (status) { + const statuses = { + 'CONFIRMED': 'ok', + }; + return this.safeString (statuses, status, status); + } + + parseTransfer (transfer, currency = undefined) { + // + // transfer + // + // { + // "tranId":13526853623 + // } + // + // fetchTransfers + // + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // } + // + const id = this.safeString (transfer, 'tranId'); + const currencyId = this.safeString (transfer, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const amount = this.safeNumber (transfer, 'amount'); + const type = this.safeString (transfer, 'type'); + let fromAccount = undefined; + let toAccount = undefined; + const typesByAccount = this.safeValue (this.options, 'typesByAccount', {}); + if (type !== undefined) { + const parts = type.split ('_'); + fromAccount = this.safeValue (parts, 0); + toAccount = this.safeValue (parts, 1); + fromAccount = this.safeString (typesByAccount, fromAccount, fromAccount); + toAccount = this.safeString (typesByAccount, toAccount, toAccount); + } + const timestamp = this.safeInteger (transfer, 'timestamp'); + const status = this.parseTransferStatus (this.safeString (transfer, 'status')); + return { + 'info': transfer, + 'id': id, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'currency': code, + 'amount': amount, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': status, + }; + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount, fromAccount); + const toId = this.safeString (accountsByType, toAccount, toAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'asset': currency['id'], + 'amount': this.currencyToPrecision (code, amount), + 'type': type, + }; + const response = await this.sapiPostAssetTransfer (this.extend (request, params)); + // + // { + // "tranId":13526853623 + // } + // + const transfer = this.parseTransfer (response, currency); + return this.extend (transfer, { + 'amount': amount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + }); + } + + async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const defaultType = this.safeString2 (this.options, 'fetchTransfers', 'defaultType', 'spot'); + const fromAccount = this.safeString (params, 'fromAccount', defaultType); + const defaultTo = (fromAccount === 'future') ? 'spot' : 'future'; + const toAccount = this.safeString (params, 'toAccount', defaultTo); + let type = this.safeString (params, 'type'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + if (type === undefined) { + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount parameter must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount parameter must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'type': type, + }; + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['size'] = limit; + } + const response = await this.sapiGetAssetTransfer (this.extend (request, params)); + // + // { + // total: 3, + // rows: [ + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // }, + // ] + // } + // + const rows = this.safeValue (response, 'rows', []); + return this.parseTransfers (rows, currency, since, limit); + } + async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -11634,7 +13350,7 @@ module.exports = class binance extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (detail[id], 'withdrawFee'); + withdrawFees[code] = this.safeNumber (detail[id], 'withdrawFee'); } return { 'withdraw': withdrawFees, @@ -11681,8 +13397,8 @@ module.exports = class binance extends Exchange { return { 'info': fee, 'symbol': symbol, - 'maker': this.safeFloat (fee, 'maker'), - 'taker': this.safeFloat (fee, 'taker'), + 'maker': this.safeNumber (fee, 'maker'), + 'taker': this.safeNumber (fee, 'taker'), }; } @@ -11744,7 +13460,6 @@ module.exports = class binance extends Exchange { if (api === 'wapi') { url += '.html'; } - const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); if (path === 'historicalTrades') { if (this.apiKey) { headers = { @@ -11753,19 +13468,22 @@ module.exports = class binance extends Exchange { } else { throw new AuthenticationError (this.id + ' historicalTrades endpoint requires `apiKey` credential'); } - } else if (userDataStream) { + } + const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); + if (userDataStream) { if (this.apiKey) { // v1 special case for userDataStream - body = this.urlencode (params); headers = { 'X-MBX-APIKEY': this.apiKey, 'Content-Type': 'application/x-www-form-urlencoded', }; + if (method !== 'GET') { + body = this.urlencode (params); + } } else { throw new AuthenticationError (this.id + ' userDataStream endpoint requires `apiKey` credential'); } - } - if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { + } else if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { this.checkRequiredCredentials (); let query = undefined; const recvWindow = this.safeInteger (this.options, 'recvWindow', 5000); @@ -11797,13 +13515,8 @@ module.exports = class binance extends Exchange { headers['Content-Type'] = 'application/x-www-form-urlencoded'; } } else { - // userDataStream endpoints are public, but POST, PUT, DELETE - // therefore they don't accept URL query arguments - // https://github.com/ccxt/ccxt/issues/5224 - if (!userDataStream) { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } + if (Object.keys (params).length) { + url += '?' + this.urlencode (params); } } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; @@ -11885,7 +13598,7 @@ module.exports = class binance extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],24:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],25:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -11937,13 +13650,14 @@ module.exports = class binanceus extends binance { }; -},{"./binance.js":23}],25:[function(require,module,exports){ +},{"./binance.js":24}],26:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, InvalidNonce, AuthenticationError, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -12095,12 +13809,12 @@ module.exports = class bit2c extends Exchange { const currencyId = this.currencyId (code); const uppercase = currencyId.toUpperCase (); if (uppercase in balance) { - account['free'] = this.safeFloat (balance, 'AVAILABLE_' + uppercase); - account['total'] = this.safeFloat (balance, uppercase); + account['free'] = this.safeString (balance, 'AVAILABLE_' + uppercase); + account['total'] = this.safeString (balance, uppercase); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -12119,22 +13833,22 @@ module.exports = class bit2c extends Exchange { }; const ticker = await this.publicGetExchangesPairTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const averagePrice = this.safeFloat (ticker, 'av'); - const baseVolume = this.safeFloat (ticker, 'a'); + const averagePrice = this.safeNumber (ticker, 'av'); + const baseVolume = this.safeNumber (ticker, 'a'); let quoteVolume = undefined; if (baseVolume !== undefined && averagePrice !== undefined) { quoteVolume = baseVolume * averagePrice; } - const last = this.safeFloat (ticker, 'll'); + const last = this.safeNumber (ticker, 'll'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'h'), + 'bid': this.safeNumber (ticker, 'h'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'l'), + 'ask': this.safeNumber (ticker, 'l'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -12216,14 +13930,8 @@ module.exports = class bit2c extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -12236,7 +13944,7 @@ module.exports = class bit2c extends Exchange { } const id = this.safeString (order, 'id'); const status = this.safeString (order, 'status'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -12253,12 +13961,12 @@ module.exports = class bit2c extends Exchange { 'amount': amount, 'filled': undefined, 'remaining': undefined, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -12284,16 +13992,16 @@ module.exports = class bit2c extends Exchange { parseTrade (trade, market = undefined) { let timestamp = undefined; let id = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let orderId = undefined; let feeCost = undefined; let side = undefined; const reference = this.safeString (trade, 'reference'); if (reference !== undefined) { timestamp = this.safeTimestamp (trade, 'ticks'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'firstAmount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'firstAmount'); const reference_parts = reference.split ('|'); // reference contains 'pair|orderId|tradeId' if (market === undefined) { const marketId = this.safeString (trade, 'pair'); @@ -12311,12 +14019,12 @@ module.exports = class bit2c extends Exchange { } else if (side === 1) { side = 'sell'; } - feeCost = this.safeFloat (trade, 'feeAmount'); + feeCost = this.safeNumber (trade, 'feeAmount'); } else { timestamp = this.safeTimestamp (trade, 'date'); id = this.safeString (trade, 'tid'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'amount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'amount'); side = this.safeValue (trade, 'isBid'); if (side !== undefined) { if (side) { @@ -12330,6 +14038,9 @@ module.exports = class bit2c extends Exchange { if (market !== undefined) { symbol = market['symbol']; } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -12342,7 +14053,7 @@ module.exports = class bit2c extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': { 'cost': feeCost, 'currency': 'NIS', @@ -12398,13 +14109,14 @@ module.exports = class bit2c extends Exchange { }; -},{"./base/Exchange":6,"./base/errors":8}],26:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],27:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -12479,21 +14191,23 @@ module.exports = class bitbank extends Exchange { }, }, 'markets': { + 'BAT/JPY': { 'id': 'bat_jpy', 'symbol': 'BAT/JPY', 'base': 'BAT', 'quote': 'JPY', 'baseId': 'bat', 'quoteId': 'jpy' }, + 'BAT/BTC': { 'id': 'bat_btc', 'symbol': 'BAT/BTC', 'base': 'BAT', 'quote': 'BTC', 'baseId': 'bat', 'quoteId': 'btc' }, 'BCH/BTC': { 'id': 'bcc_btc', 'symbol': 'BCH/BTC', 'base': 'BCH', 'quote': 'BTC', 'baseId': 'bcc', 'quoteId': 'btc' }, 'BCH/JPY': { 'id': 'bcc_jpy', 'symbol': 'BCH/JPY', 'base': 'BCH', 'quote': 'JPY', 'baseId': 'bcc', 'quoteId': 'jpy' }, + 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, + 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, + 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, + 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, + 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, 'MONA/BTC': { 'id': 'mona_btc', 'symbol': 'MONA/BTC', 'base': 'MONA', 'quote': 'BTC', 'baseId': 'mona', 'quoteId': 'btc' }, 'MONA/JPY': { 'id': 'mona_jpy', 'symbol': 'MONA/JPY', 'base': 'MONA', 'quote': 'JPY', 'baseId': 'mona', 'quoteId': 'jpy' }, 'QTUM/BTC': { 'id': 'qtum_btc', 'symbol': 'QTUM/BTC', 'base': 'QTUM', 'quote': 'BTC', 'baseId': 'qtum', 'quoteId': 'btc' }, 'QTUM/JPY': { 'id': 'qtum_jpy', 'symbol': 'QTUM/JPY', 'base': 'QTUM', 'quote': 'JPY', 'baseId': 'qtum', 'quoteId': 'jpy' }, - 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, - 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, - 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, - 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, - 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, - 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, - 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, - 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, 'XLM/BTC': { 'id': 'xlm_btc', 'symbol': 'XLM/BTC', 'base': 'XLM', 'quote': 'BTC', 'baseId': 'xlm', 'quoteId': 'btc' }, + 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, + 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, + 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, }, 'fees': { 'trading': { @@ -12542,16 +14256,16 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -12561,7 +14275,7 @@ module.exports = class bitbank extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -12597,18 +14311,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; feeCurrency = market['quote']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'transaction_id', 'trade_id'); const takerOrMaker = this.safeString (trade, 'maker_taker'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee_amount_quote'); + const feeCost = this.safeNumber (trade, 'fee_amount_quote'); if (feeCost !== undefined) { fee = { 'currency': feeCurrency, @@ -12660,11 +14371,11 @@ module.exports = class bitbank extends Exchange { // return [ this.safeInteger (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -12715,14 +14426,13 @@ module.exports = class bitbank extends Exchange { const balance = assets[i]; const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'free_amount'), - 'used': this.safeFloat (balance, 'locked_amount'), - 'total': this.safeFloat (balance, 'onhand_amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'free_amount'); + account['used'] = this.safeString (balance, 'locked_amount'); + account['total'] = this.safeString (balance, 'onhand_amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -12747,21 +14457,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (order, 'ordered_at'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'start_amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const average = this.safeFloat (order, 'average_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'start_amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const average = this.safeNumber (order, 'average_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -12775,7 +14479,7 @@ module.exports = class bitbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, @@ -12783,7 +14487,7 @@ module.exports = class bitbank extends Exchange { 'trades': undefined, 'fee': undefined, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -13026,13 +14730,14 @@ module.exports = class bitbank extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],27:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],28:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { InvalidNonce, InsufficientFunds, AuthenticationError, InvalidOrder, ExchangeError, OrderNotFound, AccountSuspended, BadSymbol, OrderImmediatelyFillable, RateLimitExceeded, OnMaintenance, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -13307,8 +15012,8 @@ module.exports = class bitbay extends Exchange { if (this.inArray (base, fiatCurrencies) || this.inArray (quote, fiatCurrencies)) { fees = this.safeValue (this.fees, 'fiat', {}); } - const maker = this.safeFloat (fees, 'maker'); - const taker = this.safeFloat (fees, 'taker'); + const maker = this.safeNumber (fees, 'maker'); + const taker = this.safeNumber (fees, 'taker'); // todo: check that the limits have ben interpreted correctly // todo: parse the fees page result.push ({ @@ -13324,7 +15029,7 @@ module.exports = class bitbay extends Exchange { 'taker': taker, 'limits': { 'amount': { - 'min': this.safeFloat (first, 'minOffer'), + 'min': this.safeNumber (first, 'minOffer'), 'max': undefined, }, 'price': { @@ -13332,7 +15037,7 @@ module.exports = class bitbay extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (second, 'minOffer'), + 'min': this.safeNumber (second, 'minOffer'), 'max': undefined, }, }, @@ -13372,16 +15077,10 @@ module.exports = class bitbay extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (order, 'time'); - const amount = this.safeFloat (order, 'startAmount'); - const remaining = this.safeFloat (order, 'currentAmount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } + const amount = this.safeNumber (order, 'startAmount'); + const remaining = this.safeNumber (order, 'currentAmount'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'info': order, @@ -13394,16 +15093,16 @@ module.exports = class bitbay extends Exchange { 'timeInForce': undefined, 'postOnly': postOnly, 'side': this.safeStringLower (order, 'offerType'), - 'price': this.safeFloat (order, 'rate'), + 'price': this.safeNumber (order, 'rate'), 'stopPrice': undefined, 'amount': amount, 'cost': undefined, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'average': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -13456,11 +15155,11 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lockedFunds'); - account['free'] = this.safeFloat (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'lockedFunds'); + account['free'] = this.safeString (balance, 'availableFunds'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -13479,22 +15178,22 @@ module.exports = class bitbay extends Exchange { }; const ticker = await this.publicGetIdTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'volume'); - const vwap = this.safeFloat (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max'), + 'low': this.safeNumber (ticker, 'min'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -13503,7 +15202,7 @@ module.exports = class bitbay extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), + 'average': this.safeNumber (ticker, 'average'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -13804,7 +15503,7 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const change = this.safeValue (item, 'change', {}); - let amount = this.safeFloat (change, 'total'); + let amount = this.safeNumber (change, 'total'); let direction = 'in'; if (amount < 0) { direction = 'out'; @@ -13816,9 +15515,9 @@ module.exports = class bitbay extends Exchange { const referenceId = this.safeString (item, 'detailId'); const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const fundsBefore = this.safeValue (item, 'fundsBefore', {}); - const before = this.safeFloat (fundsBefore, 'total'); + const before = this.safeNumber (fundsBefore, 'total'); const fundsAfter = this.safeValue (item, 'fundsAfter', {}); - const after = this.safeFloat (fundsAfter, 'total'); + const after = this.safeNumber (fundsAfter, 'total'); return { 'info': item, 'id': id, @@ -13875,11 +15574,11 @@ module.exports = class bitbay extends Exchange { const first = this.safeValue (ohlcv, 1, {}); return [ this.safeInteger (ohlcv, 0), - this.safeFloat (first, 'o'), - this.safeFloat (first, 'h'), - this.safeFloat (first, 'l'), - this.safeFloat (first, 'c'), - this.safeFloat (first, 'v'), + this.safeNumber (first, 'o'), + this.safeNumber (first, 'h'), + this.safeNumber (first, 'l'), + this.safeNumber (first, 'c'), + this.safeNumber (first, 'v'), ]; } @@ -13962,15 +15661,12 @@ module.exports = class bitbay extends Exchange { if (wasTaker !== undefined) { takerOrMaker = wasTaker ? 'taker' : 'maker'; } - const price = this.safeFloat2 (trade, 'rate', 'r'); - const amount = this.safeFloat2 (trade, 'amount', 'a'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'commissionValue'); + const priceString = this.safeString2 (trade, 'rate', 'r'); + const amountString = this.safeString2 (trade, 'amount', 'a'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'commissionValue'); const marketId = this.safeString (trade, 'market'); market = this.safeMarket (marketId, market, '-'); const symbol = market['symbol']; @@ -14302,7 +15998,7 @@ module.exports = class bitbay extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],28:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],29:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -14338,7 +16034,7 @@ module.exports = class bitcoincom extends hitbtc { } }; -},{"./hitbtc.js":93}],29:[function(require,module,exports){ +},{"./hitbtc.js":91}],30:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -14346,6 +16042,7 @@ module.exports = class bitcoincom extends hitbtc { const Exchange = require ('./base/Exchange'); const { NotSupported, RateLimitExceeded, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, InvalidNonce, BadSymbol } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -14386,6 +16083,7 @@ module.exports = class bitfinex extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': '1m', @@ -14499,6 +16197,7 @@ module.exports = class bitfinex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'maker': 0.1 / 100, @@ -14685,6 +16384,8 @@ module.exports = class bitfinex extends Exchange { 'No summary found.': ExchangeError, // fetchTradingFees (summary) endpoint can give this vague error message 'Cannot evaluate your available balance, please try again': ExchangeNotAvailable, 'Unknown symbol': BadSymbol, + 'Cannot complete transfer. Exchange balance insufficient.': InsufficientFunds, + 'Momentary balance check. Please wait few seconds and try the transfer again.': ExchangeError, }, 'broad': { 'Invalid X-BFX-SIGNATURE': AuthenticationError, @@ -14782,6 +16483,15 @@ module.exports = class bitfinex extends Exchange { 'limit': 'exchange limit', 'market': 'exchange market', }, + 'accountsByType': { + 'spot': 'exchange', + 'margin': 'trading', + 'funding': 'deposit', + 'exchange': 'exchange', + 'trading': 'trading', + 'deposit': 'deposit', + 'derivatives': 'trading', + }, }, }); } @@ -14795,7 +16505,7 @@ module.exports = class bitfinex extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdraw[code] = this.safeFloat (fees, id); + withdraw[code] = this.safeNumber (fees, id); } return { 'info': response, @@ -14831,14 +16541,31 @@ module.exports = class bitfinex extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } async fetchMarkets (params = {}) { const ids = await this.publicGetSymbols (); + // + // [ "btcusd", "ltcusd", "ltcbtc" ] + // const details = await this.publicGetSymbolsDetails (); + // + // [ + // { + // "pair":"btcusd", + // "price_precision":5, + // "initial_margin":"10.0", + // "minimum_margin":"5.0", + // "maximum_order_size":"2000.0", + // "minimum_order_size":"0.0002", + // "expiration":"NA", + // "margin":true + // }, + // ] + // const result = []; for (let i = 0; i < details.length; i++) { const market = details[i]; @@ -14869,8 +16596,8 @@ module.exports = class bitfinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -14881,6 +16608,7 @@ module.exports = class bitfinex extends Exchange { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -14889,6 +16617,8 @@ module.exports = class bitfinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': true, + 'type': 'spot', + 'margin': margin, 'precision': precision, 'limits': limits, 'info': market, @@ -14913,40 +16643,15 @@ module.exports = class bitfinex extends Exchange { return this.decimalToPrecision (price, TRUNCATE, 8, DECIMAL_PLACES); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - const code = market[key]; - const currency = this.safeValue (this.currencies, code); - if (currency !== undefined) { - const precision = this.safeInteger (currency, 'precision'); - if (precision !== undefined) { - cost = parseFloat (this.currencyToPrecision (code, cost)); - } - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); - const types = { - 'exchange': 'exchange', - 'deposit': 'funding', - 'trading': 'margin', - }; - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } const query = this.omit (params, 'type'); const response = await this.privatePostBalances (query); // [ { type: 'deposit', @@ -14962,12 +16667,16 @@ module.exports = class bitfinex extends Exchange { // amount: '0.0005', // available: '0.0005' } ], const result = { 'info': response }; + const isDerivative = requestedType === 'derivatives'; for (let i = 0; i < response.length; i++) { const balance = response[i]; const type = this.safeString (balance, 'type'); - const parsedType = this.safeString (types, type); - if ((parsedType === balanceType) || (type === balanceType)) { - const currencyId = this.safeString (balance, 'currency'); + const currencyId = this.safeStringLower (balance, 'currency', ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { const code = this.safeCurrencyCode (currencyId); // bitfinex had BCH previously, now it's BAB, but the old // BCH symbol is kept for backward-compatibility @@ -14976,13 +16685,80 @@ module.exports = class bitfinex extends Exchange { // https://github.com/ccxt/ccxt/issues/4989 if (!(code in result)) { const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currencyId = this.currencyId (code); + const fromCurrencyId = this.convertDerivativesId (currencyId, fromAccount); + const toCurrencyId = this.convertDerivativesId (currencyId, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'walletfrom': fromId, + 'walletto': toId, + }; + const response = await this.privatePostTransfer (this.extend (request, params)); + // [ + // { + // status: 'success', + // message: '0.0001 Bitcoin transfered from Margin to Exchange' + // } + // ] + const result = this.safeValue (response, 0); + const status = this.safeString (result, 'status'); + const message = this.safeString (result, 'message'); + if (message === undefined) { + throw new ExchangeError (this.id + ' transfer failed'); + } + // [{"status":"error","message":"Momentary balance check. Please wait few seconds and try the transfer again."}] + if (status === 'error') { + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + return { + 'info': response, + 'status': status, + 'amount': requestedAmount, + 'code': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'timestamp': undefined, + 'datetime': undefined, + }; + } + + convertDerivativesId (currencyId, type) { + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if ((type !== 'derivatives' && type !== 'trading' && type !== 'margin') && isDerivativeCode) { + currencyId = currencyId.slice (0, start); + } else if (type === 'derivatives' && !isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + return currencyId; } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -15021,7 +16797,7 @@ module.exports = class bitfinex extends Exchange { } parseTicker (ticker, market = undefined) { - let timestamp = this.safeFloat (ticker, 'timestamp'); + let timestamp = this.safeNumber (ticker, 'timestamp'); if (timestamp !== undefined) { timestamp *= 1000; } @@ -15044,16 +16820,16 @@ module.exports = class bitfinex extends Exchange { } } } - const last = this.safeFloat (ticker, 'last_price'); + const last = this.safeNumber (ticker, 'last_price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -15062,8 +16838,8 @@ module.exports = class bitfinex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'mid'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'mid'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -15071,24 +16847,21 @@ module.exports = class bitfinex extends Exchange { parseTrade (trade, market) { const id = this.safeString (trade, 'tid'); - let timestamp = this.safeFloat (trade, 'timestamp'); + let timestamp = this.safeNumber (trade, 'timestamp'); if (timestamp !== undefined) { timestamp = parseInt (timestamp) * 1000; } const type = undefined; const side = this.safeStringLower (trade, 'type'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; if ('fee_amount' in trade) { - const feeCost = -this.safeFloat (trade, 'fee_amount'); + const feeCost = -this.safeNumber (trade, 'fee_amount'); const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { @@ -15203,6 +16976,30 @@ module.exports = class bitfinex extends Exchange { } parseOrder (order, market = undefined) { + // + // { + // id: 57334010955, + // cid: 1611584840966, + // cid_date: null, + // gid: null, + // symbol: 'ltcbtc', + // exchange: null, + // price: '0.0042125', + // avg_execution_price: '0.0042097', + // side: 'sell', + // type: 'exchange market', + // timestamp: '1611584841.0', + // is_live: false, + // is_cancelled: false, + // is_hidden: 0, + // oco_order: 0, + // was_forced: false, + // original_amount: '0.205176', + // remaining_amount: '0.0', + // executed_amount: '0.205176', + // src: 'web' + // } + // const side = this.safeString (order, 'side'); const open = this.safeValue (order, 'is_live'); const canceled = this.safeValue (order, 'is_cancelled'); @@ -15214,30 +17011,17 @@ module.exports = class bitfinex extends Exchange { } else { status = 'closed'; } - let symbol = undefined; - if (market === undefined) { - const marketId = this.safeStringUpper (order, 'symbol'); - if (marketId !== undefined) { - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } - } - } - if (market !== undefined) { - symbol = market['symbol']; - } - let orderType = order['type']; + const marketId = this.safeStringUpper (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market); + let orderType = this.safeString (order, 'type', ''); const exchange = orderType.indexOf ('exchange ') >= 0; if (exchange) { const parts = order['type'].split (' '); orderType = parts[1]; } - let timestamp = this.safeFloat (order, 'timestamp'); - if (timestamp !== undefined) { - timestamp = parseInt (timestamp) * 1000; - } + const timestamp = this.safeTimestamp (order, 'timestamp'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -15249,17 +17033,17 @@ module.exports = class bitfinex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': side, - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_execution_price'), - 'amount': this.safeFloat (order, 'original_amount'), - 'remaining': this.safeFloat (order, 'remaining_amount'), - 'filled': this.safeFloat (order, 'executed_amount'), + 'average': this.safeNumber (order, 'avg_execution_price'), + 'amount': this.safeNumber (order, 'original_amount'), + 'remaining': this.safeNumber (order, 'remaining_amount'), + 'filled': this.safeNumber (order, 'executed_amount'), 'status': status, 'fee': undefined, 'cost': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -15314,11 +17098,11 @@ module.exports = class bitfinex extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -15466,11 +17250,11 @@ module.exports = class bitfinex extends Exchange { // "timestamp_created": "1561716066.0" // } // - let timestamp = this.safeFloat (transaction, 'timestamp_created'); + let timestamp = this.safeNumber (transaction, 'timestamp_created'); if (timestamp !== undefined) { timestamp = parseInt (timestamp * 1000); } - let updated = this.safeFloat (transaction, 'timestamp'); + let updated = this.safeNumber (transaction, 'timestamp'); if (updated !== undefined) { updated = parseInt (updated * 1000); } @@ -15478,7 +17262,7 @@ module.exports = class bitfinex extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const type = this.safeStringLower (transaction, 'type'); // DEPOSIT or WITHDRAWAL const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -15491,7 +17275,7 @@ module.exports = class bitfinex extends Exchange { 'address': this.safeString (transaction, 'address'), // todo: this is actually the tag for XRP transfers (the address is missing) 'tag': undefined, // refix it properly for the tag from description 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -15545,7 +17329,7 @@ module.exports = class bitfinex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // @@ -15623,7 +17407,7 @@ module.exports = class bitfinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],30:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],31:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -15912,6 +17696,15 @@ module.exports = class bitfinex2 extends bitfinex { 'JPY': 'JPY', 'GBP': 'GBP', }, + // actually the correct names unlike the v1 + // we don't want to extend this with accountsByType in v1 + 'v2AccountsByType': { + 'spot': 'exchange', + 'exchange': 'exchange', + 'funding': 'funding', + 'margin': 'margin', + 'derivatives': 'margin', + }, }, 'exceptions': { 'exact': { @@ -15993,8 +17786,8 @@ module.exports = class bitfinex2 extends bitfinex { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -16005,6 +17798,7 @@ module.exports = class bitfinex2 extends bitfinex { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -16019,6 +17813,7 @@ module.exports = class bitfinex2 extends bitfinex { 'type': type, 'swap': false, 'spot': spot, + 'margin': margin, 'futures': futures, }); } @@ -16131,7 +17926,7 @@ module.exports = class bitfinex2 extends bitfinex { const ids = this.safeValue (response, 0, []); const result = {}; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; const code = this.safeCurrencyCode (id); const label = this.safeValue (indexed['label'], id, []); const name = this.safeString (label, 1); @@ -16139,13 +17934,14 @@ module.exports = class bitfinex2 extends bitfinex { const type = this.safeString (pool, 1); const feeValues = this.safeValue (indexed['fees'], id, []); const fees = this.safeValue (feeValues, 1, []); - const fee = this.safeFloat (fees, 1); + const fee = this.safeNumber (fees, 1); + const undl = this.safeValue (indexed['undl'], id, []); const precision = 8; // default precision, todo: fix "magic constants" - id = 'f' + id; + const fid = 'f' + id; result[code] = { - 'id': id, + 'id': fid, 'code': code, - 'info': [ id, label, pool, feeValues ], + 'info': [ id, label, pool, feeValues, undl ], 'type': type, 'name': name, 'active': true, @@ -16176,40 +17972,117 @@ module.exports = class bitfinex2 extends bitfinex { async fetchBalance (params = {}) { // this api call does not return the 'used' amount - use the v1 version instead (which also returns zero balances) + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 await this.loadMarkets (); - const response = await this.privatePostAuthRWallets (params); - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } + const isDerivative = requestedType === 'derivatives'; + const query = this.omit (params, 'type'); + const response = await this.privatePostAuthRWallets (query); const result = { 'info': response }; - for (let b = 0; b < response.length; b++) { - const balance = response[b]; - const accountType = balance[0]; - let currency = balance[1]; - const total = balance[2]; - const available = balance[4]; - if (accountType === balanceType) { - if (currency[0] === 't') { - currency = currency.slice (1); - } - const code = this.safeCurrencyCode (currency); + for (let i = 0; i < response.length; i++) { + const balance = response[i]; + const type = this.safeString (balance, 0); + const currencyId = this.safeStringLower (balance, 1, ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { + const code = this.safeCurrencyCode (currencyId); const account = this.account (); - // do not fill in zeroes and missing values in the parser - // rewrite and unify the following to use the unified parseBalance - account['total'] = total; - if (!available) { - if (available === 0) { - account['free'] = 0; - account['used'] = total; - } else { - account['free'] = total; - } - } else { - account['free'] = available; - account['used'] = account['total'] - account['free']; - } + account['total'] = this.safeString (balance, 2); + account['free'] = this.safeString (balance, 4); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currency = this.currency (code); + const fromCurrencyId = this.convertDerivativesId (currency, fromAccount); + const toCurrencyId = this.convertDerivativesId (currency, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + // this request is slightly different from v1 fromAccount -> from + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'from': fromId, + 'to': toId, + }; + const response = await this.privatePostAuthWTransfer (this.extend (request, params)); + // [1616451183763,"acc_tf",null,null,[1616451183763,"exchange","margin",null,"UST","UST",null,1],null,"SUCCESS","1.0 Tether USDt transfered from Exchange to Margin"] + const timestamp = this.safeInteger (response, 0); + // ["error",10001,"Momentary balance check. Please wait few seconds and try the transfer again."] + const error = this.safeString (response, 0); + if (error === 'error') { + const message = this.safeString (response, 2, ''); + // same message as in v1 + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + const info = this.safeValue (response, 4); + const fromResponse = this.safeString (info, 1); + const toResponse = this.safeString (info, 2); + const toCode = this.safeCurrencyCode (this.safeString (info, 5)); + const success = this.safeString (response, 6); + const status = (success === 'SUCCESS') ? 'ok' : undefined; + return { + 'info': response, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'status': status, + 'amount': requestedAmount, + 'code': toCode, + 'fromAccount': fromResponse, + 'toAccount': toResponse, + }; + } + + convertDerivativesId (currency, type) { + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 + // { + // id: 'fUSTF0', + // code: 'USTF0', + // info: [ 'USTF0', [], [], [], [ 'USTF0', 'UST' ] ], + const info = this.safeValue (currency, 'info'); + const transferId = this.safeString (info, 0); + const underlying = this.safeValue (info, 4, []); + let currencyId = undefined; + if (type === 'derivatives') { + currencyId = this.safeString (underlying, 0, transferId); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if (!isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + } else if (type !== 'margin') { + currencyId = this.safeString (underlying, 1, transferId); + } else { + currencyId = transferId; + } + return currencyId; } async fetchOrder (id, symbol = undefined, params = {}) { @@ -16239,9 +18112,10 @@ module.exports = class bitfinex2 extends bitfinex { const priceIndex = (fullRequest['precision'] === 'R0') ? 1 : 0; for (let i = 0; i < orderbook.length; i++) { const order = orderbook[i]; - const price = order[priceIndex]; - const amount = Math.abs (order[2]); - const side = (order[2] > 0) ? 'bids' : 'asks'; + const price = this.safeNumber (order, priceIndex); + const signedAmount = this.safeNumber (order, 2); + const amount = Math.abs (signedAmount); + const side = (signedAmount > 0) ? 'bids' : 'asks'; result[side].push ([ price, amount ]); } result['bids'] = this.sortBy (result['bids'], 0, true); @@ -16256,26 +18130,26 @@ module.exports = class bitfinex2 extends bitfinex { symbol = market['symbol']; } const length = ticker.length; - const last = ticker[length - 4]; + const last = this.safeNumber (ticker, length - 4); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': ticker[length - 2], - 'low': ticker[length - 1], - 'bid': ticker[length - 10], + 'high': this.safeNumber (ticker, length - 2), + 'low': this.safeNumber (ticker, length - 1), + 'bid': this.safeNumber (ticker, length - 10), 'bidVolume': undefined, - 'ask': ticker[length - 8], + 'ask': this.safeNumber (ticker, length - 8), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': ticker[length - 6], - 'percentage': ticker[length - 5] * 100, + 'change': this.safeNumber (ticker, length - 6), + 'percentage': this.safeNumber (ticker, length - 5) * 100, 'average': undefined, - 'baseVolume': ticker[length - 3], + 'baseVolume': this.safeNumber (ticker, length - 3), 'quoteVolume': undefined, 'info': ticker, }; @@ -16364,12 +18238,12 @@ module.exports = class bitfinex2 extends bitfinex { // const tradeLength = trade.length; const isPrivate = (tradeLength > 5); - const id = trade[0].toString (); + const id = this.safeString (trade, 0); const amountIndex = isPrivate ? 4 : 2; - let amount = trade[amountIndex]; + let amount = this.safeNumber (trade, amountIndex); let cost = undefined; const priceIndex = isPrivate ? 5 : 3; - const price = trade[priceIndex]; + const price = this.safeNumber (trade, priceIndex); let side = undefined; let orderId = undefined; let takerOrMaker = undefined; @@ -16377,7 +18251,7 @@ module.exports = class bitfinex2 extends bitfinex { let fee = undefined; let symbol = undefined; const timestampIndex = isPrivate ? 2 : 1; - const timestamp = trade[timestampIndex]; + const timestamp = this.safeInteger (trade, timestampIndex); if (isPrivate) { const marketId = trade[1]; if (marketId in this.markets_by_id) { @@ -16386,10 +18260,12 @@ module.exports = class bitfinex2 extends bitfinex { } else { symbol = this.parseSymbol (marketId); } - orderId = trade[3].toString (); - takerOrMaker = (trade[8] === 1) ? 'maker' : 'taker'; - let feeCost = trade[9]; - const feeCurrency = this.safeCurrencyCode (trade[10]); + orderId = this.safeString (trade, 3); + const maker = this.safeInteger (trade, 8); + takerOrMaker = (maker === 1) ? 'maker' : 'taker'; + let feeCost = this.safeNumber (trade, 9); + const feeCurrencyId = this.safeString (trade, 10); + const feeCurrency = this.safeCurrencyCode (feeCurrencyId); if (feeCost !== undefined) { feeCost = -feeCost; if (symbol in this.markets) { @@ -16530,10 +18406,10 @@ module.exports = class bitfinex2 extends bitfinex { // https://github.com/ccxt/ccxt/issues/6686 // const timestamp = this.safeTimestamp (order, 5); const timestamp = this.safeInteger (order, 5); - const remaining = Math.abs (this.safeFloat (order, 6)); - const amount = Math.abs (this.safeFloat (order, 7)); - const filled = amount - remaining; - const side = (order[7] < 0) ? 'sell' : 'buy'; + const remaining = Math.abs (this.safeNumber (order, 6)); + const signedAmount = this.safeNumber (order, 7); + const amount = Math.abs (signedAmount); + const side = (signedAmount < 0) ? 'sell' : 'buy'; const orderType = this.safeString (order, 8); const type = this.safeString (this.safeValue (this.options, 'exchangeTypes'), orderType); let status = undefined; @@ -16542,11 +18418,10 @@ module.exports = class bitfinex2 extends bitfinex { const parts = statusString.split (' @ '); status = this.parseOrderStatus (this.safeString (parts, 0)); } - const price = this.safeFloat (order, 16); - const average = this.safeFloat (order, 17); - const cost = price * filled; + const price = this.safeNumber (order, 16); + const average = this.safeNumber (order, 17); const clientOrderId = this.safeString (order, 2); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -16561,14 +18436,14 @@ module.exports = class bitfinex2 extends bitfinex { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -16585,11 +18460,11 @@ module.exports = class bitfinex2 extends bitfinex { if ((orderType === 'LIMIT') || (orderType === 'EXCHANGE LIMIT')) { request['price'] = this.numberToString (price); } else if ((orderType === 'STOP') || (orderType === 'EXCHANGE STOP')) { - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'STOP LIMIT') || (orderType === 'EXCHANGE STOP LIMIT')) { - const priceAuxLimit = this.safeFloat (params, 'price_aux_limit'); - let stopPrice = this.safeFloat (params, 'stopPrice'); + const priceAuxLimit = this.safeNumber (params, 'price_aux_limit'); + let stopPrice = this.safeNumber (params, 'stopPrice'); if (priceAuxLimit === undefined) { if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter or a price_aux_limit parameter for a ' + orderType + ' order'); @@ -16604,9 +18479,9 @@ module.exports = class bitfinex2 extends bitfinex { } request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'TRAILING STOP') || (orderType === 'EXCHANGE TRAILING STOP')) { - const priceTrailing = this.safeFloat (params, 'price_trailing'); + const priceTrailing = this.safeNumber (params, 'price_trailing'); request['price_trailing'] = this.numberToString (priceTrailing); - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'FOK') || (orderType === 'EXCHANGE FOK') || (orderType === 'IOC') || (orderType === 'EXCHANGE IOC')) { request['price'] = this.numberToString (price); @@ -16938,11 +18813,11 @@ module.exports = class bitfinex2 extends bitfinex { if (currency !== undefined) { code = currency['code']; } - feeCost = this.safeFloat (data, 8); + feeCost = this.safeNumber (data, 8); if (feeCost !== undefined) { feeCost = -feeCost; } - amount = this.safeFloat (data, 5); + amount = this.safeNumber (data, 5); id = this.safeValue (data, 0); status = 'ok'; if (id === 0) { @@ -16956,7 +18831,7 @@ module.exports = class bitfinex2 extends bitfinex { timestamp = this.safeInteger (transaction, 5); updated = this.safeInteger (transaction, 6); status = this.parseTransactionStatus (this.safeString (transaction, 9)); - amount = this.safeFloat (transaction, 12); + amount = this.safeNumber (transaction, 12); if (amount !== undefined) { if (amount < 0) { type = 'withdrawal'; @@ -16964,7 +18839,7 @@ module.exports = class bitfinex2 extends bitfinex { type = 'deposit'; } } - feeCost = this.safeFloat (transaction, 13); + feeCost = this.safeNumber (transaction, 13); if (feeCost !== undefined) { feeCost = -feeCost; } @@ -17092,7 +18967,7 @@ module.exports = class bitfinex2 extends bitfinex { }); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // @@ -17197,13 +19072,14 @@ module.exports = class bitfinex2 extends bitfinex { } }; -},{"./base/errors":8,"./bitfinex.js":29}],31:[function(require,module,exports){ +},{"./base/errors":9,"./bitfinex.js":30}],32:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -17385,11 +19261,11 @@ module.exports = class bitflyer extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'amount'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -17408,16 +19284,16 @@ module.exports = class bitflyer extends Exchange { }; const ticker = await this.publicGetGetticker (this.extend (request, params)); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'ltp'); + const last = this.safeNumber (ticker, 'ltp'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'best_bid'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -17427,7 +19303,7 @@ module.exports = class bitflyer extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_by_product'), + 'baseVolume': this.safeNumber (ticker, 'volume_by_product'), 'quoteVolume': undefined, 'info': ticker, }; @@ -17451,14 +19327,11 @@ module.exports = class bitflyer extends Exchange { order = this.safeString (trade, 'child_order_acceptance_id'); } const timestamp = this.parse8601 (this.safeString (trade, 'exec_date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -17534,18 +19407,17 @@ module.exports = class bitflyer extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'child_order_date')); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'outstanding_size'); - const filled = this.safeFloat (order, 'executed_size'); - const price = this.safeFloat (order, 'price'); - const cost = price * filled; + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'outstanding_size'); + const filled = this.safeNumber (order, 'executed_size'); + const price = this.safeNumber (order, 'price'); const status = this.parseOrderStatus (this.safeString (order, 'child_order_state')); const type = this.safeStringLower (order, 'child_order_type'); const side = this.safeStringLower (order, 'side'); const marketId = this.safeString (order, 'product_code'); const symbol = this.safeSymbol (marketId, market); let fee = undefined; - const feeCost = this.safeFloat (order, 'total_commission'); + const feeCost = this.safeNumber (order, 'total_commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -17554,7 +19426,7 @@ module.exports = class bitflyer extends Exchange { }; } const id = this.safeString (order, 'child_order_acceptance_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -17569,14 +19441,14 @@ module.exports = class bitflyer extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrders (symbol = undefined, since = undefined, limit = 100, params = {}) { @@ -17639,7 +19511,7 @@ module.exports = class bitflyer extends Exchange { return this.parseTrades (response, market, since, limit); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { if (symbols === undefined) { throw new ArgumentsRequired (this.id + ' fetchPositions() requires a `symbols` argument, exactly one symbol in an array'); } @@ -17723,13 +19595,14 @@ module.exports = class bitflyer extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],32:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],33:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, DDoSProtection, PermissionDenied, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -17985,7 +19858,7 @@ module.exports = class bitforex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -18021,14 +19894,11 @@ module.exports = class bitforex extends Exchange { const timestamp = this.safeInteger (trade, 'time'); const id = this.safeString (trade, 'tid'); const orderId = undefined; - const amount = this.safeFloat (trade, 'amount'); - const price = this.safeFloat (trade, 'price'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const sideId = this.safeInteger (trade, 'direction'); const side = this.parseSide (sideId); return { @@ -18071,12 +19941,12 @@ module.exports = class bitforex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'active'); - account['total'] = this.safeFloat (balance, 'fix'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'active'); + account['total'] = this.safeString (balance, 'fix'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTicker (symbol, params = {}) { @@ -18092,21 +19962,21 @@ module.exports = class bitforex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (data, 'high'), - 'low': this.safeFloat (data, 'low'), - 'bid': this.safeFloat (data, 'buy'), + 'high': this.safeNumber (data, 'high'), + 'low': this.safeNumber (data, 'low'), + 'bid': this.safeNumber (data, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (data, 'sell'), + 'ask': this.safeNumber (data, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (data, 'last'), - 'last': this.safeFloat (data, 'last'), + 'close': this.safeNumber (data, 'last'), + 'last': this.safeNumber (data, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (data, 'vol'), + 'baseVolume': this.safeNumber (data, 'vol'), 'quoteVolume': undefined, 'info': response, }; @@ -18126,11 +19996,11 @@ module.exports = class bitforex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -18198,26 +20068,24 @@ module.exports = class bitforex extends Exchange { parseOrder (order, market = undefined) { const id = this.safeString (order, 'orderId'); - const timestamp = this.safeFloat (order, 'createTime'); - const lastTradeTimestamp = this.safeFloat (order, 'lastTime'); + const timestamp = this.safeNumber (order, 'createTime'); + const lastTradeTimestamp = this.safeNumber (order, 'lastTime'); const symbol = market['symbol']; const sideId = this.safeInteger (order, 'tradeType'); const side = this.parseSide (sideId); const type = undefined; - const price = this.safeFloat (order, 'orderPrice'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderAmount'); - const filled = this.safeFloat (order, 'dealAmount'); - const remaining = amount - filled; + const price = this.safeNumber (order, 'orderPrice'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderAmount'); + const filled = this.safeNumber (order, 'dealAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderState')); - const cost = filled * price; const feeSide = (side === 'buy') ? 'base' : 'quote'; const feeCurrency = market[feeSide]; const fee = { - 'cost': this.safeFloat (order, 'tradeFee'), + 'cost': this.safeNumber (order, 'tradeFee'), 'currency': feeCurrency, }; - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -18231,16 +20099,15 @@ module.exports = class bitforex extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -18356,7 +20223,7 @@ module.exports = class bitforex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],33:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],34:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -18364,6 +20231,7 @@ module.exports = class bitforex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -19152,7 +21020,7 @@ module.exports = class bitget extends Exchange { let swap = false; const baseId = this.safeString2 (market, 'base_currency', 'coin'); const quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { marketType = 'swap'; spot = false; @@ -19170,7 +21038,7 @@ module.exports = class bitget extends Exchange { 'amount': parseFloat ('1e-' + sizeIncrement), 'price': parseFloat ('1e-' + tickSize), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const status = this.safeString (market, 'status'); let active = undefined; if (status !== undefined) { @@ -19427,26 +21295,26 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat2 (ticker, 'last', 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'last', 'close'); + const open = this.safeNumber (ticker, 'open'); let bidVolume = undefined; let askVolume = undefined; let bid = this.safeValue (ticker, 'bid'); if (bid === undefined) { - bid = this.safeFloat (ticker, 'best_bid'); + bid = this.safeNumber (ticker, 'best_bid'); } else { - bidVolume = this.safeFloat (bid, 1); - bid = this.safeFloat (bid, 0); + bidVolume = this.safeNumber (bid, 1); + bid = this.safeNumber (bid, 0); } let ask = this.safeValue (ticker, 'ask'); if (ask === undefined) { - ask = this.safeFloat (ticker, 'best_ask'); + ask = this.safeNumber (ticker, 'best_ask'); } else { - askVolume = this.safeFloat (ask, 1); - ask = this.safeFloat (ask, 0); + askVolume = this.safeNumber (ask, 1); + ask = this.safeNumber (ask, 0); } - const baseVolume = this.safeFloat2 (ticker, 'amount', 'volume_24h'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber2 (ticker, 'amount', 'volume_24h'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; @@ -19460,8 +21328,8 @@ module.exports = class bitget extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -19696,9 +21564,12 @@ module.exports = class bitget extends Exchange { } let timestamp = this.safeInteger (trade, 'created_at'); timestamp = this.safeInteger2 (trade, 'timestamp', 'ts', timestamp); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'filled_amount', 'order_qty'); - amount = this.safeFloat2 (trade, 'size', 'amount', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'filled_amount', 'order_qty'); + amountString = this.safeString2 (trade, 'size', 'amount', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -19717,18 +21588,13 @@ module.exports = class bitget extends Exchange { type = this.parseOrderType (side); side = this.parseOrderSide (side); } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - let feeCost = this.safeFloat (trade, 'fee'); - if (feeCost === undefined) { - feeCost = this.safeFloat (trade, 'filled_fees'); + let feeCostString = this.safeString (trade, 'fee'); + if (feeCostString === undefined) { + feeCostString = this.safeString (trade, 'filled_fees'); } else { - feeCost = -feeCost; + feeCostString = (feeCostString[0] === '-') ? feeCostString.slice (1) : feeCostString; } + const feeCost = this.parseNumber (feeCostString); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -19851,23 +21717,23 @@ module.exports = class bitget extends Exchange { const volumeIndex = this.safeString (volume, market['type'], 'amount'); return [ this.safeInteger (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets ]; } else { const volumeIndex = this.safeValue (volume, market['type'], 6); return [ this.safeInteger (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, volumeIndex), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, volumeIndex), // Base Volume ]; } } @@ -19969,13 +21835,13 @@ module.exports = class bitget extends Exchange { } const type = this.safeValue (balance, 'type'); if (type === 'trade') { - result[code]['free'] = this.safeFloat (balance, 'balance'); + result[code]['free'] = this.safeString (balance, 'balance'); } else if ((type === 'frozen') || (type === 'lock')) { - const used = this.safeFloat (result[code], 'used'); - result[code]['used'] = this.sum (used, this.safeFloat (balance, 'balance')); + const used = this.safeString (result[code], 'used'); + result[code]['used'] = Precise.stringAdd (used, this.safeString (balance, 'balance')); } } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseSwapBalance (response) { @@ -19999,11 +21865,11 @@ module.exports = class bitget extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeString (balance, 'equity'); + account['free'] = this.safeString (balance, 'total_avail_balance'); result[symbol] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchAccounts (params = {}) { @@ -20280,26 +22146,13 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let amount = this.safeFloat2 (order, 'amount', 'size'); - const filled = this.safeFloat2 (order, 'filled_amount', 'filled_qty'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - amount = Math.max (amount, filled); - remaining = Math.max (0, amount - filled); - } - } - if (type === 'market') { - remaining = 0; - } - const cost = this.safeFloat (order, 'filled_cash_amount'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); - if ((average === undefined) && (filled !== undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } + const amount = this.safeNumber2 (order, 'amount', 'size'); + const filled = this.safeNumber2 (order, 'filled_amount', 'filled_qty'); + const cost = this.safeNumber (order, 'filled_cash_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'price_avg'); const status = this.parseOrderStatus (this.safeString2 (order, 'state', 'status')); - const feeCost = this.safeFloat2 (order, 'filled_fees', 'fee'); + const feeCost = this.safeNumber2 (order, 'filled_fees', 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -20309,7 +22162,7 @@ module.exports = class bitget extends Exchange { }; } const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -20327,11 +22180,11 @@ module.exports = class bitget extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -20378,7 +22231,7 @@ module.exports = class bitget extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'amount'); + let cost = this.safeNumber (params, 'amount'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -20928,12 +22781,12 @@ module.exports = class bitget extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const txid = this.safeString (transaction, 'tx_hash'); const timestamp = this.safeInteger (transaction, 'created_at'); const updated = this.safeInteger (transaction, 'updated_at'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -21123,7 +22976,7 @@ module.exports = class bitget extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.swapGetPositionAllPosition (params); // @@ -21264,7 +23117,7 @@ module.exports = class bitget extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],34:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],35:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -21272,6 +23125,7 @@ module.exports = class bitget extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, AuthenticationError, BadRequest, PermissionDenied, InvalidAddress, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); const { DECIMAL_PLACES, SIGNIFICANT_DIGITS, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -21465,12 +23319,12 @@ module.exports = class bithumb extends Exchange { const account = this.account (); const currency = this.currency (code); const lowerCurrencyId = this.safeStringLower (currency, 'id'); - account['total'] = this.safeFloat (balances, 'total_' + lowerCurrencyId); - account['used'] = this.safeFloat (balances, 'in_use_' + lowerCurrencyId); - account['free'] = this.safeFloat (balances, 'available_' + lowerCurrencyId); + account['total'] = this.safeString (balances, 'total_' + lowerCurrencyId); + account['used'] = this.safeString (balances, 'in_use_' + lowerCurrencyId); + account['free'] = this.safeString (balances, 'available_' + lowerCurrencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -21532,8 +23386,8 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'opening_price'); - const close = this.safeFloat (ticker, 'closing_price'); + const open = this.safeNumber (ticker, 'opening_price'); + const close = this.safeNumber (ticker, 'closing_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -21544,18 +23398,18 @@ module.exports = class bithumb extends Exchange { } average = this.sum (open, close) / 2; } - const baseVolume = this.safeFloat (ticker, 'units_traded_24H'); - const quoteVolume = this.safeFloat (ticker, 'acc_trade_value_24H'); + const baseVolume = this.safeNumber (ticker, 'units_traded_24H'); + const quoteVolume = this.safeNumber (ticker, 'acc_trade_value_24H'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -21661,11 +23515,11 @@ module.exports = class bithumb extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -21755,18 +23609,16 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'units_traded', 'units'); - let cost = this.safeFloat (trade, 'total'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'units_traded', 'units'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.commonCurrencyCode (feeCurrencyId); @@ -21969,14 +23821,14 @@ module.exports = class bithumb extends Exchange { const sideProperty = this.safeValue2 (order, 'type', 'side'); const side = (sideProperty === 'bid') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'order_status')); - let price = this.safeFloat2 (order, 'order_price', 'price'); + let price = this.safeNumber2 (order, 'order_price', 'price'); let type = 'limit'; if (price === 0) { price = undefined; type = 'market'; } - const amount = this.safeFloat2 (order, 'order_qty', 'units'); - let remaining = this.safeFloat (order, 'units_remaining'); + const amount = this.safeNumber2 (order, 'order_qty', 'units'); + let remaining = this.safeNumber (order, 'units_remaining'); if (remaining === undefined) { if (status === 'closed') { remaining = 0; @@ -21995,65 +23847,14 @@ module.exports = class bithumb extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let filled = undefined; - let cost = undefined; - let average = undefined; const id = this.safeString (order, 'order_id'); - const rawTrades = this.safeValue (order, 'contract'); - let trades = undefined; - let fee = undefined; - let fees = undefined; - let feesByCurrency = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'side': side, - 'symbol': symbol, - 'order': id, - }); - filled = 0; - feesByCurrency = {}; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - filled = this.sum (filled, trade['amount']); - cost = this.sum (cost, trade['cost']); - const tradeFee = trade['fee']; - const feeCurrency = tradeFee['currency']; - if (feeCurrency in feesByCurrency) { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': this.sum (feesByCurrency[feeCurrency]['cost'], tradeFee['cost']), - }; - } else { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': tradeFee['cost'], - }; - } - } - const feeCurrencies = Object.keys (feesByCurrency); - const feeCurrenciesLength = feeCurrencies.length; - if (feeCurrenciesLength > 1) { - fees = []; - for (let i = 0; i < feeCurrencies.length; i++) { - const feeCurrency = feeCurrencies[i]; - fees.push (feesByCurrency[feeCurrency]); - } - } else { - fee = this.safeValue (feesByCurrency, feeCurrencies[0]); - } - if (filled !== 0) { - average = cost / filled; - } - } - if (amount !== undefined) { - if ((filled === undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if ((remaining === undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const result = { + const rawTrades = this.safeValue (order, 'contract', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'side': side, + 'symbol': symbol, + 'order': id, + }); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -22068,20 +23869,14 @@ module.exports = class bithumb extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, + 'cost': undefined, + 'average': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': trades, - }; - if (fee !== undefined) { - result['fee'] = fee; - } else if (fees !== undefined) { - result['fees'] = fees; - } - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -22241,7 +24036,7 @@ module.exports = class bithumb extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],35:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],36:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -22272,7 +24067,7 @@ module.exports = class bitkk extends zb { } }; -},{"./zb.js":182}],36:[function(require,module,exports){ +},{"./zb.js":178}],37:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -22710,16 +24505,16 @@ module.exports = class bitmart extends Exchange { // const pricePrecision = this.safeInteger (market, 'price_max_precision'); const precision = { - 'amount': this.safeFloat (market, 'base_min_size'), + 'amount': this.safeNumber (market, 'base_min_size'), 'price': parseFloat (this.decimalToPrecision (Math.pow (10, -pricePrecision), ROUND, 10)), }; - const minBuyCost = this.safeFloat (market, 'min_buy_amount'); - const minSellCost = this.safeFloat (market, 'min_sell_amount'); + const minBuyCost = this.safeNumber (market, 'min_buy_amount'); + const minSellCost = this.safeNumber (market, 'min_sell_amount'); const minCost = Math.max (minBuyCost, minSellCost); const limits = { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': { 'min': undefined, @@ -22829,16 +24624,16 @@ module.exports = class bitmart extends Exchange { // // the docs are wrong: https://github.com/ccxt/ccxt/issues/5612 // - const amountPrecision = this.safeFloat (contract, 'vol_unit'); - const pricePrecision = this.safeFloat (contract, 'price_unit'); + const amountPrecision = this.safeNumber (contract, 'vol_unit'); + const pricePrecision = this.safeNumber (contract, 'price_unit'); const precision = { 'amount': amountPrecision, 'price': pricePrecision, }; const limits = { 'amount': { - 'min': this.safeFloat (contract, 'min_vol'), - 'max': this.safeFloat (contract, 'max_vol'), + 'min': this.safeNumber (contract, 'min_vol'), + 'max': this.safeNumber (contract, 'max_vol'), }, 'price': { 'min': undefined, @@ -22861,8 +24656,8 @@ module.exports = class bitmart extends Exchange { future = true; } const feeConfig = this.safeValue (market, 'fee_config', {}); - const maker = this.safeFloat (feeConfig, 'maker_fee'); - const taker = this.safeFloat (feeConfig, 'taker_fee'); + const maker = this.safeNumber (feeConfig, 'maker_fee'); + const taker = this.safeNumber (feeConfig, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -22950,33 +24745,33 @@ module.exports = class bitmart extends Exchange { const timestamp = this.safeTimestamp (ticker, 'timestamp', this.milliseconds ()); const marketId = this.safeString2 (ticker, 'symbol', 'contract_id'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat2 (ticker, 'close_24h', 'last_price'); - let percentage = this.safeFloat (ticker, 'fluctuation', 'rise_fall_rate'); + const last = this.safeNumber2 (ticker, 'close_24h', 'last_price'); + let percentage = this.safeNumber (ticker, 'fluctuation', 'rise_fall_rate'); if (percentage !== undefined) { percentage *= 100; } - const baseVolume = this.safeFloat2 (ticker, 'base_volume_24h', 'base_coin_volume'); - const quoteVolume = this.safeFloat2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); + const baseVolume = this.safeNumber2 (ticker, 'base_volume_24h', 'base_coin_volume'); + const quoteVolume = this.safeNumber2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const open = this.safeFloat2 (ticker, 'open_24h', 'open'); + const open = this.safeNumber2 (ticker, 'open_24h', 'open'); let average = undefined; if ((last !== undefined) && (open !== undefined)) { average = this.sum (last, open) / 2; } - average = this.safeFloat (ticker, 'avg_price', average); + average = this.safeNumber (ticker, 'avg_price', average); const price = this.safeValue (ticker, 'depth_price', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), - 'bid': this.safeFloat (price, 'best_bid', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (price, 'best_ask', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), + 'bid': this.safeNumber (price, 'best_bid', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (price, 'best_ask', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open_24h'), + 'open': this.safeNumber (ticker, 'open_24h'), 'close': last, 'last': last, 'previousClose': undefined, @@ -23280,18 +25075,18 @@ module.exports = class bitmart extends Exchange { if (execType !== undefined) { takerOrMaker = (execType === 'M') ? 'maker' : 'taker'; } - let price = this.safeFloat2 (trade, 'price', 'deal_price'); - price = this.safeFloat (trade, 'price_avg', price); - let amount = this.safeFloat2 (trade, 'amount', 'deal_vol'); - amount = this.safeFloat (trade, 'size', amount); - let cost = this.safeFloat2 (trade, 'count', 'notional'); + let price = this.safeNumber2 (trade, 'price', 'deal_price'); + price = this.safeNumber (trade, 'price_avg', price); + let amount = this.safeNumber2 (trade, 'amount', 'deal_vol'); + amount = this.safeNumber (trade, 'size', amount); + let cost = this.safeNumber2 (trade, 'count', 'notional'); if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { cost = amount * price; } const orderId = this.safeInteger (trade, 'order_id'); const marketId = this.safeString2 (trade, 'contract_id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (trade, 'fees'); + const feeCost = this.safeNumber (trade, 'fees'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_coin_name'); @@ -23419,11 +25214,11 @@ module.exports = class bitmart extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -23750,11 +25545,11 @@ module.exports = class bitmart extends Exchange { currencyId = this.safeString (balance, 'coind_code', currencyId); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat2 (balance, 'available', 'available_vol'); - account['used'] = this.safeFloat2 (balance, 'frozen', 'freeze_vol'); + account['free'] = this.safeString2 (balance, 'available', 'available_vol'); + account['used'] = this.safeString2 (balance, 'frozen', 'freeze_vol'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -23823,29 +25618,10 @@ module.exports = class bitmart extends Exchange { if (market !== undefined) { status = this.parseOrderStatusByType (market['type'], this.safeString (order, 'status')); } - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat2 (order, 'price_avg', 'done_avg_price'); - const amount = this.safeFloat2 (order, 'size', 'vol'); - let cost = undefined; - let filled = this.safeFloat2 (order, 'filled_size', 'done_vol'); - let remaining = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - if (filled === undefined) { - filled = Math.max (0, amount - remaining); - } - } - if (filled !== undefined) { - if (remaining === undefined) { - remaining = Math.max (0, amount - filled); - } - if (cost === undefined) { - if (average !== undefined) { - cost = average * filled; - } - } - } - } + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber2 (order, 'price_avg', 'done_avg_price'); + const amount = this.safeNumber2 (order, 'size', 'vol'); + const filled = this.safeNumber2 (order, 'filled_size', 'done_vol'); let side = this.safeString (order, 'side'); // 1 = Open long // 2 = Close short @@ -23867,7 +25643,7 @@ module.exports = class bitmart extends Exchange { average = undefined; } } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -23882,14 +25658,14 @@ module.exports = class bitmart extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatusByType (type, status) { @@ -23930,7 +25706,7 @@ module.exports = class bitmart extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -24516,12 +26292,12 @@ module.exports = class bitmart extends Exchange { type = 'deposit'; id = depositId; } - const amount = this.safeFloat (transaction, 'arrival_amount'); + const amount = this.safeNumber (transaction, 'arrival_amount'); const timestamp = this.safeInteger (transaction, 'tapply_timeime'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -24637,1735 +26413,7 @@ module.exports = class bitmart extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],37:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); - -// --------------------------------------------------------------------------- - -module.exports = class bitmax extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'bitmax', - 'name': 'BitMax', - 'countries': [ 'CN' ], // China - 'rateLimit': 500, - // new metainfo interface - 'has': { - 'CORS': false, - 'fetchMarkets': true, - 'fetchCurrencies': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchOHLCV': true, - 'fetchTrades': true, - 'fetchAccounts': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'cancelAllOrders': true, - 'fetchDepositAddress': true, - 'fetchTransactions': true, - 'fetchDeposits': true, - 'fetchWithdrawals': true, - 'fetchOrder': true, - 'fetchOrders': true, - 'fetchOpenOrders': true, - 'fetchClosedOrders': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '6h': '360', - '12h': '720', - '1d': '1d', - '1w': '1w', - '1M': '1m', - }, - 'version': 'v1', - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg', - 'api': 'https://bitmax.io', - 'test': 'https://bitmax-test.io', - 'www': 'https://bitmax.io', - 'doc': [ - 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', - ], - 'fees': 'https://bitmax.io/#/feeRate/tradeRate', - 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', - }, - 'api': { - 'public': { - 'get': [ - 'assets', - 'products', - 'ticker', - 'barhist/info', - 'barhist', - 'depth', - 'trades', - 'cash/assets', // not documented - 'cash/products', // not documented - 'margin/assets', // not documented - 'margin/products', // not documented - 'futures/collateral', - 'futures/contracts', - 'futures/ref-px', - 'futures/market-data', - 'futures/funding-rates', - ], - }, - 'accountCategory': { - 'get': [ - 'balance', - 'order/open', - 'order/status', - 'order/hist/current', - 'risk', - ], - 'post': [ - 'order', - 'order/batch', - ], - 'delete': [ - 'order', - 'order/all', - 'order/batch', - ], - }, - 'accountGroup': { - 'get': [ - 'cash/balance', - 'margin/balance', - 'margin/risk', - 'transfer', - 'futures/collateral-balance', - 'futures/position', - 'futures/risk', - 'futures/funding-payments', - 'order/hist', - ], - 'post': [ - 'futures/transfer/deposit', - 'futures/transfer/withdraw', - ], - }, - 'private': { - 'get': [ - 'info', - 'wallet/transactions', - 'wallet/deposit/address', // not documented - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'taker': 0.002, - 'maker': 0.002, - }, - }, - 'precisionMode': TICK_SIZE, - 'options': { - 'account-category': 'cash', // 'cash'/'margin'/'futures' - 'account-group': undefined, - 'fetchClosedOrders': { - 'method': 'accountGroupGetOrderHist', // 'accountGroupGetAccountCategoryOrderHistCurrent' - }, - }, - 'exceptions': { - 'exact': { - // not documented - '1900': BadRequest, // {"code":1900,"message":"Invalid Http Request Input"} - '2100': AuthenticationError, // {"code":2100,"message":"ApiKeyFailure"} - '5002': BadSymbol, // {"code":5002,"message":"Invalid Symbol"} - '6001': BadSymbol, // {"code":6001,"message":"Trading is disabled on symbol."} - '6010': InsufficientFunds, // {'code': 6010, 'message': 'Not enough balance.'} - '60060': InvalidOrder, // { 'code': 60060, 'message': 'The order is already filled or canceled.' } - '600503': InvalidOrder, // {"code":600503,"message":"Notional is too small."} - // documented - '100001': BadRequest, // INVALID_HTTP_INPUT Http request is invalid - '100002': BadRequest, // DATA_NOT_AVAILABLE Some required data is missing - '100003': BadRequest, // KEY_CONFLICT The same key exists already - '100004': BadRequest, // INVALID_REQUEST_DATA The HTTP request contains invalid field or argument - '100005': BadRequest, // INVALID_WS_REQUEST_DATA Websocket request contains invalid field or argument - '100006': BadRequest, // INVALID_ARGUMENT The arugment is invalid - '100007': BadRequest, // ENCRYPTION_ERROR Something wrong with data encryption - '100008': BadSymbol, // SYMBOL_ERROR Symbol does not exist or not valid for the request - '100009': AuthenticationError, // AUTHORIZATION_NEEDED Authorization is require for the API access or request - '100010': BadRequest, // INVALID_OPERATION The action is invalid or not allowed for the account - '100011': BadRequest, // INVALID_TIMESTAMP Not a valid timestamp - '100012': BadRequest, // INVALID_STR_FORMAT String format does not - '100013': BadRequest, // INVALID_NUM_FORMAT Invalid number input - '100101': ExchangeError, // UNKNOWN_ERROR Some unknown error - '150001': BadRequest, // INVALID_JSON_FORMAT Require a valid json object - '200001': AuthenticationError, // AUTHENTICATION_FAILED Authorization failed - '200002': ExchangeError, // TOO_MANY_ATTEMPTS Tried and failed too many times - '200003': ExchangeError, // ACCOUNT_NOT_FOUND Account not exist - '200004': ExchangeError, // ACCOUNT_NOT_SETUP Account not setup properly - '200005': ExchangeError, // ACCOUNT_ALREADY_EXIST Account already exist - '200006': ExchangeError, // ACCOUNT_ERROR Some error related with error - '200007': ExchangeError, // CODE_NOT_FOUND - '200008': ExchangeError, // CODE_EXPIRED Code expired - '200009': ExchangeError, // CODE_MISMATCH Code does not match - '200010': AuthenticationError, // PASSWORD_ERROR Wrong assword - '200011': ExchangeError, // CODE_GEN_FAILED Do not generate required code promptly - '200012': ExchangeError, // FAKE_COKE_VERIFY - '200013': ExchangeError, // SECURITY_ALERT Provide security alert message - '200014': PermissionDenied, // RESTRICTED_ACCOUNT Account is restricted for certain activity, such as trading, or withdraw. - '200015': PermissionDenied, // PERMISSION_DENIED No enough permission for the operation - '300001': InvalidOrder, // INVALID_PRICE Order price is invalid - '300002': InvalidOrder, // INVALID_QTY Order size is invalid - '300003': InvalidOrder, // INVALID_SIDE Order side is invalid - '300004': InvalidOrder, // INVALID_NOTIONAL Notional is too small or too large - '300005': InvalidOrder, // INVALID_TYPE Order typs is invalid - '300006': InvalidOrder, // INVALID_ORDER_ID Order id is invalid - '300007': InvalidOrder, // INVALID_TIME_IN_FORCE Time In Force in order request is invalid - '300008': InvalidOrder, // INVALID_ORDER_PARAMETER Some order parameter is invalid - '300009': InvalidOrder, // TRADING_VIOLATION Trading violation on account or asset - '300011': InsufficientFunds, // INVALID_BALANCE No enough account or asset balance for the trading - '300012': BadSymbol, // INVALID_PRODUCT Not a valid product supported by exchange - '300013': InvalidOrder, // INVALID_BATCH_ORDER Some or all orders are invalid in batch order request - '300020': InvalidOrder, // TRADING_RESTRICTED There is some trading restriction on account or asset - '300021': InvalidOrder, // TRADING_DISABLED Trading is disabled on account or asset - '300031': InvalidOrder, // NO_MARKET_PRICE No market price for market type order trading - '310001': InsufficientFunds, // INVALID_MARGIN_BALANCE No enough margin balance - '310002': InvalidOrder, // INVALID_MARGIN_ACCOUNT Not a valid account for margin trading - '310003': InvalidOrder, // MARGIN_TOO_RISKY Leverage is too high - '310004': BadSymbol, // INVALID_MARGIN_ASSET This asset does not support margin trading - '310005': InvalidOrder, // INVALID_REFERENCE_PRICE There is no valid reference price - '510001': ExchangeError, // SERVER_ERROR Something wrong with server. - '900001': ExchangeError, // HUMAN_CHALLENGE Human change do not pass - }, - 'broad': {}, - }, - 'commonCurrencies': { - 'BTCBEAR': 'BEAR', - 'BTCBULL': 'BULL', - }, - }); - } - - getAccount (params = {}) { - // get current or provided bitmax sub-account - const account = this.safeValue (params, 'account', this.options['account']); - return account.toLowerCase ().capitalize (); - } - - async fetchCurrencies (params = {}) { - const assets = await this.publicGetAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode" : "LTCBULL", - // "assetName" : "3X Long LTC Token", - // "precisionScale" : 9, - // "nativeScale" : 4, - // "withdrawalFee" : "0.2", - // "minWithdrawalAmt" : "1.0", - // "status" : "Normal" - // }, - // ] - // } - // - const margin = await this.publicGetMarginAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode":"BTT", - // "borrowAssetCode":"BTT-B", - // "interestAssetCode":"BTT-I", - // "nativeScale":0, - // "numConfirmations":1, - // "withdrawFee":"100.0", - // "minWithdrawalAmt":"1000.0", - // "statusCode":"Normal", - // "statusMessage":"", - // "interestRate":"0.001" - // } - // ] - // } - // - const cash = await this.publicGetCashAssets (params); - // - // { - // "code":0, - // "data":[ - // { - // "assetCode":"LTCBULL", - // "nativeScale":4, - // "numConfirmations":20, - // "withdrawFee":"0.2", - // "minWithdrawalAmt":"1.0", - // "statusCode":"Normal", - // "statusMessage":"" - // } - // ] - // } - // - const assetsData = this.safeValue (assets, 'data', []); - const marginData = this.safeValue (margin, 'data', []); - const cashData = this.safeValue (cash, 'data', []); - const assetsById = this.indexBy (assetsData, 'assetCode'); - const marginById = this.indexBy (marginData, 'assetCode'); - const cashById = this.indexBy (cashData, 'assetCode'); - const dataById = this.deepExtend (assetsById, marginById, cashById); - const ids = Object.keys (dataById); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const currency = dataById[id]; - const code = this.safeCurrencyCode (id); - const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); - // why would the exchange API have different names for the same field - const fee = this.safeFloat2 (currency, 'withdrawFee', 'withdrawalFee'); - const status = this.safeString2 (currency, 'status', 'statusCode'); - const active = (status === 'Normal'); - const margin = ('borrowAssetCode' in currency); - result[code] = { - 'id': id, - 'code': code, - 'info': currency, - 'type': undefined, - 'margin': margin, - 'name': this.safeString (currency, 'assetName'), - 'active': active, - 'fee': fee, - 'precision': precision, - 'limits': { - 'amount': { - 'min': Math.pow (10, -precision), - 'max': undefined, - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': undefined, - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawalAmt'), - 'max': undefined, - }, - }, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - const products = await this.publicGetProducts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"LBA/BTC", - // "baseAsset":"LBA", - // "quoteAsset":"BTC", - // "status":"Normal", - // "minNotional":"0.000625", - // "maxNotional":"6.25", - // "marginTradable":false, - // "commissionType":"Quote", - // "commissionReserveRate":"0.001", - // "tickSize":"0.000000001", - // "lotSize":"1" - // }, - // ] - // } - // - const cash = await this.publicGetCashProducts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"QTUM/BTC", - // "domain":"BTC", - // "tradingStartTime":1569506400000, - // "collapseDecimals":"0.0001,0.000001,0.00000001", - // "minQty":"0.000000001", - // "maxQty":"1000000000", - // "minNotional":"0.000625", - // "maxNotional":"12.5", - // "statusCode":"Normal", - // "statusMessage":"", - // "tickSize":"0.00000001", - // "useTick":false, - // "lotSize":"0.1", - // "useLot":false, - // "commissionType":"Quote", - // "commissionReserveRate":"0.001", - // "qtyScale":1, - // "priceScale":8, - // "notionalScale":4 - // } - // ] - // } - // - const futures = await this.publicGetFuturesContracts (params); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"BTC-PERP", - // "tradingStartTime":1579701600000, - // "collapseDecimals":"1,0.1,0.01", - // "minQty":"0.000000001", - // "maxQty":"1000000000", - // "minNotional":"5", - // "maxNotional":"1000000", - // "statusCode":"Normal", - // "statusMessage":"", - // "tickSize":"0.25", - // "lotSize":"0.0001", - // "priceScale":2, - // "qtyScale":4, - // "notionalScale":2 - // } - // ] - // } - // - const productsData = this.safeValue (products, 'data', []); - const productsById = this.indexBy (productsData, 'symbol'); - const cashData = this.safeValue (cash, 'data', []); - const futuresData = this.safeValue (futures, 'data', []); - const cashAndFuturesData = this.arrayConcat (cashData, futuresData); - const cashAndFuturesById = this.indexBy (cashAndFuturesData, 'symbol'); - const dataById = this.deepExtend (productsById, cashAndFuturesById); - const ids = Object.keys (dataById); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const market = dataById[id]; - const baseId = this.safeString (market, 'baseAsset'); - const quoteId = this.safeString (market, 'quoteAsset'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), - }; - const status = this.safeString (market, 'status'); - const active = (status === 'Normal'); - const type = ('useLot' in market) ? 'spot' : 'future'; - const spot = (type === 'spot'); - const future = (type === 'future'); - let symbol = id; - if (!future) { - symbol = base + '/' + quote; - } - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'type': type, - 'spot': spot, - 'future': future, - 'active': active, - 'precision': precision, - 'limits': { - 'amount': { - 'min': this.safeFloat (market, 'minQty'), - 'max': this.safeFloat (market, 'maxQty'), - }, - 'price': { - 'min': this.safeFloat (market, 'tickSize'), - 'max': undefined, - }, - 'cost': { - 'min': this.safeFloat (market, 'minNotional'), - 'max': this.safeFloat (market, 'maxNotional'), - }, - }, - }); - } - return result; - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - // TODO: fee calculation here is incorrect, we need to support tiered fee calculation. - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - - async fetchAccounts (params = {}) { - let accountGroup = this.safeString (this.options, 'account-group'); - let response = undefined; - if (accountGroup === undefined) { - response = await this.privateGetInfo (params); - // - // { - // "code":0, - // "data":{ - // "email":"igor.kroitor@gmail.com", - // "accountGroup":8, - // "viewPermission":true, - // "tradePermission":true, - // "transferPermission":true, - // "cashAccount":["cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda"], - // "marginAccount":["martXoh1v1N3EMQC5FDtSj5VHso8aI2Z"], - // "futuresAccount":["futc9r7UmFJAyBY2rE3beA2JFxav2XFF"], - // "userUID":"U6491137460" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - accountGroup = this.safeString (data, 'accountGroup'); - this.options['account-group'] = accountGroup; - } - return [ - { - 'id': accountGroup, - 'type': undefined, - 'currency': undefined, - 'info': response, - }, - ]; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchBalance', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeString (account, 'id'); - const request = { - 'account-group': accountGroup, - }; - let method = 'accountCategoryGetBalance'; - if (accountCategory === 'futures') { - method = 'accountGroupGetFuturesCollateralBalance'; - } else { - request['account-category'] = accountCategory; - } - const response = await this[method] (this.extend (request, params)); - // - // cash - // - // { - // 'code': 0, - // 'data': [ - // { - // 'asset': 'BCHSV', - // 'totalBalance': '64.298000048', - // 'availableBalance': '64.298000048', - // }, - // ] - // } - // - // margin - // - // { - // 'code': 0, - // 'data': [ - // { - // 'asset': 'BCHSV', - // 'totalBalance': '64.298000048', - // 'availableBalance': '64.298000048', - // 'borrowed': '0', - // 'interest': '0', - // }, - // ] - // } - // - // futures - // - // { - // "code":0, - // "data":[ - // {"asset":"BTC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"9456.59"}, - // {"asset":"ETH","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"235.95"}, - // {"asset":"USDT","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"}, - // {"asset":"USDC","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00035"}, - // {"asset":"PAX","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1.00045"}, - // {"asset":"USDTR","totalBalance":"0","availableBalance":"0","maxTransferrable":"0","priceInUSDT":"1"} - // ] - // } - // - const result = { 'info': response }; - const balances = this.safeValue (response, 'data', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - const response = await this.publicGetDepth (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "m":"depth-snapshot", - // "symbol":"BTC-PERP", - // "data":{ - // "ts":1590223998202, - // "seqnum":115444921, - // "asks":[ - // ["9207.5","18.2383"], - // ["9207.75","18.8235"], - // ["9208","10.7873"], - // ], - // "bids":[ - // ["9207.25","0.4009"], - // ["9207","0.003"], - // ["9206.5","0.003"], - // ] - // } - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const orderbook = this.safeValue (data, 'data', {}); - const timestamp = this.safeInteger (orderbook, 'ts'); - const result = this.parseOrderBook (orderbook, timestamp); - result['nonce'] = this.safeInteger (orderbook, 'seqnum'); - return result; - } - - parseTicker (ticker, market = undefined) { - // - // { - // "symbol":"QTUM/BTC", - // "open":"0.00016537", - // "close":"0.00019077", - // "high":"0.000192", - // "low":"0.00016537", - // "volume":"846.6", - // "ask":["0.00018698","26.2"], - // "bid":["0.00018408","503.7"], - // "type":"spot" - // } - // - const timestamp = undefined; - const marketId = this.safeString (ticker, 'symbol'); - let symbol = undefined; - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } else if (marketId !== undefined) { - const type = this.safeString (ticker, 'type'); - if (type === 'spot') { - const [ baseId, quoteId ] = marketId.split ('/'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - } - } - if ((symbol === undefined) && (market !== undefined)) { - symbol = market['symbol']; - } - const close = this.safeFloat (ticker, 'close'); - const bid = this.safeValue (ticker, 'bid', []); - const ask = this.safeValue (ticker, 'ask', []); - const open = this.safeFloat (ticker, 'open'); - let change = undefined; - let percentage = undefined; - let average = undefined; - if ((open !== undefined) && (close !== undefined)) { - change = close - open; - if (open > 0) { - percentage = change / open * 100; - } - average = this.sum (open, close) / 2; - } - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 0), - 'bidVolume': this.safeFloat (bid, 1), - 'ask': this.safeFloat (ask, 0), - 'askVolume': this.safeFloat (ask, 1), - 'vwap': undefined, - 'open': open, - 'close': close, - 'last': close, - 'previousClose': undefined, // previous day close - 'change': change, - 'percentage': percentage, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - const response = await this.publicGetTicker (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "symbol":"BTC-PERP", // or "BTC/USDT" - // "open":"9073", - // "close":"9185.75", - // "high":"9185.75", - // "low":"9185.75", - // "volume":"576.8334", - // "ask":["9185.75","15.5863"], - // "bid":["9185.5","0.003"], - // "type":"derivatives", // or "spot" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - return this.parseTicker (data, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const request = {}; - if (symbols !== undefined) { - const marketIds = this.marketIds (symbols); - request['symbol'] = marketIds.join (','); - } - const response = await this.publicGetTicker (this.extend (request, params)); - // - // { - // "code":0, - // "data":[ - // { - // "symbol":"QTUM/BTC", - // "open":"0.00016537", - // "close":"0.00019077", - // "high":"0.000192", - // "low":"0.00016537", - // "volume":"846.6", - // "ask":["0.00018698","26.2"], - // "bid":["0.00018408","503.7"], - // "type":"spot" - // } - // ] - // } - // - const data = this.safeValue (response, 'data', []); - return this.parseTickers (data, symbols); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "m":"bar", - // "s":"BTC/USDT", - // "data":{ - // "i":"1", - // "ts":1590228000000, - // "o":"9139.59", - // "c":"9131.94", - // "h":"9139.99", - // "l":"9121.71", - // "v":"25.20648" - // } - // } - // - const data = this.safeValue (ohlcv, 'data', {}); - return [ - this.safeInteger (data, 'ts'), - this.safeFloat (data, 'o'), - this.safeFloat (data, 'h'), - this.safeFloat (data, 'l'), - this.safeFloat (data, 'c'), - this.safeFloat (data, 'v'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - 'interval': this.timeframes[timeframe], - }; - // if since and limit are not specified - // the exchange will return just 1 last candle by default - const duration = this.parseTimeframe (timeframe); - const options = this.safeValue (this.options, 'fetchOHLCV', {}); - const defaultLimit = this.safeInteger (options, 'limit', 500); - if (since !== undefined) { - request['from'] = since; - if (limit === undefined) { - limit = defaultLimit; - } else { - limit = Math.min (limit, defaultLimit); - } - request['to'] = this.sum (since, limit * duration * 1000, 1); - } else if (limit !== undefined) { - request['n'] = limit; // max 500 - } - const response = await this.publicGetBarhist (this.extend (request, params)); - // - // { - // "code":0, - // "data":[ - // { - // "m":"bar", - // "s":"BTC/USDT", - // "data":{ - // "i":"1", - // "ts":1590228000000, - // "o":"9139.59", - // "c":"9131.94", - // "h":"9139.99", - // "l":"9121.71", - // "v":"25.20648" - // } - // } - // ] - // } - // - const data = this.safeValue (response, 'data', []); - return this.parseOHLCVs (data, market, timeframe, since, limit); - } - - parseTrade (trade, market = undefined) { - // - // public fetchTrades - // - // { - // "p":"9128.5", // price - // "q":"0.0030", // quantity - // "ts":1590229002385, // timestamp - // "bm":false, // if true, the buyer is the market maker, we only use this field to "define the side" of a public trade - // "seqnum":180143985289898554 - // } - // - const timestamp = this.safeInteger (trade, 'ts'); - const price = this.safeFloat2 (trade, 'price', 'p'); - const amount = this.safeFloat (trade, 'q'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } - const buyerIsMaker = this.safeValue (trade, 'bm', false); - const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; - const side = buyerIsMaker ? 'buy' : 'sell'; - let symbol = undefined; - if ((symbol === undefined) && (market !== undefined)) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'id': undefined, - 'order': undefined, - 'type': undefined, - 'takerOrMaker': makerOrTaker, - 'side': side, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'symbol': market['id'], - }; - if (limit !== undefined) { - request['n'] = limit; // max 100 - } - const response = await this.publicGetTrades (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "m":"trades", - // "symbol":"BTC-PERP", - // "data":[ - // {"p":"9128.5","q":"0.0030","ts":1590229002385,"bm":false,"seqnum":180143985289898554}, - // {"p":"9129","q":"0.0030","ts":1590229002642,"bm":false,"seqnum":180143985289898587}, - // {"p":"9129.5","q":"0.0030","ts":1590229021306,"bm":false,"seqnum":180143985289899043} - // ] - // } - // } - // - const records = this.safeValue (response, 'data', []); - const trades = this.safeValue (records, 'data', []); - return this.parseTrades (trades, market, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'PendingNew': 'open', - 'New': 'open', - 'PartiallyFilled': 'open', - 'Filled': 'closed', - 'Canceled': 'canceled', - 'Rejected': 'rejected', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - // - // createOrder - // - // { - // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", - // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", - // "orderType": "Market", - // "symbol": "BTC/USDT", - // "timestamp": 1573576916201 - // } - // - // fetchOrder, fetchOpenOrders, fetchClosedOrders - // - // { - // "symbol": "BTC/USDT", - // "price": "8131.22", - // "orderQty": "0.00082", - // "orderType": "Market", - // "avgPx": "7392.02", - // "cumFee": "0.005152238", - // "cumFilledQty": "0.00082", - // "errorCode": "", - // "feeAsset": "USDT", - // "lastExecTime": 1575953151764, - // "orderId": "a16eee20b6750866943712zWEDdAjt3", - // "seqNum": 2623469, - // "side": "Buy", - // "status": "Filled", - // "stopPrice": "", - // "execInst": "NULL_VAL" - // } - // - // { - // "ac": "FUTURES", - // "accountId": "testabcdefg", - // "avgPx": "0", - // "cumFee": "0", - // "cumQty": "0", - // "errorCode": "NULL_VAL", - // "execInst": "NULL_VAL", - // "feeAsset": "USDT", - // "lastExecTime": 1584072844085, - // "orderId": "r170d21956dd5450276356bbtcpKa74", - // "orderQty": "1.1499", - // "orderType": "Limit", - // "price": "4000", - // "sendingTime": 1584072841033, - // "seqNum": 24105338, - // "side": "Buy", - // "status": "Canceled", - // "stopPrice": "", - // "symbol": "BTC-PERP" - // }, - // - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'symbol'); - const symbol = this.safeSymbol (marketId, market, '/'); - let timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); - let lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const average = this.safeFloat (order, 'avgPx'); - const filled = this.safeFloat2 (order, 'cumFilledQty', 'cumQty'); - let remaining = undefined; - if (filled !== undefined) { - if (filled === 0) { - timestamp = lastTradeTimestamp; - lastTradeTimestamp = undefined; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - let cost = undefined; - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - const id = this.safeString (order, 'orderId'); - let clientOrderId = this.safeString (order, 'id'); - if (clientOrderId !== undefined) { - if (clientOrderId.length < 1) { - clientOrderId = undefined; - } - } - const type = this.safeStringLower (order, 'orderType'); - const side = this.safeStringLower (order, 'side'); - const feeCost = this.safeFloat (order, 'cumFee'); - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (order, 'feeAsset'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': stopPrice, - 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, - 'remaining': remaining, - 'status': status, - 'fee': fee, - 'trades': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const market = this.market (symbol); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'createOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'symbol': market['id'], - 'time': this.milliseconds (), - 'orderQty': this.amountToPrecision (symbol, amount), - 'orderType': type, // "limit", "market", "stop_market", "stop_limit" - 'side': side, // "buy" or "sell" - // 'orderPrice': this.priceToPrecision (symbol, price), - // 'stopPrice': this.priceToPrecision (symbol, stopPrice), // required for stop orders - // 'postOnly': 'false', // 'false', 'true' - // 'timeInForce': 'GTC', // GTC, IOC, FOK - // 'respInst': 'ACK', // ACK, 'ACCEPT, DONE - }; - if (clientOrderId !== undefined) { - request['id'] = clientOrderId; - params = this.omit (params, [ 'clientOrderId', 'id' ]); - } - if ((type === 'limit') || (type === 'stop_limit')) { - request['orderPrice'] = this.priceToPrecision (symbol, price); - } - if ((type === 'stop_limit') || (type === 'stop_market')) { - const stopPrice = this.safeFloat (params, 'stopPrice'); - if (stopPrice === undefined) { - throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); - } else { - request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); - params = this.omit (params, 'stopPrice'); - } - } - const response = await this.accountCategoryPostOrder (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "ac": "MARGIN", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "action": "place-order", - // "info": { - // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa", - // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830", - // "orderType": "Market", - // "symbol": "BTC/USDT", - // "timestamp": 1573576916201 - // }, - // "status": "Ack" - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const info = this.safeValue (data, 'info', {}); - return this.parseOrder (info, market); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'orderId': id, - }; - const response = await this.accountCategoryGetOrderStatus (this.extend (request, params)); - // - // { - // "code": 0, - // "accountCategory": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "data": [ - // { - // "symbol": "BTC/USDT", - // "price": "8131.22", - // "orderQty": "0.00082", - // "orderType": "Market", - // "avgPx": "7392.02", - // "cumFee": "0.005152238", - // "cumFilledQty": "0.00082", - // "errorCode": "", - // "feeAsset": "USDT", - // "lastExecTime": 1575953151764, - // "orderId": "a16eee20b6750866943712zWEDdAjt3", - // "seqNum": 2623469, - // "side": "Buy", - // "status": "Filled", - // "stopPrice": "", - // "execInst": "NULL_VAL" - // } - // ] - // } - // - const data = this.safeValue (response, 'data', {}); - return this.parseOrder (data); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'fetchOpenOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - }; - const response = await this.accountCategoryGetOrderOpen (this.extend (request, params)); - // - // { - // "ac": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "code": 0, - // "data": [ - // { - // "avgPx": "0", // Average filled price of the order - // "cumFee": "0", // cumulative fee paid for this order - // "cumFilledQty": "0", // cumulative filled quantity - // "errorCode": "", // error code; could be empty - // "feeAsset": "USDT", // fee asset - // "lastExecTime": 1576019723550, // The last execution time of the order - // "orderId": "s16ef21882ea0866943712034f36d83", // server provided orderId - // "orderQty": "0.0083", // order quantity - // "orderType": "Limit", // order type - // "price": "7105", // order price - // "seqNum": 8193258, // sequence number - // "side": "Buy", // order side - // "status": "New", // order status on matching engine - // "stopPrice": "", // only available for stop market and stop limit orders; otherwise empty - // "symbol": "BTC/USDT", - // "execInst": "NULL_VAL" // execution instruction - // }, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - if (accountCategory === 'futures') { - return this.parseOrders (data, market, since, limit); - } - // a workaround for https://github.com/ccxt/ccxt/issues/7187 - const orders = []; - for (let i = 0; i < data.length; i++) { - const order = this.parseOrder (data[i], market); - orders.push (order); - } - return this.filterBySymbolSinceLimit (orders, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - const defaultAccountCategory = this.safeString (this.options, 'account-category'); - const options = this.safeValue (this.options, 'fetchClosedOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - // 'category': accountCategory, - // 'symbol': market['id'], - // 'orderType': 'market', // optional, string - // 'side': 'buy', // or 'sell', optional, case insensitive. - // 'status': 'Filled', // "Filled", "Canceled", or "Rejected" - // 'startTime': exchange.milliseconds (), - // 'endTime': exchange.milliseconds (), - // 'page': 1, - // 'pageSize': 100, - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['symbol'] = market['id']; - } - const method = this.safeValue (options, 'method', 'accountGroupGetOrderHist'); - if (method === 'accountGroupGetOrderHist') { - if (accountCategory !== undefined) { - request['category'] = accountCategory; - } - } else { - request['account-category'] = accountCategory; - } - if (since !== undefined) { - request['startTime'] = since; - } - if (limit !== undefined) { - request['pageSize'] = limit; - } - const response = await this[method] (this.extend (request, params)); - // - // accountCategoryGetOrderHistCurrent - // - // { - // "code":0, - // "accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda", - // "ac":"CASH", - // "data":[ - // { - // "seqNum":15561826728, - // "orderId":"a17294d305c0U6491137460bethu7kw9", - // "symbol":"ETH/USDT", - // "orderType":"Limit", - // "lastExecTime":1591635618200, - // "price":"200", - // "orderQty":"0.1", - // "side":"Buy", - // "status":"Canceled", - // "avgPx":"0", - // "cumFilledQty":"0", - // "stopPrice":"", - // "errorCode":"", - // "cumFee":"0", - // "feeAsset":"USDT", - // "execInst":"NULL_VAL" - // } - // ] - // } - // - // accountGroupGetOrderHist - // - // { - // "code": 0, - // "data": { - // "data": [ - // { - // "ac": "FUTURES", - // "accountId": "testabcdefg", - // "avgPx": "0", - // "cumFee": "0", - // "cumQty": "0", - // "errorCode": "NULL_VAL", - // "execInst": "NULL_VAL", - // "feeAsset": "USDT", - // "lastExecTime": 1584072844085, - // "orderId": "r170d21956dd5450276356bbtcpKa74", - // "orderQty": "1.1499", - // "orderType": "Limit", - // "price": "4000", - // "sendingTime": 1584072841033, - // "seqNum": 24105338, - // "side": "Buy", - // "status": "Canceled", - // "stopPrice": "", - // "symbol": "BTC-PERP" - // }, - // ], - // "hasNext": False, - // "limit": 500, - // "page": 1, - // "pageSize": 20 - // } - // } - // - let data = this.safeValue (response, 'data'); - const isArray = Array.isArray (data); - if (!isArray) { - data = this.safeValue (data, 'data', []); - } - return this.parseOrders (data, market, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument'); - } - await this.loadMarkets (); - await this.loadAccounts (); - const market = this.market (symbol); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'cancelOrder', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const clientOrderId = this.safeString2 (params, 'clientOrderId', 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'symbol': market['id'], - 'time': this.milliseconds (), - 'id': 'foobar', - }; - if (clientOrderId === undefined) { - request['orderId'] = id; - } else { - request['id'] = clientOrderId; - params = this.omit (params, [ 'clientOrderId', 'id' ]); - } - const response = await this.accountCategoryDeleteOrder (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "ac": "CASH", - // "action": "cancel-order", - // "status": "Ack", - // "info": { - // "id": "wv8QGquoeamhssvQBeHOHGQCGlcBjj23", - // "orderId": "16e6198afb4s8bXHbAwwoqDo2ebc19dc", - // "orderType": "", // could be empty - // "symbol": "ETH/USDT", - // "timestamp": 1573594877822 - // } - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const info = this.safeValue (data, 'info', {}); - return this.parseOrder (info, market); - } - - async cancelAllOrders (symbol = undefined, params = {}) { - await this.loadMarkets (); - await this.loadAccounts (); - const defaultAccountCategory = this.safeString (this.options, 'account-category', 'cash'); - const options = this.safeValue (this.options, 'cancelAllOrders', {}); - let accountCategory = this.safeString (options, 'account-category', defaultAccountCategory); - accountCategory = this.safeString (params, 'account-category', accountCategory); - params = this.omit (params, 'account-category'); - const account = this.safeValue (this.accounts, 0, {}); - const accountGroup = this.safeValue (account, 'id'); - const request = { - 'account-group': accountGroup, - 'account-category': accountCategory, - 'time': this.milliseconds (), - }; - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - request['symbol'] = market['id']; - } - const response = await this.accountCategoryDeleteOrderAll (this.extend (request, params)); - // - // { - // "code": 0, - // "data": { - // "ac": "CASH", - // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo", - // "action": "cancel-all", - // "info": { - // "id": "2bmYvi7lyTrneMzpcJcf2D7Pe9V1P9wy", - // "orderId": "", - // "orderType": "NULL_VAL", - // "symbol": "", - // "timestamp": 1574118495462 - // }, - // "status": "Ack" - // } - // } - // - return response; - } - - parseDepositAddress (depositAddress, currency = undefined) { - // - // { - // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // destTag: "", - // tagType: "", - // tagId: "", - // chainName: "ERC20", - // numConfirmations: 20, - // withdrawalFee: 1, - // nativeScale: 4, - // tips: [] - // } - // - const address = this.safeString (depositAddress, 'address'); - const tagId = this.safeString (depositAddress, 'tagId'); - const tag = this.safeString (depositAddress, tagId); - this.checkAddress (address); - const code = (currency === undefined) ? undefined : currency['code']; - return { - 'currency': code, - 'address': address, - 'tag': tag, - 'info': depositAddress, - }; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const chainName = this.safeString (params, 'chainName'); - params = this.omit (params, 'chainName'); - const request = { - 'asset': currency['id'], - }; - const response = await this.privateGetWalletDepositAddress (this.extend (request, params)); - // - // { - // "code":0, - // "data":{ - // "asset":"USDT", - // "assetName":"Tether", - // "address":[ - // { - // "address":"1N22odLHXnLPCjC8kwBJPTayarr9RtPod6", - // "destTag":"", - // "tagType":"", - // "tagId":"", - // "chainName":"Omni", - // "numConfirmations":3, - // "withdrawalFee":4.7, - // "nativeScale":4, - // "tips":[] - // }, - // { - // "address":"0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // "destTag":"", - // "tagType":"", - // "tagId":"", - // "chainName":"ERC20", - // "numConfirmations":20, - // "withdrawalFee":1.0, - // "nativeScale":4, - // "tips":[] - // } - // ] - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const addresses = this.safeValue (data, 'address', []); - const numAddresses = addresses.length; - let address = undefined; - if (numAddresses > 1) { - const addressesByChainName = this.indexBy (addresses, 'chainName'); - if (chainName === undefined) { - const chainNames = Object.keys (addressesByChainName); - const chains = chainNames.join (', '); - throw new ArgumentsRequired (this.id + ' fetchDepositAddress returned more than one address, a chainName parameter is required, one of ' + chains); - } - address = this.safeValue (addressesByChainName, chainName, {}); - } else { - // first address - address = this.safeValue (addresses, 0, {}); - } - const result = this.parseDepositAddress (address, currency); - return this.extend (result, { - 'info': response, - }); - } - - async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { - const request = { - 'txType': 'deposit', - }; - return await this.fetchTransactions (code, since, limit, this.extend (request, params)); - } - - async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) { - const request = { - 'txType': 'withdrawal', - }; - return await this.fetchTransactions (code, since, limit, this.extend (request, params)); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'asset': currency['id'], - // 'page': 1, - // 'pageSize': 20, - // 'startTs': this.milliseconds (), - // 'endTs': this.milliseconds (), - // 'txType': undefned, // deposit, withdrawal - }; - let currency = undefined; - if (code !== undefined) { - currency = this.currency (code); - request['asset'] = currency['id']; - } - if (since !== undefined) { - request['startTs'] = since; - } - if (limit !== undefined) { - request['pageSize'] = limit; - } - const response = await this.privateGetWalletTransactions (this.extend (request, params)); - // - // { - // code: 0, - // data: { - // data: [ - // { - // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", - // time: 1591606166000, - // asset: "USDT", - // transactionType: "deposit", - // amount: "25", - // commission: "0", - // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", - // status: "pending", - // numConfirmed: 8, - // numConfirmations: 20, - // destAddress: { address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722" } - // } - // ], - // page: 1, - // pageSize: 20, - // hasNext: false - // } - // } - // - const data = this.safeValue (response, 'data', {}); - const transactions = this.safeValue (data, 'data', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - 'reviewing': 'pending', - 'pending': 'pending', - 'confirmed': 'ok', - 'rejected': 'rejected', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // requestId: "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB", - // time: 1591606166000, - // asset: "USDT", - // transactionType: "deposit", - // amount: "25", - // commission: "0", - // networkTransactionId: "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce", - // status: "pending", - // numConfirmed: 8, - // numConfirmations: 20, - // destAddress: { - // address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722", - // destTag: "..." // for currencies that have it - // } - // } - // - const id = this.safeString (transaction, 'requestId'); - const amount = this.safeFloat (transaction, 'amount'); - const destAddress = this.safeValue (transaction, 'destAddress', {}); - const address = this.safeString (destAddress, 'address'); - const tag = this.safeString (destAddress, 'destTag'); - const txid = this.safeString (transaction, 'networkTransactionId'); - const type = this.safeString (transaction, 'transactionType'); - const timestamp = this.safeInteger (transaction, 'time'); - const currencyId = this.safeString (transaction, 'asset'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'commission'); - return { - 'info': transaction, - 'id': id, - 'currency': code, - 'amount': amount, - 'address': address, - 'addressTo': address, - 'addressFrom': undefined, - 'tag': tag, - 'tagTo': tag, - 'tagFrom': undefined, - 'status': status, - 'type': type, - 'updated': undefined, - 'txid': txid, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'fee': { - 'currency': code, - 'cost': feeCost, - }, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = ''; - let query = params; - const accountCategory = (api === 'accountCategory'); - if (accountCategory || (api === 'accountGroup')) { - url += this.implodeParams ('/{account-group}', params); - query = this.omit (params, 'account-group'); - } - const request = this.implodeParams (path, query); - url += '/api/pro/' + this.version; - if (accountCategory) { - url += this.implodeParams ('/{account-category}', query); - query = this.omit (query, 'account-category'); - } - url += '/' + request; - query = this.omit (query, this.extractParams (path)); - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const timestamp = this.milliseconds ().toString (); - const payload = timestamp + '+' + request; - const hmac = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64'); - headers = { - 'x-auth-key': this.apiKey, - 'x-auth-timestamp': timestamp, - 'x-auth-signature': hmac, - }; - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - headers['Content-Type'] = 'application/json'; - body = this.json (query); - } - } - url = this.urls['api'] + url; - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - // - // {'code': 6010, 'message': 'Not enough balance.'} - // {'code': 60060, 'message': 'The order is already filled or canceled.'} - // {"code":2100,"message":"ApiKeyFailure"} - // {"code":300001,"message":"Price is too low from market price.","reason":"INVALID_PRICE","accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda","ac":"CASH","action":"place-order","status":"Err","info":{"symbol":"BTC/USDT"}} - // - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'message'); - const error = (code !== undefined) && (code !== '0'); - if (error || (message !== undefined)) { - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],38:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],38:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -26373,6 +26421,7 @@ module.exports = class bitmax extends Exchange { const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, BadRequest, DDoSProtection, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -26583,8 +26632,8 @@ module.exports = class bitmex extends Exchange { 'amount': undefined, 'price': undefined, }; - const lotSize = this.safeFloat (market, 'lotSize'); - const tickSize = this.safeFloat (market, 'tickSize'); + const lotSize = this.safeNumber (market, 'lotSize'); + const tickSize = this.safeNumber (market, 'tickSize'); if (lotSize !== undefined) { precision['amount'] = lotSize; } @@ -26598,7 +26647,7 @@ module.exports = class bitmex extends Exchange { }, 'price': { 'min': tickSize, - 'max': this.safeFloat (market, 'maxPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { 'min': undefined, @@ -26608,7 +26657,7 @@ module.exports = class bitmex extends Exchange { const limitField = (position === quote) ? 'cost' : 'amount'; limits[limitField] = { 'min': lotSize, - 'max': this.safeFloat (market, 'maxOrderQty'), + 'max': this.safeNumber (market, 'maxOrderQty'), }; result.push ({ 'id': id, @@ -26620,8 +26669,8 @@ module.exports = class bitmex extends Exchange { 'active': active, 'precision': precision, 'limits': limits, - 'taker': this.safeFloat (market, 'takerFee'), - 'maker': this.safeFloat (market, 'makerFee'), + 'taker': this.safeNumber (market, 'takerFee'), + 'maker': this.safeNumber (market, 'makerFee'), 'type': type, 'spot': false, 'swap': swap, @@ -26687,21 +26736,17 @@ module.exports = class bitmex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - let free = this.safeFloat (balance, 'availableMargin'); - let total = this.safeFloat (balance, 'marginBalance'); + let free = this.safeString (balance, 'availableMargin'); + let total = this.safeString (balance, 'marginBalance'); if (code === 'BTC') { - if (free !== undefined) { - free /= 100000000; - } - if (total !== undefined) { - total /= 100000000; - } + free = Precise.stringDiv (free, '1e8'); + total = Precise.stringDiv (total, '1e8'); } account['free'] = free; account['total'] = total; result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -26780,8 +26825,8 @@ module.exports = class bitmex extends Exchange { for (let i = 0; i < response.length; i++) { const order = response[i]; const side = (order['side'] === 'Sell') ? 'asks' : 'bids'; - const amount = this.safeFloat (order, 'size'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const price = this.safeNumber (order, 'price'); // https://github.com/ccxt/ccxt/issues/4926 // https://github.com/ccxt/ccxt/issues/4927 // the exchange sometimes returns null price in the orderbook @@ -26987,7 +27032,7 @@ module.exports = class bitmex extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'transactType')); const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount !== undefined) { amount = amount / 100000000; } @@ -26998,7 +27043,7 @@ module.exports = class bitmex extends Exchange { // for unrealized pnl and other transactions without a timestamp timestamp = 0; // see comments above } - let feeCost = this.safeFloat (item, 'fee', 0); + let feeCost = this.safeNumber (item, 'fee', 0); if (feeCost !== undefined) { feeCost = feeCost / 100000000; } @@ -27006,7 +27051,7 @@ module.exports = class bitmex extends Exchange { 'cost': feeCost, 'currency': code, }; - let after = this.safeFloat (item, 'walletBalance'); + let after = this.safeNumber (item, 'walletBalance'); if (after !== undefined) { after = after / 100000000; } @@ -27325,8 +27370,8 @@ module.exports = class bitmex extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const open = this.safeFloat (ticker, 'prevPrice24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'prevPrice24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; if (last !== undefined && open !== undefined) { @@ -27339,13 +27384,13 @@ module.exports = class bitmex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askPrice'), + 'ask': this.safeNumber (ticker, 'askPrice'), 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'vwap'), + 'vwap': this.safeNumber (ticker, 'vwap'), 'open': open, 'close': last, 'last': last, @@ -27353,8 +27398,8 @@ module.exports = class bitmex extends Exchange { 'change': change, 'percentage': percentage, 'average': this.sum (open, last) / 2, - 'baseVolume': this.safeFloat (ticker, 'homeNotional24h'), - 'quoteVolume': this.safeFloat (ticker, 'foreignNotional24h'), + 'baseVolume': this.safeNumber (ticker, 'homeNotional24h'), + 'quoteVolume': this.safeNumber (ticker, 'foreignNotional24h'), 'info': ticker, }; } @@ -27379,11 +27424,11 @@ module.exports = class bitmex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -27512,23 +27557,23 @@ module.exports = class bitmex extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat2 (trade, 'avgPx', 'price'); - const amount = this.safeFloat2 (trade, 'size', 'lastQty'); + const price = this.safeNumber2 (trade, 'avgPx', 'price'); + const amount = this.safeNumber2 (trade, 'size', 'lastQty'); const id = this.safeString (trade, 'trdMatchID'); const order = this.safeString (trade, 'orderID'); const side = this.safeStringLower (trade, 'side'); // price * amount doesn't work for all symbols (e.g. XBT, ETH) - let cost = this.safeFloat (trade, 'execCost'); + let cost = this.safeNumber (trade, 'execCost'); if (cost !== undefined) { cost = Math.abs (cost) / 100000000; } let fee = undefined; if ('execComm' in trade) { - let feeCost = this.safeFloat (trade, 'execComm'); + let feeCost = this.safeNumber (trade, 'execComm'); feeCost = feeCost / 100000000; const currencyId = this.safeString (trade, 'settlCurrency'); const feeCurrency = this.safeCurrencyCode (currencyId); - const feeRate = this.safeFloat (trade, 'commission'); + const feeRate = this.safeNumber (trade, 'commission'); fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -27630,33 +27675,19 @@ module.exports = class bitmex extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'transactTime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty', 0.0); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (amount - filled, 0.0); - } - } - const average = this.safeFloat (order, 'avgPx'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = average * filled; - } else if (price !== undefined) { - cost = price * filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty', 0.0); + const average = this.safeNumber (order, 'avgPx'); const id = this.safeString (order, 'orderID'); const type = this.safeStringLower (order, 'ordType'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'clOrdID'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'ParticipateDoNotInitiate'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -27671,14 +27702,14 @@ module.exports = class bitmex extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { @@ -27739,7 +27770,7 @@ module.exports = class bitmex extends Exchange { 'ordType': orderType, }; if ((orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched')) { - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPx or stopPrice parameter for the ' + orderType + ' order type'); } else { @@ -27856,7 +27887,7 @@ module.exports = class bitmex extends Exchange { return this.parseOrders (response, market); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPosition (params); // [ @@ -28051,7 +28082,7 @@ module.exports = class bitmex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],39:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],39:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -28382,7 +28413,7 @@ module.exports = class bitpanda extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; @@ -28455,9 +28486,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -28504,8 +28535,8 @@ module.exports = class bitpanda extends Exchange { const activeFeeTier = this.safeValue (response, 'active_fee_tier', {}); const result = { 'info': response, - 'maker': this.safeFloat (activeFeeTier, 'maker_fee'), - 'taker': this.safeFloat (activeFeeTier, 'taker_fee'), + 'maker': this.safeNumber (activeFeeTier, 'maker_fee'), + 'taker': this.safeNumber (activeFeeTier, 'taker_fee'), 'percentage': true, 'tierBased': true, }; @@ -28514,9 +28545,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -28554,27 +28585,27 @@ module.exports = class bitpanda extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last_price'); - const percentage = this.safeFloat (ticker, 'price_change_percentage'); - const change = this.safeFloat (ticker, 'price_change'); + const last = this.safeNumber (ticker, 'last_price'); + const percentage = this.safeNumber (ticker, 'price_change_percentage'); + const change = this.safeNumber (ticker, 'price_change'); let open = undefined; let average = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'best_bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -28759,11 +28790,11 @@ module.exports = class bitpanda extends Exchange { const volumeField = this.safeString (options, 'volume', 'total_amount'); return [ alignedTimestamp, - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -28849,21 +28880,21 @@ module.exports = class bitpanda extends Exchange { timestamp = this.parse8601 (this.safeString (trade, 'time')); } const side = this.safeStringLower2 (trade, 'side', 'taker_side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + let cost = this.safeNumber (trade, 'volume'); if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { cost = amount * price; } const marketId = this.safeString (trade, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (feeInfo, 'fee_amount'); + const feeCost = this.safeNumber (feeInfo, 'fee_amount'); let takerOrMaker = undefined; let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (feeInfo, 'fee_percentage'); + const feeRate = this.safeNumber (feeInfo, 'fee_percentage'); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, @@ -28946,11 +28977,11 @@ module.exports = class bitpanda extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -29204,12 +29235,12 @@ module.exports = class bitpanda extends Exchange { // } // const id = this.safeString (transaction, 'transaction_id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const currencyId = this.safeString (transaction, 'currency'); currency = this.safeCurrency (currencyId, currency); const status = 'ok'; // the exchange returns cleared transactions only - const feeCost = this.safeFloat2 (transaction, 'fee_amount', 'fee'); + const feeCost = this.safeNumber2 (transaction, 'fee_amount', 'fee'); let fee = undefined; const addressTo = this.safeString (transaction, 'recipient'); const tagTo = this.safeString (transaction, 'destination_tag'); @@ -29324,72 +29355,34 @@ module.exports = class bitpanda extends Exchange { // ] // } // - const rawTrades = this.safeValue (order, 'trades', []); - order = this.safeValue (order, 'order', order); - const id = this.safeString (order, 'order_id'); - const clientOrderId = this.safeString (order, 'client_id'); - const timestamp = this.parse8601 (this.safeString (order, 'time')); - let status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'instrument_code'); + const rawOrder = this.safeValue (order, 'order', order); + const id = this.safeString (rawOrder, 'order_id'); + const clientOrderId = this.safeString (rawOrder, 'client_id'); + const timestamp = this.parse8601 (this.safeString (rawOrder, 'time')); + const rawStatus = this.parseOrderStatus (this.safeString (rawOrder, 'status')); + const status = this.parseOrderStatus (rawStatus); + const marketId = this.safeString (rawOrder, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - if (status === undefined) { - if (remaining > 0) { - status = 'open'; - } else { - status = 'closed'; - } - } - } - } - const side = this.safeStringLower (order, 'side'); - const type = this.safeStringLower (order, 'type'); - const trades = this.parseTrades (rawTrades, market, undefined, undefined); - const fees = []; - const numTrades = trades.length; - let lastTradeTimestamp = undefined; - let tradeCost = undefined; - let tradeAmount = undefined; - if (numTrades > 0) { - lastTradeTimestamp = trades[0]['timestamp']; - tradeCost = 0; - tradeAmount = 0; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - fees.push (trade['fee']); - lastTradeTimestamp = Math.max (lastTradeTimestamp, trade['timestamp']); - tradeCost = this.sum (tradeCost, trade['cost']); - tradeAmount = this.sum (tradeAmount, trade['amount']); - } - } - let average = this.safeFloat (order, 'average_price'); - if (average === undefined) { - if ((tradeCost !== undefined) && (tradeAmount !== undefined) && (tradeAmount !== 0)) { - average = tradeCost / tradeAmount; - } - } - if (cost === undefined) { - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - } - const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'trigger_price'); - const postOnly = this.safeValue (order, 'is_post_only'); - const result = { + const price = this.safeNumber (rawOrder, 'price'); + const amount = this.safeNumber (rawOrder, 'amount'); + const filledString = this.safeString (rawOrder, 'filled_amount'); + const filled = this.parseNumber (filledString); + const side = this.safeStringLower (rawOrder, 'side'); + const type = this.safeStringLower (rawOrder, 'type'); + const timeInForce = this.parseTimeInForce (this.safeString (rawOrder, 'time_in_force')); + const stopPrice = this.safeNumber (rawOrder, 'trigger_price'); + const postOnly = this.safeValue (rawOrder, 'is_post_only'); + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'type': type, + }); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -29398,41 +29391,14 @@ module.exports = class bitpanda extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, // 'fee': undefined, 'trades': trades, - }; - const numFees = fees.length; - if (numFees > 0) { - if (numFees === 1) { - result['fee'] = fees[0]; - } else { - const feesByCurrency = this.groupBy (fees, 'currency'); - const feeCurrencies = Object.keys (feesByCurrency); - const numFeesByCurrency = feeCurrencies.length; - if (numFeesByCurrency === 1) { - const feeCurrency = feeCurrencies[0]; - const feeArray = this.safeValue (feesByCurrency, feeCurrency); - let feeCost = 0; - for (let i = 0; i < feeArray.length; i++) { - feeCost = this.sum (feeCost, feeArray[i]['cost']); - } - result['fee'] = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } else { - result['fees'] = fees; - } - } - } else { - result['fee'] = undefined; - } - return result; + }); } parseTimeInForce (timeInForce) { @@ -29466,7 +29432,7 @@ module.exports = class bitpanda extends Exchange { priceIsRequired = true; } if (uppercaseType === 'STOP') { - const triggerPrice = this.safeFloat (params, 'trigger_price'); + const triggerPrice = this.safeNumber (params, 'trigger_price'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a trigger_price param for ' + type + ' orders'); } @@ -29869,7 +29835,7 @@ module.exports = class bitpanda extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],40:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],40:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -30029,28 +29995,28 @@ module.exports = class bitso extends Exchange { const symbol = base + '/' + quote; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), - 'max': this.safeFloat (market, 'maximum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), + 'max': this.safeNumber (market, 'maximum_amount'), }, 'price': { - 'min': this.safeFloat (market, 'minimum_price'), - 'max': this.safeFloat (market, 'maximum_price'), + 'min': this.safeNumber (market, 'minimum_price'), + 'max': this.safeNumber (market, 'maximum_price'), }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), - 'max': this.safeFloat (market, 'maximum_value'), + 'min': this.safeNumber (market, 'minimum_value'), + 'max': this.safeNumber (market, 'maximum_value'), }, }; - const defaultPricePrecision = this.safeFloat (this.options['precision'], quote, this.options['defaultPrecision']); - const pricePrecision = this.safeFloat (market, 'tick_size', defaultPricePrecision); + const defaultPricePrecision = this.safeNumber (this.options['precision'], quote, this.options['defaultPrecision']); + const pricePrecision = this.safeNumber (market, 'tick_size', defaultPricePrecision); const precision = { - 'amount': this.safeFloat (this.options['precision'], base, this.options['defaultPrecision']), + 'amount': this.safeNumber (this.options['precision'], base, this.options['defaultPrecision']), 'price': pricePrecision, }; const fees = this.safeValue (market, 'fees', {}); const flatRate = this.safeValue (fees, 'flat_rate', {}); - const maker = this.safeFloat (flatRate, 'maker'); - const taker = this.safeFloat (flatRate, 'taker'); + const maker = this.safeNumber (flatRate, 'maker'); + const taker = this.safeNumber (flatRate, 'taker'); const feeTiers = this.safeValue (fees, 'structure', []); const fee = { 'taker': parseFloat (this.decimalToPrecision (taker / 100, ROUND, 0.00000001, TICK_SIZE)), @@ -30062,9 +30028,9 @@ module.exports = class bitso extends Exchange { const makerFees = []; for (let j = 0; j < feeTiers.length; j++) { const tier = feeTiers[j]; - const volume = this.safeFloat (tier, 'volume'); - const takerFee = this.safeFloat (tier, 'taker'); - const makerFee = this.safeFloat (tier, 'maker'); + const volume = this.safeNumber (tier, 'volume'); + const takerFee = this.safeNumber (tier, 'taker'); + const makerFee = this.safeNumber (tier, 'maker'); const takerFeeToPrecision = parseFloat (this.decimalToPrecision (takerFee / 100, ROUND, 0.00000001, TICK_SIZE)); const makerFeeToPrecision = parseFloat (this.decimalToPrecision (makerFee / 100, ROUND, 0.00000001, TICK_SIZE)); takerFees.push ([ volume, takerFeeToPrecision ]); @@ -30104,14 +30070,13 @@ module.exports = class bitso extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'locked'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -30133,22 +30098,22 @@ module.exports = class bitso extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'payload'); const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -30169,12 +30134,12 @@ module.exports = class bitso extends Exchange { const marketId = this.safeString (trade, 'book'); const symbol = this.safeSymbol (marketId, market, '_'); const side = this.safeString2 (trade, 'side', 'maker_side'); - let amount = this.safeFloat2 (trade, 'amount', 'major'); + let amount = this.safeNumber2 (trade, 'amount', 'major'); if (amount !== undefined) { amount = Math.abs (amount); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fees_amount'); + const feeCost = this.safeNumber (trade, 'fees_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fees_currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -30183,11 +30148,11 @@ module.exports = class bitso extends Exchange { 'currency': feeCurrency, }; } - let cost = this.safeFloat (trade, 'minor'); + let cost = this.safeNumber (trade, 'minor'); if (cost !== undefined) { cost = Math.abs (cost); } - const price = this.safeFloat (trade, 'price'); + const price = this.safeNumber (trade, 'price'); const orderId = this.safeString (trade, 'oid'); const id = this.safeString (trade, 'tid'); return { @@ -30288,17 +30253,11 @@ module.exports = class bitso extends Exchange { const symbol = this.safeSymbol (marketId, market, '_'); const orderType = this.safeString (order, 'type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'unfilled_amount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'unfilled_amount'); const clientOrderId = this.safeString (order, 'client_id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -30315,12 +30274,12 @@ module.exports = class bitso extends Exchange { 'amount': amount, 'cost': undefined, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = 25, params = {}) { @@ -30496,7 +30455,7 @@ module.exports = class bitso extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],41:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],41:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -30614,6 +30573,16 @@ module.exports = class bitstamp extends Exchange { 'usdc_address/', 'omg_withdrawal/', 'omg_address/', + 'dai_withdrawal/', + 'dai_address/', + 'knc_withdrawal/', + 'knc_address/', + 'mkr_withdrawal/', + 'mkr_address/', + 'zrx_withdrawal/', + 'zrx_address/', + 'gusd_withdrawal/', + 'gusd_address/', 'transfer-to-main/', 'transfer-from-main/', 'withdrawal-requests/', @@ -30748,13 +30717,15 @@ module.exports = class bitstamp extends Exchange { const symbolId = baseId + '_' + quoteId; const id = this.safeString (market, 'url_symbol'); const precision = { - 'amount': market['base_decimals'], - 'price': market['counter_decimals'], + 'amount': this.safeInteger (market, 'base_decimals'), + 'price': this.safeInteger (market, 'counter_decimals'), }; - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; // let [ cost, currency ] = market['minimum_order'].split (' '); - const active = (market['trading'] === 'Enabled'); + const trading = this.safeString (market, 'trading'); + const active = (trading === 'Enabled'); result.push ({ 'id': id, 'symbol': symbol, @@ -30798,7 +30769,7 @@ module.exports = class bitstamp extends Exchange { 'type': currencyType, 'name': name, 'active': true, - 'fee': this.safeFloat (description['fees']['funding']['withdraw'], code), + 'fee': this.safeNumber (description['fees']['funding']['withdraw'], code), 'precision': precision, 'limits': { 'amount': { @@ -30851,13 +30822,16 @@ module.exports = class bitstamp extends Exchange { quote = this.safeCurrencyCode (quote); const description = this.safeString (market, 'description'); const [ baseDescription, quoteDescription ] = description.split (' / '); - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; if (!(base in result)) { - result[base] = this.constructCurrencyObject (baseId, base, baseDescription, market['base_decimals'], undefined, market); + const baseDecimals = this.safeInteger (market, 'base_decimals'); + result[base] = this.constructCurrencyObject (baseId, base, baseDescription, baseDecimals, undefined, market); } if (!(quote in result)) { - result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, market['counter_decimals'], parseFloat (cost), market); + const counterDecimals = this.safeInteger (market, 'counter_decimals'); + result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, counterDecimals, parseFloat (cost), market); } } return result; @@ -30899,25 +30873,25 @@ module.exports = class bitstamp extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -30960,7 +30934,7 @@ module.exports = class bitstamp extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; if (id.indexOf ('_') < 0) { - const value = this.safeFloat (transaction, id); + const value = this.safeNumber (transaction, id); if ((value !== undefined) && (value !== 0)) { return id; } @@ -31042,11 +31016,11 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString2 (trade, 'id', 'tid'); let symbol = undefined; let side = undefined; - let price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat (trade, 'amount'); + let price = this.safeNumber (trade, 'price'); + let amount = this.safeNumber (trade, 'amount'); const orderId = this.safeString (trade, 'order_id'); const type = undefined; - let cost = this.safeFloat (trade, 'cost'); + let cost = this.safeNumber (trade, 'cost'); if (market === undefined) { const keys = Object.keys (trade); for (let i = 0; i < keys.length; i++) { @@ -31063,12 +31037,12 @@ module.exports = class bitstamp extends Exchange { market = this.getMarketFromTrade (trade); } } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = undefined; if (market !== undefined) { - price = this.safeFloat (trade, market['symbolId'], price); - amount = this.safeFloat (trade, market['baseId'], amount); - cost = this.safeFloat (trade, market['quoteId'], cost); + price = this.safeNumber (trade, market['symbolId'], price); + amount = this.safeNumber (trade, market['baseId'], amount); + cost = this.safeNumber (trade, market['quoteId'], cost); feeCurrency = market['quote']; symbol = market['symbol']; } @@ -31137,7 +31111,7 @@ module.exports = class bitstamp extends Exchange { parseTradingFee (balances, symbol) { const market = this.market (symbol); - const tradeFee = this.safeFloat (balances, market['id'] + '_fee'); + const tradeFee = this.safeNumber (balances, market['id'] + '_fee'); return { 'symbol': symbol, 'maker': tradeFee, @@ -31187,11 +31161,11 @@ module.exports = class bitstamp extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -31249,12 +31223,12 @@ module.exports = class bitstamp extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -31301,7 +31275,7 @@ module.exports = class bitstamp extends Exchange { if (id.indexOf ('_withdrawal_fee') >= 0) { const currencyId = id.split ('_')[0]; const code = this.safeCurrencyCode (currencyId); - withdraw[code] = this.safeFloat (balance, id); + withdraw[code] = this.safeNumber (balance, id); } } return { @@ -31547,16 +31521,16 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString (transaction, 'id'); const currencyId = this.getCurrencyIdFromTransaction (transaction); const code = this.safeCurrencyCode (currencyId, currency); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let feeCurrency = undefined; let amount = undefined; if ('amount' in transaction) { - amount = this.safeFloat (transaction, 'amount'); + amount = this.safeNumber (transaction, 'amount'); } else if (currency !== undefined) { - amount = this.safeFloat (transaction, currency['id'], amount); + amount = this.safeNumber (transaction, currency['id'], amount); feeCurrency = currency['code']; } else if ((code !== undefined) && (currencyId !== undefined)) { - amount = this.safeFloat (transaction, currencyId, amount); + amount = this.safeNumber (transaction, currencyId, amount); feeCurrency = code; } if (amount !== undefined) { @@ -31681,83 +31655,23 @@ module.exports = class bitstamp extends Exchange { } // there is no timestamp from fetchOrder const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - let lastTradeTimestamp = undefined; - let symbol = undefined; - let marketId = this.safeStringLower (order, 'currency_pair'); - if (marketId !== undefined) { - marketId = marketId.replace ('/', ''); - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - symbol = market['symbol']; - } - } - let amount = this.safeFloat (order, 'amount'); - let filled = 0.0; - const trades = []; - const transactions = this.safeValue (order, 'transactions', []); - let feeCost = undefined; - let cost = undefined; - const numTransactions = transactions.length; - if (numTransactions > 0) { - feeCost = 0.0; - for (let i = 0; i < numTransactions; i++) { - const trade = this.parseTrade (this.extend ({ - 'order_id': id, - 'side': side, - }, transactions[i]), market); - filled = this.sum (filled, trade['amount']); - feeCost = this.sum (feeCost, trade['fee']['cost']); - if (cost === undefined) { - cost = 0.0; - } - cost = this.sum (cost, trade['cost']); - trades.push (trade); - } - lastTradeTimestamp = trades[numTransactions - 1]['timestamp']; - } + const marketId = this.safeStringLower (order, 'currency_pair'); + let symbol = this.safeSymbol (marketId, market, '/'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((status === 'closed') && (amount === undefined)) { - amount = filled; + const amount = this.safeNumber (order, 'amount'); + const transactions = this.safeValue (order, 'transactions', []); + const trades = this.parseTrades (transactions, market); + const length = trades.length; + if (length) { + symbol = trades[0]['symbol']; } - let remaining = undefined; - if (amount !== undefined) { - remaining = amount - filled; - } - let price = this.safeFloat (order, 'price'); - if (market === undefined) { - market = this.getMarketFromTrades (trades); - } - let feeCurrency = undefined; - if (market !== undefined) { - if (symbol === undefined) { - symbol = market['symbol']; - } - feeCurrency = market['quote']; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if (price === undefined) { - if (filled > 0) { - price = cost / filled; - } - } - let fee = undefined; - if (feeCost !== undefined) { - if (feeCurrency !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { + const price = this.safeNumber (order, 'price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': undefined, @@ -31766,15 +31680,15 @@ module.exports = class bitstamp extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, - 'filled': filled, - 'remaining': remaining, + 'filled': undefined, + 'remaining': undefined, 'trades': trades, - 'fee': fee, + 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } parseLedgerEntryType (type) { @@ -31854,11 +31768,11 @@ module.exports = class bitstamp extends Exchange { const parsedTransaction = this.parseTransaction (item); let direction = undefined; if ('amount' in item) { - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); direction = amount > 0 ? 'in' : 'out'; } else if (('currency' in parsedTransaction) && parsedTransaction['currency'] !== undefined) { const currencyId = this.currencyId (parsedTransaction['currency']); - const amount = this.safeFloat (item, currencyId); + const amount = this.safeNumber (item, currencyId); direction = amount > 0 ? 'in' : 'out'; } return { @@ -32105,13 +32019,14 @@ module.exports = class bitstamp extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],42:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],42:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -32208,25 +32123,25 @@ module.exports = class bitstamp1 extends Exchange { await this.loadMarkets (); const ticker = await this.publicGetTicker (params); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -32249,14 +32164,11 @@ module.exports = class bitstamp1 extends Exchange { } } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -32300,12 +32212,12 @@ module.exports = class bitstamp1 extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -32406,7 +32318,7 @@ module.exports = class bitstamp1 extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],43:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],43:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -32414,6 +32326,7 @@ module.exports = class bitstamp1 extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, DDoSProtection, PermissionDenied, AddressPending, OnMaintenance, BadRequest, InvalidAddress } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -32689,7 +32602,7 @@ module.exports = class bittrex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeSize'), + 'min': this.safeNumber (market, 'minTradeSize'), 'max': undefined, }, 'price': { @@ -32717,11 +32630,11 @@ module.exports = class bittrex extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); const balance = indexed[currencyId]; - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -32781,7 +32694,7 @@ module.exports = class bittrex extends Exchange { const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); const precision = 8; // default precision, todo: fix "magic constants" - const fee = this.safeFloat (currency, 'txFee'); // todo: redesign + const fee = this.safeNumber (currency, 'txFee'); // todo: redesign const isActive = this.safeString (currency, 'status'); result[code] = { 'id': id, @@ -32842,17 +32755,17 @@ module.exports = class bittrex extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'updatedAt')); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const percentage = this.safeFloat (ticker, 'percentChange'); - const last = this.safeFloat (ticker, 'lastTradeRate'); + const percentage = this.safeNumber (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'lastTradeRate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidRate'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidRate'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askRate'), + 'ask': this.safeNumber (ticker, 'askRate'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -32862,8 +32775,8 @@ module.exports = class bittrex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -32976,21 +32889,18 @@ module.exports = class bittrex extends Exchange { const order = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'marketSymbol'); market = this.safeMarket (marketId, market, '-'); - let cost = undefined; - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'quantity'); - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = undefined; const isTaker = this.safeValue (trade, 'isTaker'); if (isTaker !== undefined) { takerOrMaker = isTaker ? 'taker' : 'maker'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -33060,11 +32970,11 @@ module.exports = class bittrex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'startsAt')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -33171,9 +33081,9 @@ module.exports = class bittrex extends Exchange { let cost = undefined; if (isCeilingLimit) { request['limit'] = this.priceToPrecision (symbol, price); - cost = this.safeFloat2 (params, 'ceiling', 'cost', amount); + cost = this.safeNumber2 (params, 'ceiling', 'cost', amount); } else if (isCeilingMarket) { - cost = this.safeFloat2 (params, 'ceiling', 'cost'); + cost = this.safeNumber2 (params, 'ceiling', 'cost'); if (cost === undefined) { if (price === undefined) { cost = amount; @@ -33332,7 +33242,7 @@ module.exports = class bittrex extends Exchange { // } // const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const address = this.safeString (transaction, 'cryptoAddress'); const txid = this.safeString (transaction, 'txId'); const updated = this.parse8601 (this.safeString (transaction, 'updatedAt')); @@ -33368,7 +33278,7 @@ module.exports = class bittrex extends Exchange { status = 'ok'; } } - let feeCost = this.safeFloat (transaction, 'txCost'); + let feeCost = this.safeNumber (transaction, 'txCost'); if (feeCost === undefined) { if (type === 'deposit') { // according to https://support.bittrex.com/hc/en-us/articles/115000199651-What-fees-does-Bittrex-charge- @@ -33425,15 +33335,9 @@ module.exports = class bittrex extends Exchange { // } // const marketSymbol = this.safeString (order, 'marketSymbol'); - let symbol = undefined; - let feeCurrency = undefined; - if (marketSymbol !== undefined) { - const [ baseId, quoteId ] = marketSymbol.split ('-'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - feeCurrency = quote; - } + market = this.safeMarket (marketSymbol, market, '-'); + const symbol = market['symbol']; + const feeCurrency = market['quote']; const direction = this.safeStringLower (order, 'direction'); const createdAt = this.safeString (order, 'createdAt'); const updatedAt = this.safeString (order, 'updatedAt'); @@ -33446,32 +33350,15 @@ module.exports = class bittrex extends Exchange { } const timestamp = this.parse8601 (createdAt); const type = this.safeStringLower (order, 'type'); - const quantity = this.safeFloat (order, 'quantity'); - const limit = this.safeFloat (order, 'limit'); - const fillQuantity = this.safeFloat (order, 'fillQuantity'); - const commission = this.safeFloat (order, 'commission'); - const proceeds = this.safeFloat (order, 'proceeds'); - let average = undefined; - let remaining = undefined; - if (fillQuantity !== undefined) { - if (proceeds !== undefined) { - if (fillQuantity > 0) { - average = proceeds / fillQuantity; - } else if (proceeds === 0) { - average = 0; - } - } - if (quantity !== undefined) { - remaining = quantity - fillQuantity; - } - } - let status = this.safeStringLower (order, 'status'); - if ((status === 'closed') && (remaining !== undefined) && (remaining > 0)) { - status = 'canceled'; - } + const quantity = this.safeNumber (order, 'quantity'); + const limit = this.safeNumber (order, 'limit'); + const fillQuantity = this.safeNumber (order, 'fillQuantity'); + const commission = this.safeNumber (order, 'commission'); + const proceeds = this.safeNumber (order, 'proceeds'); + const status = this.safeStringLower (order, 'status'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'timestamp': timestamp, @@ -33485,10 +33372,10 @@ module.exports = class bittrex extends Exchange { 'price': limit, 'stopPrice': undefined, 'cost': proceeds, - 'average': average, + 'average': undefined, 'amount': quantity, 'filled': fillQuantity, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': { 'cost': commission, @@ -33496,7 +33383,7 @@ module.exports = class bittrex extends Exchange { }, 'info': order, 'trades': undefined, - }; + }); } parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { @@ -33545,9 +33432,9 @@ module.exports = class bittrex extends Exchange { 'side': this.safeString (order, 'side'), 'order': this.safeString (order, 'id'), 'type': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'average'), - 'amount': this.safeFloat (order, 'filled'), - 'cost': this.safeFloat (order, 'cost'), + 'price': this.safeNumber (order, 'average'), + 'amount': this.safeNumber (order, 'filled'), + 'cost': this.safeNumber (order, 'cost'), 'symbol': this.safeString (order, 'symbol'), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -33839,7 +33726,7 @@ module.exports = class bittrex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],44:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],44:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -33847,6 +33734,7 @@ module.exports = class bittrex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, BadSymbol, AuthenticationError, InsufficientFunds, InvalidOrder, ArgumentsRequired, OrderNotFound, InvalidAddress, BadRequest, RateLimitExceeded, PermissionDenied, ExchangeNotAvailable, AccountSuspended, OnMaintenance } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -34148,7 +34036,7 @@ module.exports = class bitvavo extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minOrderInBaseAsset'), + 'min': this.safeNumber (market, 'minOrderInBaseAsset'), 'max': undefined, }, 'price': { @@ -34156,7 +34044,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderInQuoteAsset'), + 'min': this.safeNumber (market, 'minOrderInQuoteAsset'), 'max': undefined, }, }, @@ -34219,7 +34107,7 @@ module.exports = class bitvavo extends Exchange { 'code': code, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -34235,7 +34123,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMinAmount'), + 'min': this.safeNumber (currency, 'withdrawalMinAmount'), 'max': undefined, }, }, @@ -34292,14 +34180,14 @@ module.exports = class bitvavo extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); + const last = this.safeNumber (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -34311,12 +34199,12 @@ module.exports = class bitvavo extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': vwap, 'open': open, 'close': last, @@ -34332,14 +34220,6 @@ module.exports = class bitvavo extends Exchange { return result; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24h (params); @@ -34453,12 +34333,11 @@ module.exports = class bitvavo extends Exchange { // feeCurrency: 'EUR' // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'side'); const id = this.safeString2 (trade, 'id', 'fillId'); @@ -34469,7 +34348,7 @@ module.exports = class bitvavo extends Exchange { if (taker !== undefined) { takerOrMaker = taker ? 'taker' : 'maker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); @@ -34540,11 +34419,11 @@ module.exports = class bitvavo extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -34592,13 +34471,12 @@ module.exports = class bitvavo extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'inOrder'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'inOrder'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDepositAddress (code, params = {}) { @@ -34648,7 +34526,7 @@ module.exports = class bitvavo extends Exchange { if (price !== undefined) { cost = amount * price; } else { - cost = this.safeFloat2 (params, 'cost', 'amountQuote'); + cost = this.safeNumber2 (params, 'cost', 'amountQuote'); } if (cost !== undefined) { const precision = market['precision']['price']; @@ -34661,7 +34539,7 @@ module.exports = class bitvavo extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['amount'] = this.amountToPrecision (symbol, amount); } else if (isStopMarket || isStopLimit) { - let stopPrice = this.safeFloat2 (params, 'stopPrice', 'triggerAmount'); + let stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerAmount'); if (stopPrice === undefined) { if (isStopLimit) { throw new ArgumentsRequired (this.id + ' createOrder requires a stopPrice parameter for a ' + type + ' order'); @@ -34723,7 +34601,7 @@ module.exports = class bitvavo extends Exchange { await this.loadMarkets (); const market = this.market (symbol); let request = {}; - const amountRemaining = this.safeFloat (params, 'amountRemaining'); + const amountRemaining = this.safeNumber (params, 'amountRemaining'); params = this.omit (params, 'amountRemaining'); if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); @@ -34788,7 +34666,6 @@ module.exports = class bitvavo extends Exchange { throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument'); } await this.loadMarkets (); - await this.loadMarkets (); const market = this.market (symbol); const request = { 'orderId': id, @@ -35014,26 +34891,13 @@ module.exports = class bitvavo extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let remaining = this.safeFloat (order, 'amountRemaining'); - let filled = this.safeFloat (order, 'filledAmount'); - const remainingCost = this.safeFloat (order, 'remainingCost'); - if ((remainingCost !== undefined) && (remainingCost === 0.0)) { - remaining = 0; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - const cost = this.safeFloat (order, 'filledAmountQuote'); - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amountRemaining'); + const filled = this.safeNumber (order, 'filledAmount'); + const cost = this.safeNumber (order, 'filledAmountQuote'); let fee = undefined; - const feeCost = this.safeFloat (order, 'feePaid'); + const feeCost = this.safeNumber (order, 'feePaid'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -35042,32 +34906,24 @@ module.exports = class bitvavo extends Exchange { 'currency': feeCurrencyCode, }; } - let lastTradeTimestamp = undefined; - const rawTrades = this.safeValue (order, 'fills'); - let trades = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'symbol': symbol, - 'order': id, - 'side': side, - }); - const numTrades = trades.length; - if (numTrades > 0) { - const lastTrade = this.safeValue (trades, numTrades - 1); - lastTradeTimestamp = lastTrade['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'symbol': symbol, + 'order': id, + 'side': side, + 'type': type, + }); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = this.safeValue (order, 'postOnly'); // https://github.com/ccxt/ccxt/issues/8489 - const stopPrice = this.safeFloat (order, 'triggerPrice'); - return { + const stopPrice = this.safeNumber (order, 'triggerPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -35077,13 +34933,13 @@ module.exports = class bitvavo extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -35278,11 +35134,11 @@ module.exports = class bitvavo extends Exchange { const currencyId = this.safeString (transaction, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -35373,7 +35229,7 @@ module.exports = class bitvavo extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],45:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],45:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -35435,7 +35291,7 @@ module.exports = class bitz extends Exchange { 'assets': 'https://{hostname}', }, 'www': 'https://www.bitz.com', - 'doc': 'https://apidoc.bitz.com/en/', + 'doc': 'https://apidocv2.bitz.plus/en/', 'fees': 'https://www.bitz.com/fee?type=1', 'referral': 'https://u.bitz.com/register?invite_code=1429193', }, @@ -35452,6 +35308,11 @@ module.exports = class bitz extends Exchange { 'currencyRate', 'currencyCoinRate', 'coinRate', + 'getContractCoin', + 'getContractKline', + 'getContractOrderBook', + 'getContractTradesHistory', + 'getContractTickers', ], }, 'trade': { @@ -35464,6 +35325,10 @@ module.exports = class bitz extends Exchange { 'getUserNowEntrustSheet', // open orders 'getEntrustSheetInfo', // order 'depositOrWithdraw', // transactions + 'getCoinAddress', + 'getCoinAddressList', + 'marketTrade', + 'addEntrustSheetBatch', ], }, 'assets': { @@ -35471,6 +35336,20 @@ module.exports = class bitz extends Exchange { 'getUserAssets', ], }, + 'contract': { + 'post': [ + 'addContractTrade', + 'cancelContractTrade', + 'getContractActivePositions', + 'getContractAccountInfo', + 'getContractMyPositions', + 'getContractOrderResult', + 'getContractTradeResult', + 'getContractOrder', + 'getContractMyHistoryTrade', + 'getContractMyTrades', + ], + }, }, 'fees': { 'trading': { @@ -35657,8 +35536,8 @@ module.exports = class bitz extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTrade'), - 'max': this.safeFloat (market, 'maxTrade'), + 'min': this.safeNumber (market, 'minTrade'), + 'max': this.safeNumber (market, 'maxTrade'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -35707,12 +35586,12 @@ module.exports = class bitz extends Exchange { const currencyId = this.safeString (balance, 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lock'); - account['total'] = this.safeFloat (balance, 'num'); - account['free'] = this.safeFloat (balance, 'over'); + account['used'] = this.safeString (balance, 'lock'); + account['total'] = this.safeString (balance, 'num'); + account['free'] = this.safeString (balance, 'over'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTicker (ticker, market = undefined) { @@ -35742,8 +35621,8 @@ module.exports = class bitz extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'now'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'now'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -35754,22 +35633,22 @@ module.exports = class bitz extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': undefined, 'open': open, 'close': last, 'last': last, 'previousClose': undefined, 'change': change, - 'percentage': this.safeFloat (ticker, 'priceChange24h'), + 'percentage': this.safeNumber (ticker, 'priceChange24h'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -35959,8 +35838,8 @@ module.exports = class bitz extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'p'); - const amount = this.safeFloat (trade, 'n'); + const price = this.safeNumber (trade, 'p'); + const amount = this.safeNumber (trade, 'n'); let cost = undefined; if (price !== undefined) { if (amount !== undefined) { @@ -36028,11 +35907,11 @@ module.exports = class bitz extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -36130,22 +36009,17 @@ module.exports = class bitz extends Exchange { if (side !== undefined) { side = (side === 'sale') ? 'sell' : 'buy'; } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'number'); - const remaining = this.safeFloat (order, 'numberOver'); - const filled = this.safeFloat (order, 'numberDeal'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'number'); + const remaining = this.safeNumber (order, 'numberOver'); + const filled = this.safeNumber (order, 'numberDeal'); let timestamp = this.safeInteger (order, 'timestamp'); if (timestamp === undefined) { timestamp = this.safeTimestamp (order, 'created'); } - let cost = this.safeFloat (order, 'orderTotalPrice'); - if (price !== undefined) { - if (filled !== undefined) { - cost = filled * price; - } - } + const cost = this.safeNumber (order, 'orderTotalPrice'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -36167,7 +36041,7 @@ module.exports = class bitz extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -36494,7 +36368,7 @@ module.exports = class bitz extends Exchange { const type = this.safeStringLower (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'network_fee'); + const feeCost = this.safeNumber (transaction, 'network_fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -36509,7 +36383,7 @@ module.exports = class bitz extends Exchange { 'address': this.safeString (transaction, 'wallet'), 'tag': this.safeString (transaction, 'memo'), 'type': type, - 'amount': this.safeFloat (transaction, 'number'), + 'amount': this.safeNumber (transaction, 'number'), 'currency': code, 'status': status, 'updated': timestamp, @@ -36661,12 +36535,13 @@ module.exports = class bitz extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],46:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],46:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -36745,17 +36620,19 @@ module.exports = class bl3p extends Exchange { const available = this.safeValue (wallet, 'available', {}); const balance = this.safeValue (wallet, 'balance', {}); const account = this.account (); - account['free'] = this.safeFloat (available, 'value'); - account['total'] = this.safeFloat (balance, 'value'); + account['free'] = this.safeString (available, 'value'); + account['total'] = this.safeString (balance, 'value'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { + const price = this.safeNumber (bidask, priceKey); + const size = this.safeNumber (bidask, amountKey); return [ - bidask[priceKey] / 100000.0, - bidask[amountKey] / 100000000.0, + price / 100000.0, + size / 100000000.0, ]; } @@ -36775,16 +36652,16 @@ module.exports = class bl3p extends Exchange { }; const ticker = await this.publicGetMarketTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -36794,7 +36671,7 @@ module.exports = class bl3p extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker['volume'], '24h'), + 'baseVolume': this.safeNumber (ticker['volume'], '24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -36803,20 +36680,13 @@ module.exports = class bl3p extends Exchange { parseTrade (trade, market = undefined) { const id = this.safeString (trade, 'trade_id'); const timestamp = this.safeInteger (trade, 'date'); - let price = this.safeFloat (trade, 'price_int'); - if (price !== undefined) { - price /= 100000.0; - } - let amount = this.safeFloat (trade, 'amount_int'); - if (amount !== undefined) { - amount /= 100000000.0; - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + let priceString = this.safeString (trade, 'price_int'); + priceString = Precise.stringDiv (priceString, '100000'); + let amountString = this.safeString (trade, 'amount_int'); + amountString = Precise.stringDiv (amountString, '100000000'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -36899,7 +36769,7 @@ module.exports = class bl3p extends Exchange { } }; -},{"./base/Exchange":6}],47:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],47:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -37065,8 +36935,8 @@ module.exports = class bleutrade extends Exchange { 'code': code, 'name': this.safeString (item, 'AssetLong'), 'active': this.safeValue (item, 'IsActive') && !this.safeValue (item, 'MaintenanceMode'), - 'fee': this.safeFloat (item, 'WithdrawTxFee'), - 'precision': this.safeFloat (item, 'DecimalPlaces'), + 'fee': this.safeNumber (item, 'WithdrawTxFee'), + 'precision': this.safeNumber (item, 'DecimalPlaces'), 'info': item, 'limits': this.limits, }; @@ -37118,7 +36988,7 @@ module.exports = class bleutrade extends Exchange { 'taker': this.fees['trading']['taker'], 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinTradeSize'), + 'min': this.safeNumber (market, 'MinTradeSize'), 'max': undefined, }, 'price': { @@ -37194,8 +37064,8 @@ module.exports = class bleutrade extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'TimeStamp')); const marketId = this.safeString (ticker, 'MarketName'); const symbol = this.safeSymbol (marketId, market, '_'); - const previous = this.safeFloat (ticker, 'PrevDay'); - const last = this.safeFloat (ticker, 'Last'); + const previous = this.safeNumber (ticker, 'PrevDay'); + const last = this.safeNumber (ticker, 'Last'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -37210,11 +37080,11 @@ module.exports = class bleutrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'High'), - 'low': this.safeFloat (ticker, 'Low'), - 'bid': this.safeFloat (ticker, 'Bid'), + 'high': this.safeNumber (ticker, 'High'), + 'low': this.safeNumber (ticker, 'Low'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': previous, @@ -37224,8 +37094,8 @@ module.exports = class bleutrade extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume'), - 'quoteVolume': this.safeFloat (ticker, 'BaseVolume'), + 'baseVolume': this.safeNumber (ticker, 'Volume'), + 'quoteVolume': this.safeNumber (ticker, 'BaseVolume'), 'info': ticker, }; } @@ -37233,11 +37103,11 @@ module.exports = class bleutrade extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (ohlcv['TimeStamp'] + '+00:00'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -37313,11 +37183,11 @@ module.exports = class bleutrade extends Exchange { const currencyId = this.safeString (item, 'Asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (item, 'Available'); - account['total'] = this.safeFloat (item, 'Balance'); + account['free'] = this.safeString (item, 'Available'); + account['total'] = this.safeString (item, 'Balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -37460,7 +37330,7 @@ module.exports = class bleutrade extends Exchange { // } const timestamp = this.parse8601 (this.safeString (item, 'TimeStamp')); - let amount = this.safeFloat (item, 'Amount'); + let amount = this.safeNumber (item, 'Amount'); let direction = undefined; if (amount !== undefined) { direction = 'in'; @@ -37534,27 +37404,12 @@ module.exports = class bleutrade extends Exchange { if ('Created' in order) { timestamp = this.parse8601 (order['Created'] + '+00:00'); } - let price = this.safeFloat (order, 'Price'); - let cost = undefined; - const amount = this.safeFloat (order, 'Quantity'); - const remaining = this.safeFloat (order, 'QuantityRemaining'); - let filled = undefined; - if (amount !== undefined && remaining !== undefined) { - filled = amount - remaining; - } - if (!cost) { - if (price && filled) { - cost = price * filled; - } - } - if (!price) { - if (cost && filled) { - price = cost / filled; - } - } - const average = this.safeFloat (order, 'PricePerUnit'); + const price = this.safeNumber (order, 'Price'); + const amount = this.safeNumber (order, 'Quantity'); + const remaining = this.safeNumber (order, 'QuantityRemaining'); + const average = this.safeNumber (order, 'PricePerUnit'); const id = this.safeString (order, 'OrderID'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -37568,15 +37423,15 @@ module.exports = class bleutrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -37613,7 +37468,7 @@ module.exports = class bleutrade extends Exchange { // Symbol: 'BTC' } // const id = this.safeString (transaction, 'ID'); - let amount = this.safeFloat (transaction, 'Amount'); + let amount = this.safeNumber (transaction, 'Amount'); let type = 'deposit'; if (amount < 0) { amount = Math.abs (amount); @@ -37715,13 +37570,14 @@ module.exports = class bleutrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],48:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],48:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -37902,11 +37758,11 @@ module.exports = class braziliex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': this.safeFloat (currency, 'txWithdrawalFee'), + 'fee': this.safeNumber (currency, 'txWithdrawalFee'), }, 'deposit': { 'active': canDeposit, - 'fee': this.safeFloat (currency, 'txDepositFee'), + 'fee': this.safeNumber (currency, 'txDepositFee'), }, }, 'limits': { @@ -37923,11 +37779,11 @@ module.exports = class braziliex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'MinWithdrawal'), + 'min': this.safeNumber (currency, 'MinWithdrawal'), 'max': Math.pow (10, precision), }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, }, @@ -37975,9 +37831,9 @@ module.exports = class braziliex extends Exchange { const quoteIsFiat = this.safeInteger (quoteCurrency, 'is_fiat', 0); let minCost = undefined; if (quoteIsFiat) { - minCost = this.safeFloat (baseCurrency, 'minAmountTradeFIAT'); + minCost = this.safeNumber (baseCurrency, 'minAmountTradeFIAT'); } else { - minCost = this.safeFloat (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); + minCost = this.safeNumber (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); } const isActive = this.safeInteger (market, 'active'); const active = (isActive === 1); @@ -38020,27 +37876,27 @@ module.exports = class braziliex extends Exchange { symbol = market['symbol']; } const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highestBid24'), - 'low': this.safeFloat (ticker, 'lowestAsk24'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'highestBid24'), + 'low': this.safeNumber (ticker, 'lowestAsk24'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'percentChange'), + 'change': this.safeNumber (ticker, 'percentChange'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume24'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume24'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24'), 'info': ticker, }; } @@ -38080,13 +37936,18 @@ module.exports = class braziliex extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString2 (trade, 'date_exec', 'date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } - const cost = this.safeFloat (trade, 'total'); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_number'); const type = 'limit'; const side = this.safeString (trade, 'type'); @@ -38128,11 +37989,11 @@ module.exports = class braziliex extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -38154,21 +38015,16 @@ module.exports = class braziliex extends Exchange { if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'date')); } - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'total', 0.0); - const amount = this.safeFloat (order, 'amount'); - const filledPercentage = this.safeFloat (order, 'progress'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'total'); + const amount = this.safeNumber (order, 'amount'); + const filledPercentage = this.safeNumber (order, 'progress'); const filled = amount * filledPercentage; - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); - let info = order; - if ('info' in info) { - info = order['info']; - } const id = this.safeString (order, 'order_number'); const fee = this.safeValue (order, 'fee'); // propagated from createOrder const status = (filledPercentage === 1.0) ? 'closed' : 'open'; const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -38185,12 +38041,12 @@ module.exports = class braziliex extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, - 'info': info, + 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -38242,7 +38098,7 @@ module.exports = class braziliex extends Exchange { 'price': this.safeString (priceParts, 1), 'total': this.safeString (totalParts, 1), 'fee': { - 'cost': this.safeFloat (feeParts, 1), + 'cost': this.safeNumber (feeParts, 1), 'currency': this.safeString (feeParts, 2), }, 'progress': '0.0', @@ -38359,13 +38215,14 @@ module.exports = class braziliex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],49:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],49:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -38507,8 +38364,8 @@ module.exports = class btcalpha extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -38560,14 +38417,11 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'id', 'tid'); const side = this.safeString2 (trade, 'my_side', 'side'); const orderId = this.safeString (trade, 'o_id'); @@ -38616,11 +38470,11 @@ module.exports = class btcalpha extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -38657,11 +38511,11 @@ module.exports = class btcalpha extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'reserve'); - account['total'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserve'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -38682,8 +38536,8 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (order, 'date'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString2 (order, 'oid', 'id'); let trades = this.safeValue (order, 'trades', []); @@ -38864,13 +38718,14 @@ module.exports = class btcalpha extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],50:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],50:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, InvalidOrder, AuthenticationError, PermissionDenied, InvalidNonce, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -38955,12 +38810,12 @@ module.exports = class btcbox extends Exchange { if (free in response) { const account = this.account (); const used = currencyId + '_lock'; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -38981,16 +38836,16 @@ module.exports = class btcbox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -39000,8 +38855,8 @@ module.exports = class btcbox extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -39025,14 +38880,11 @@ module.exports = class btcbox extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeString (trade, 'type'); return { @@ -39132,15 +38984,15 @@ module.exports = class btcbox extends Exchange { if (datetimeString !== undefined) { timestamp = this.parse8601 (order['datetime'] + '+09:00'); // Tokyo time } - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let cost = undefined; if (price !== undefined) { if (filled !== undefined) { @@ -39292,7 +39144,7 @@ module.exports = class btcbox extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],51:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],51:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -39541,11 +39393,11 @@ module.exports = class btcmarkets extends Exchange { const tagTo = tag; const addressFrom = undefined; const tagFrom = undefined; - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const currencyId = this.safeString (transaction, 'assetName'); const code = this.safeCurrencyCode (currencyId); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (fee) { amount -= fee; } @@ -39598,10 +39450,10 @@ module.exports = class btcmarkets extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const fees = this.safeValue (this.safeValue (this.options, 'fees', {}), quote, this.fees); - const pricePrecision = this.safeFloat (market, 'priceDecimals'); - const amountPrecision = this.safeFloat (market, 'amountDecimals'); - const minAmount = this.safeFloat (market, 'minOrderAmount'); - const maxAmount = this.safeFloat (market, 'maxOrderAmount'); + const pricePrecision = this.safeNumber (market, 'priceDecimals'); + const amountPrecision = this.safeNumber (market, 'amountDecimals'); + const minAmount = this.safeNumber (market, 'minOrderAmount'); + const maxAmount = this.safeNumber (market, 'maxOrderAmount'); let minPrice = undefined; if (quote === 'AUD') { minPrice = Math.pow (10, -pricePrecision); @@ -39660,14 +39512,12 @@ module.exports = class btcmarkets extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetName'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance, 'balance'); - const used = this.safeFloat (balance, 'locked'); const account = this.account (); - account['used'] = used; - account['total'] = total; + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -39683,11 +39533,11 @@ module.exports = class btcmarkets extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 0)), - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 2), // high - this.safeFloat (ohlcv, 3), // low - this.safeFloat (ohlcv, 4), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 2), // high + this.safeNumber (ohlcv, 3), // low + this.safeNumber (ohlcv, 4), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -39783,21 +39633,21 @@ module.exports = class btcmarkets extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'lastPrice'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); - const quoteVolume = this.safeFloat (ticker, 'volumeQte24h'); + const last = this.safeNumber (ticker, 'lastPrice'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); + const quoteVolume = this.safeNumber (ticker, 'volumeQte24h'); const vwap = this.vwap (baseVolume, quoteVolume); - const change = this.safeFloat (ticker, 'price24h'); - const percentage = this.safeFloat (ticker, 'pricePct24h'); + const change = this.safeNumber (ticker, 'price24h'); + const percentage = this.safeNumber (ticker, 'pricePct24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bestBid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'bestAsk'), + 'ask': this.safeNumber (ticker, 'bestAsk'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -39908,8 +39758,8 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -39918,7 +39768,7 @@ module.exports = class btcmarkets extends Exchange { } const orderId = this.safeString (trade, 'orderId'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -40009,7 +39859,7 @@ module.exports = class btcmarkets extends Exchange { } } if (triggerPriceIsRequired) { - const triggerPrice = this.safeFloat (params, 'triggerPrice'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); params = this.omit (params, 'triggerPrice'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a triggerPrice parameter for a ' + type + 'order'); @@ -40142,9 +39992,9 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const type = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'openAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'openAmount'); let filled = undefined; if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); @@ -40159,7 +40009,7 @@ module.exports = class btcmarkets extends Exchange { const id = this.safeString (order, 'orderId'); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -40351,13 +40201,14 @@ module.exports = class btcmarkets extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],52:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],52:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -40460,10 +40311,10 @@ module.exports = class btctradeua extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -40603,14 +40454,11 @@ module.exports = class btctradeua extends Exchange { const id = this.safeString (trade, 'id'); const type = 'limit'; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amnt_trade'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amnt_trade'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -40691,11 +40539,11 @@ module.exports = class btctradeua extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'amnt_trade'), + 'amount': this.safeNumber (order, 'amnt_trade'), 'filled': 0, - 'remaining': this.safeFloat (order, 'amnt_trade'), + 'remaining': this.safeNumber (order, 'amnt_trade'), 'trades': undefined, 'info': order, 'cost': undefined, @@ -40747,7 +40595,7 @@ module.exports = class btctradeua extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],53:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],53:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -40875,13 +40723,13 @@ module.exports = class btcturk extends Exchange { const used = currency['id'] + '_reserved'; if (free in response) { const account = this.account (); - account['free'] = this.safeFloat (response, free); - account['total'] = this.safeFloat (response, total); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['total'] = this.safeString (response, total); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -40901,26 +40749,26 @@ module.exports = class btcturk extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'average'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -40954,8 +40802,8 @@ module.exports = class btcturk extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -40997,11 +40845,11 @@ module.exports = class btcturk extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (this.safeString (ohlcv, 'Time')), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -41076,13 +40924,14 @@ module.exports = class btcturk extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],54:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],54:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { AddressPending, AuthenticationError, ExchangeError, NotSupported, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -41299,7 +41148,7 @@ module.exports = class buda extends Exchange { } const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); - const precision = this.safeFloat (currency, 'input_decimals'); + const precision = this.safeNumber (currency, 'input_decimals'); const minimum = Math.pow (10, -precision); result[code] = { 'id': id, @@ -41460,24 +41309,25 @@ module.exports = class buda extends Exchange { let timestamp = undefined; let side = undefined; const type = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; const order = undefined; const fee = undefined; let symbol = undefined; - let cost = undefined; if (market) { symbol = market['symbol']; } if (Array.isArray (trade)) { - timestamp = parseInt (trade[0]); - price = parseFloat (trade[1]); - amount = parseFloat (trade[2]); - cost = price * amount; - side = trade[3]; - id = trade[4].toString (); + timestamp = this.safeInteger (trade, 0); + priceString = this.safeString (trade, 1); + amountString = this.safeString (trade, 2); + side = this.safeString (trade, 3); + id = this.safeString (trade, 4); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': order, @@ -41532,11 +41382,11 @@ module.exports = class buda extends Exchange { const currencyId = this.safeString (balance, 'id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = parseFloat (balance['available_amount'][0]); - account['total'] = parseFloat (balance['amount'][0]); + account['free'] = this.safeString (balance['available_amount'], 0); + account['total'] = this.safeString (balance['amount'], 0); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -41644,15 +41494,15 @@ module.exports = class buda extends Exchange { const side = this.safeStringLower (order, 'type'); const status = this.parseOrderStatus (this.safeString (order, 'state')); const originalAmount = this.safeValue (order, 'original_amount', []); - const amount = this.safeFloat (originalAmount, 0); + const amount = this.safeNumber (originalAmount, 0); const remainingAmount = this.safeValue (order, 'amount', []); - const remaining = this.safeFloat (remainingAmount, 0); + const remaining = this.safeNumber (remainingAmount, 0); const tradedAmount = this.safeValue (order, 'traded_amount', []); - const filled = this.safeFloat (tradedAmount, 0); + const filled = this.safeNumber (tradedAmount, 0); const totalExchanged = this.safeValue (order, 'totalExchanged', []); - const cost = this.safeFloat (totalExchanged, 0); + const cost = this.safeNumber (totalExchanged, 0); const limitPrice = this.safeValue (order, 'limit', []); - let price = this.safeFloat (limitPrice, 0); + let price = this.safeNumber (limitPrice, 0); if (price === undefined) { if (limitPrice !== undefined) { price = limitPrice; @@ -41663,7 +41513,7 @@ module.exports = class buda extends Exchange { average = this.priceToPrecision (symbol, cost / filled); } const paidFee = this.safeValue (order, 'paid_fee', []); - const feeCost = this.safeFloat (paidFee, 0); + const feeCost = this.safeNumber (paidFee, 0); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (paidFee, 1); @@ -41902,13 +41752,14 @@ module.exports = class buda extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],55:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],55:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { RateLimitExceeded, BadSymbol, OrderNotFound, ExchangeError, AuthenticationError, ArgumentsRequired, ExchangeNotAvailable } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -42090,7 +41941,7 @@ module.exports = class bw extends Exchange { const symbol = base + '/' + quote; const state = this.safeInteger (market, 'state'); const active = (state === 1); - const fee = this.safeFloat (market, 'defaultFee'); + const fee = this.safeNumber (market, 'defaultFee'); result.push ({ 'id': id, 'active': active, @@ -42111,7 +41962,7 @@ module.exports = class bw extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -42197,11 +42048,11 @@ module.exports = class bw extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'drawFee'), + 'fee': this.safeNumber (currency, 'drawFee'), 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'limitAmount', 0), + 'min': this.safeNumber (currency, 'limitAmount', 0), 'max': undefined, }, 'price': { @@ -42214,7 +42065,7 @@ module.exports = class bw extends Exchange { }, 'withdraw': { 'min': undefined, - 'max': this.safeFloat (currency, 'onceDrawLimit'), + 'max': this.safeNumber (currency, 'onceDrawLimit'), }, }, }; @@ -42251,9 +42102,9 @@ module.exports = class bw extends Exchange { 'high': parseFloat (this.safeValue (ticker, 2)), 'low': parseFloat (this.safeValue (ticker, 3)), 'bid': parseFloat (this.safeValue (ticker, 7)), - 'bidVolume': this.safeFloat (bid, 'quantity'), + 'bidVolume': this.safeNumber (bid, 'quantity'), 'ask': parseFloat (this.safeValue (ticker, 8)), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, 'open': undefined, 'close': close, @@ -42382,8 +42233,11 @@ module.exports = class bw extends Exchange { // ... // const timestamp = this.safeTimestamp (trade, 2); - const price = this.safeFloat (trade, 5); - const amount = this.safeFloat (trade, 6); + const priceString = this.safeString (trade, 5); + const amountString = this.safeString (trade, 6); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 1); let symbol = undefined; if (marketId !== undefined) { @@ -42400,12 +42254,6 @@ module.exports = class bw extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const sideString = this.safeString (trade, 4); const side = (sideString === 'ask') ? 'sell' : 'buy'; return { @@ -42419,7 +42267,7 @@ module.exports = class bw extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': parseFloat (cost), + 'cost': cost, 'fee': undefined, 'info': trade, }; @@ -42476,11 +42324,11 @@ module.exports = class bw extends Exchange { // return [ this.safeTimestamp (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - this.safeFloat (ohlcv, 6), - this.safeFloat (ohlcv, 7), - this.safeFloat (ohlcv, 8), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + this.safeNumber (ohlcv, 6), + this.safeNumber (ohlcv, 7), + this.safeNumber (ohlcv, 8), ]; } @@ -42538,11 +42386,11 @@ module.exports = class bw extends Exchange { const currencyId = this.safeString (balance, 'currencyTypeId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'amount'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'amount'); + account['used'] = this.safeString (balance, 'freeze'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -42638,25 +42486,13 @@ module.exports = class bw extends Exchange { } else if (side === '1') { side = 'buy'; } - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'completeAmount'); - let remaining = this.safeFloat2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available - let cost = this.safeFloat (order, 'totalMoney'); - if (filled !== undefined) { - if (amount !== undefined) { - if (remaining === undefined) { - remaining = amount - filled; - } - } - if (cost === undefined) { - if (price !== undefined) { - cost = filled * cost; - } - } - } + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'completeAmount'); + const remaining = this.safeNumber2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available + const cost = this.safeNumber (order, 'totalMoney'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'entrustId'), 'clientOrderId': undefined, @@ -42678,7 +42514,7 @@ module.exports = class bw extends Exchange { 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -42974,12 +42810,12 @@ module.exports = class bw extends Exchange { code = currency['code']; } const type = ('depositId' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat2 (transaction, 'actuallyAmount', 'amount'); + const amount = this.safeNumber2 (transaction, 'actuallyAmount', 'amount'); const status = this.parseTransactionStatus (this.safeString2 (transaction, 'verifyStatus', 'state')); const timestamp = this.safeInteger (transaction, 'createTime'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -43110,7 +42946,7 @@ module.exports = class bw extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],56:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],56:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -43155,6 +42991,7 @@ module.exports = class bybit extends Exchange { 'fetchTrades': true, 'fetchTransactions': false, 'fetchWithdrawals': true, + 'fetchPositions': true, }, 'timeframes': { '1m': '1', @@ -43186,6 +43023,34 @@ module.exports = class bybit extends Exchange { 'referral': 'https://www.bybit.com/app/register?ref=X7Prm', }, 'api': { + 'futures': { + 'private': { + 'get': [ + 'position/list', + 'order/list', + 'order', + 'stop-order/list', + 'stop-order', + 'execution/list', + 'trade/closed-pnl/list', + ], + 'post': [ + 'order/create', + 'order/cancel', + 'order/cancelAll', + 'order/replace', + 'stop-order/create', + 'stop-order/cancel', + 'stop-order/cancelAll', + 'stop-order/replace', + 'position/change-position-margin', + 'position/trading-stop', + 'position/leverage/save', + 'position/switch-mode', + 'position/switch-isolated', + ], + }, + }, 'v2': { 'public': { 'get': [ @@ -43399,7 +43264,11 @@ module.exports = class bybit extends Exchange { 'LTC/USDT': 'linear', 'XTZ/USDT': 'linear', 'LINK/USDT': 'linear', + 'ADA/USDT': 'linear', + 'DOT/USDT': 'linear', + 'UNI/USDT': 'linear', }, + 'defaultType': 'linear', // may also be inverse or inverseFuture 'code': 'BTC', 'cancelAllOrders': { // 'method': 'v2PrivatePostOrderCancelAll', // v2PrivatePostStopOrderCancelAll @@ -43514,8 +43383,8 @@ module.exports = class bybit extends Exchange { const lotSizeFilter = this.safeValue (market, 'lot_size_filter', {}); const priceFilter = this.safeValue (market, 'price_filter', {}); const precision = { - 'amount': this.safeFloat (lotSizeFilter, 'qty_step'), - 'price': this.safeFloat (priceFilter, 'tick_size'), + 'amount': this.safeNumber (lotSizeFilter, 'qty_step'), + 'price': this.safeNumber (priceFilter, 'tick_size'), }; const status = this.safeString (market, 'status'); let active = undefined; @@ -43529,8 +43398,8 @@ module.exports = class bybit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'type': 'future', 'spot': false, 'future': true, @@ -43539,12 +43408,12 @@ module.exports = class bybit extends Exchange { 'inverse': inverse, 'limits': { 'amount': { - 'min': this.safeFloat (lotSizeFilter, 'min_trading_qty'), - 'max': this.safeFloat (lotSizeFilter, 'max_trading_qty'), + 'min': this.safeNumber (lotSizeFilter, 'min_trading_qty'), + 'max': this.safeNumber (lotSizeFilter, 'max_trading_qty'), }, 'price': { - 'min': this.safeFloat (priceFilter, 'min_price'), - 'max': this.safeFloat (priceFilter, 'max_price'), + 'min': this.safeNumber (priceFilter, 'min_price'), + 'max': this.safeNumber (priceFilter, 'max_price'), }, 'cost': { 'min': undefined, @@ -43590,9 +43459,9 @@ module.exports = class bybit extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const open = this.safeFloat (ticker, 'prev_price_24h'); - let percentage = this.safeFloat (ticker, 'price_24h_pcnt'); + const last = this.safeNumber (ticker, 'last_price'); + const open = this.safeNumber (ticker, 'prev_price_24h'); + let percentage = this.safeNumber (ticker, 'price_24h_pcnt'); if (percentage !== undefined) { percentage *= 100; } @@ -43602,18 +43471,18 @@ module.exports = class bybit extends Exchange { change = last - open; average = this.sum (open, last) / 2; } - const baseVolume = this.safeFloat (ticker, 'turnover_24h'); - const quoteVolume = this.safeFloat (ticker, 'volume_24h'); + const baseVolume = this.safeNumber (ticker, 'turnover_24h'); + const quoteVolume = this.safeNumber (ticker, 'volume_24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price_24h'), - 'low': this.safeFloat (ticker, 'low_price_24h'), - 'bid': this.safeFloat (ticker, 'bid_price'), + 'high': this.safeNumber (ticker, 'high_price_24h'), + 'low': this.safeNumber (ticker, 'low_price_24h'), + 'bid': this.safeNumber (ticker, 'bid_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask_price'), + 'ask': this.safeNumber (ticker, 'ask_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -43762,11 +43631,11 @@ module.exports = class bybit extends Exchange { // return [ this.safeTimestamp2 (ohlcv, 'open_time', 'start_at'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat2 (ohlcv, 'turnover', 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber2 (ohlcv, 'turnover', 'volume'), ]; } @@ -43892,9 +43761,9 @@ module.exports = class bybit extends Exchange { const marketId = this.safeString (trade, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat2 (trade, 'qty', 'exec_qty'); - let cost = this.safeFloat (trade, 'exec_value'); - const price = this.safeFloat2 (trade, 'exec_price', 'price'); + const amount = this.safeNumber2 (trade, 'qty', 'exec_qty'); + let cost = this.safeNumber (trade, 'exec_value'); + const price = this.safeNumber2 (trade, 'exec_price', 'price'); if (cost === undefined) { if (amount !== undefined) { if (price !== undefined) { @@ -43909,14 +43778,14 @@ module.exports = class bybit extends Exchange { const side = this.safeStringLower (trade, 'side'); const lastLiquidityInd = this.safeString (trade, 'last_liquidity_ind'); const takerOrMaker = (lastLiquidityInd === 'AddedLiquidity') ? 'maker' : 'taker'; - const feeCost = this.safeFloat (trade, 'exec_fee'); + const feeCost = this.safeNumber (trade, 'exec_fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyCode = market['inverse'] ? market['base'] : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'fee_rate'), + 'rate': this.safeNumber (trade, 'fee_rate'), }; } return { @@ -44076,12 +43945,12 @@ module.exports = class bybit extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['used'] = this.safeFloat (balance, 'used_margin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'used_margin'); + account['total'] = this.safeString (balance, 'equity'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -44208,56 +44077,42 @@ module.exports = class bybit extends Exchange { // const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); - let symbol = undefined; - let base = undefined; + const symbol = market['symbol']; + let feeCurrency = undefined; const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const id = this.safeString2 (order, 'order_id', 'stop_order_id'); const type = this.safeStringLower (order, 'order_type'); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - let average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'qty'); - let cost = this.safeFloat (order, 'cum_exec_value'); - let filled = this.safeFloat (order, 'cum_exec_qty'); - let remaining = this.safeFloat (order, 'leaves_qty'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'qty'); + const cost = this.safeNumber (order, 'cum_exec_value'); + const filled = this.safeNumber (order, 'cum_exec_qty'); + const remaining = this.safeNumber (order, 'leaves_qty'); + const marketTypes = this.safeValue (this.options, 'marketTypes', {}); + const marketType = this.safeString (marketTypes, symbol); if (market !== undefined) { - symbol = market['symbol']; - base = market['base']; + if (marketType === 'linear') { + feeCurrency = market['quote']; + } else { + feeCurrency = market['base']; + } } let lastTradeTimestamp = this.safeTimestamp (order, 'last_exec_time'); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = amount - remaining; - } - if (filled !== undefined) { - if ((remaining === undefined) && (amount !== undefined)) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if ((type === 'market') && (cost !== undefined) && (cost > 0)) { - price = undefined; - if (average === undefined) { - average = filled / cost; - } - } - } const status = this.parseOrderStatus (this.safeString2 (order, 'order_status', 'stop_order_status')); const side = this.safeStringLower (order, 'side'); - let feeCost = this.safeFloat (order, 'cum_exec_fee'); + let feeCost = this.safeNumber (order, 'cum_exec_fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); fee = { 'cost': feeCost, - 'currency': base, + 'currency': feeCurrency, }; } let clientOrderId = this.safeString (order, 'order_link_id'); @@ -44265,9 +44120,9 @@ module.exports = class bybit extends Exchange { clientOrderId = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'stop_px'); + const stopPrice = this.safeNumber (order, 'stop_px'); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -44289,7 +44144,7 @@ module.exports = class bybit extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -45140,7 +44995,8 @@ module.exports = class bybit extends Exchange { const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); + const type = this.safeStringLower (transaction, 'type'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -45160,8 +45016,8 @@ module.exports = class bybit extends Exchange { 'tag': undefined, 'tagTo': undefined, 'tagFrom': undefined, - 'type': 'withdrawal', - 'amount': this.safeFloat (transaction, 'amount'), + 'type': type, + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -45244,8 +45100,8 @@ module.exports = class bybit extends Exchange { // const currencyId = this.safeString (item, 'coin'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'wallet_balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'wallet_balance'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -45311,7 +45167,8 @@ module.exports = class bybit extends Exchange { 'recv_window': this.options['recvWindow'], 'timestamp': timestamp, }); - const auth = this.rawencode (this.keysort (query)); + const sortedQuery = this.keysort (query); + const auth = this.rawencode (sortedQuery); const signature = this.hmac (this.encode (auth), this.encode (this.secret)); if (method === 'POST') { body = this.json (this.extend (query, { @@ -45321,7 +45178,7 @@ module.exports = class bybit extends Exchange { 'Content-Type': 'application/json', }; } else { - request += '?' + auth + '&sign=' + signature; + request += '?' + this.urlencode (sortedQuery) + '&sign=' + signature; } } url += request; @@ -45344,17 +45201,48 @@ module.exports = class bybit extends Exchange { // time_now: '1583934106.590436' // } // - const errorCode = this.safeValue (response, 'ret_code'); - if (errorCode !== 0) { + const errorCode = this.safeString (response, 'ret_code'); + if (errorCode !== '0') { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback); this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback); throw new ExchangeError (feedback); // unknown message } } + + async fetchPositions (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (Array.isArray (symbols)) { + const length = symbols.length; + if (length !== 1) { + throw new ArgumentsRequired (this.id + ' fetchPositions takes exactly one symbol'); + } + request['symbol'] = this.marketId (symbols[0]); + } + const defaultType = this.safeString (this.options, 'defaultType', 'linear'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + let response = undefined; + if (type === 'linear') { + response = await this.privateLinearGetPositionList (this.extend (request, params)); + } else if (type === 'inverse') { + response = await this.v2PrivateGetPositionList (this.extend (request, params)); + } else if (type === 'inverseFuture') { + response = await this.futuresPrivateGetPositionList (this.extend (request, params)); + } + // { + // ret_code: 0, + // ret_msg: 'OK', + // ext_code: '', + // ext_info: '', + // result: [] or {} depending on the request + // } + return this.safeValue (response, 'result'); + } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],57:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],57:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -45543,12 +45431,12 @@ module.exports = class bytetrade extends Exchange { const limits = this.safeValue (currency, 'limits'); const deposit = this.safeValue (limits, 'deposit'); const amountPrecision = this.safeInteger (currency, 'basePrecision'); - let maxDeposit = this.safeFloat (deposit, 'max'); + let maxDeposit = this.safeNumber (deposit, 'max'); if (maxDeposit === -1.0) { maxDeposit = undefined; } const withdraw = this.safeValue (limits, 'withdraw'); - let maxWithdraw = this.safeFloat (withdraw, 'max'); + let maxWithdraw = this.safeNumber (withdraw, 'max'); if (maxWithdraw === -1.0) { maxWithdraw = undefined; } @@ -45564,11 +45452,11 @@ module.exports = class bytetrade extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (deposit, 'min'), + 'min': this.safeNumber (deposit, 'min'), 'max': maxDeposit, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'min'), + 'min': this.safeNumber (withdraw, 'min'), 'max': maxWithdraw, }, }, @@ -45622,12 +45510,12 @@ module.exports = class bytetrade extends Exchange { 'normalSymbol': normalSymbol, 'limits': { 'amount': { - 'min': this.safeFloat (amount, 'min'), - 'max': this.safeFloat (amount, 'max'), + 'min': this.safeNumber (amount, 'min'), + 'max': this.safeNumber (amount, 'max'), }, 'price': { - 'min': this.safeFloat (price, 'min'), - 'max': this.safeFloat (price, 'max'), + 'min': this.safeNumber (price, 'min'), + 'max': this.safeNumber (price, 'max'), }, 'cost': { 'min': undefined, @@ -45655,11 +45543,11 @@ module.exports = class bytetrade extends Exchange { const currencyId = this.safeString (balance, 'code'); const code = this.safeCurrencyCode (currencyId, undefined); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'used'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'used'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -45720,22 +45608,22 @@ module.exports = class bytetrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'open'), - 'close': this.safeFloat (ticker, 'close'), - 'last': this.safeFloat (ticker, 'last'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'open'), + 'close': this.safeNumber (ticker, 'close'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, // previous day close - 'change': this.safeFloat (ticker, 'change'), - 'percentage': this.safeFloat (ticker, 'percentage'), + 'change': this.safeNumber (ticker, 'change'), + 'percentage': this.safeNumber (ticker, 'percentage'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -45778,24 +45666,16 @@ module.exports = class bytetrade extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetDepth (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetDepth (params); + return this.parseTickers (response, symbols); } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetTickers (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetTickers (params); + return this.parseTickers (response, symbols); } parseOHLCV (ohlcv, market = undefined) { @@ -45811,11 +45691,11 @@ module.exports = class bytetrade extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -45845,9 +45725,9 @@ module.exports = class bytetrade extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeInteger (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - const cost = this.safeFloat (trade, 'cost'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + const cost = this.safeNumber (trade, 'cost'); const id = this.safeString (trade, 'id'); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'takerOrMaker'); @@ -45917,12 +45797,12 @@ module.exports = class bytetrade extends Exchange { const timestamp = this.safeInteger (order, 'timestamp'); const datetime = this.safeString (order, 'datetime'); const lastTradeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled'); - const remaining = this.safeFloat (order, 'remaining'); - const cost = this.safeFloat (order, 'cost'); - const average = this.safeFloat (order, 'average'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled'); + const remaining = this.safeNumber (order, 'remaining'); + const cost = this.safeNumber (order, 'cost'); + const average = this.safeNumber (order, 'average'); const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); @@ -46315,7 +46195,7 @@ module.exports = class bytetrade extends Exchange { }; } - async transfer (code, amount, address, message = '', params = {}) { + async transfer (code, amount, fromAccount, toAccount, params = {}) { this.checkRequiredDependencies (); if (this.apiKey === undefined) { throw new ArgumentsRequired ('transfer() requires this.apiKey'); @@ -46333,6 +46213,7 @@ module.exports = class bytetrade extends Exchange { expirationDatetime = expirationDatetime.split ('.')[0]; const feeAmount = '300000000000000'; const defaultDappId = 'Sagittarius'; + const message = this.safeString (params, 'message', ''); const dappId = this.safeString (params, 'dappId', defaultDappId); const eightBytes = this.integerPow ('2', '64'); const byteStringArray = [ @@ -46346,8 +46227,8 @@ module.exports = class bytetrade extends Exchange { this.numberToLE (feeAmount, 8), // string for 32 bit php this.numberToLE (this.apiKey.length, 1), this.stringToBinary (this.encode (this.apiKey)), - this.numberToLE (address.length, 1), - this.stringToBinary (this.encode (address)), + this.numberToLE (toAccount.length, 1), + this.stringToBinary (this.encode (toAccount)), this.numberToLE (assetType, 4), this.numberToLE (this.integerDivide (amountChain, eightBytes), 8), this.numberToLE (this.integerModulo (amountChain, eightBytes), 8), @@ -46368,7 +46249,7 @@ module.exports = class bytetrade extends Exchange { const operation = { 'fee': '300000000000000', 'from': this.apiKey, - 'to': address, + 'to': toAccount, 'asset_type': parseInt (currency['id']), 'amount': amountChain.toString (), 'message': message, @@ -46522,9 +46403,9 @@ module.exports = class bytetrade extends Exchange { const datetime = this.safeString (transaction, 'datetime'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const feeInfo = this.safeValue (transaction, 'fee'); - const feeCost = this.safeFloat (feeInfo, 'cost'); + const feeCost = this.safeNumber (feeInfo, 'cost'); const feeCurrencyId = this.safeString (feeInfo, 'code'); const feeCode = this.safeCurrencyCode (feeCurrencyId, currency); const fee = { @@ -46787,7 +46668,7 @@ module.exports = class bytetrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],58:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],58:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -46822,7 +46703,7 @@ module.exports = class cdax extends huobipro { } }; -},{"./huobipro.js":96}],59:[function(require,module,exports){ +},{"./huobipro.js":94}],59:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -47081,7 +46962,7 @@ module.exports = class cex extends Exchange { 'fee': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimumCurrencyAmount'), + 'min': this.safeNumber (currency, 'minimumCurrencyAmount'), 'max': undefined, }, 'price': { @@ -47093,7 +46974,7 @@ module.exports = class cex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimalWithdrawalAmount'), + 'min': this.safeNumber (currency, 'minimalWithdrawalAmount'), 'max': undefined, }, }, @@ -47176,15 +47057,15 @@ module.exports = class cex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minLotSize'), - 'max': this.safeFloat (market, 'maxLotSize'), + 'min': this.safeNumber (market, 'minLotSize'), + 'max': this.safeNumber (market, 'maxLotSize'), }, 'price': { - 'min': this.safeFloat (market, 'minPrice'), - 'max': this.safeFloat (market, 'maxPrice'), + 'min': this.safeNumber (market, 'minPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { - 'min': this.safeFloat (market, 'minLotSizeS2'), + 'min': this.safeNumber (market, 'minLotSizeS2'), 'max': undefined, }, }, @@ -47205,13 +47086,13 @@ module.exports = class cex extends Exchange { const currencyId = currencyIds[i]; const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); + account['free'] = this.safeString (balance, 'available'); // https://github.com/ccxt/ccxt/issues/5484 - account['used'] = this.safeFloat (balance, 'orders', 0.0); + account['used'] = this.safeString (balance, 'orders', '0'); const code = this.safeCurrencyCode (currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -47240,11 +47121,11 @@ module.exports = class cex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -47286,12 +47167,12 @@ module.exports = class cex extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const volume = this.safeFloat (ticker, 'volume'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'last'); + const volume = this.safeNumber (ticker, 'volume'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'last'); let symbol = undefined; if (market) { symbol = market['symbol']; @@ -47353,8 +47234,8 @@ module.exports = class cex extends Exchange { const id = this.safeString (trade, 'tid'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -47426,8 +47307,8 @@ module.exports = class cex extends Exchange { // "complete": false // } // - const placedAmount = this.safeFloat (response, 'amount'); - const remaining = this.safeFloat (response, 'pending'); + const placedAmount = this.safeNumber (response, 'amount'); + const remaining = this.safeNumber (response, 'pending'); const timestamp = this.safeValue (response, 'time'); const complete = this.safeValue (response, 'complete'); const status = complete ? 'closed' : 'open'; @@ -47446,7 +47327,7 @@ module.exports = class cex extends Exchange { 'side': this.safeString (response, 'type'), 'symbol': symbol, 'status': status, - 'price': this.safeFloat (response, 'price'), + 'price': this.safeNumber (response, 'price'), 'amount': placedAmount, 'cost': undefined, 'average': undefined, @@ -47488,42 +47369,42 @@ module.exports = class cex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - let amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + let amount = this.safeNumber (order, 'amount'); // sell orders can have a negative amount // https://github.com/ccxt/ccxt/issues/5338 if (amount !== undefined) { amount = Math.abs (amount); } - const remaining = this.safeFloat2 (order, 'pending', 'remains'); + const remaining = this.safeNumber2 (order, 'pending', 'remains'); const filled = amount - remaining; let fee = undefined; let cost = undefined; if (market !== undefined) { symbol = market['symbol']; - const taCost = this.safeFloat (order, 'ta:' + market['quote']); - const ttaCost = this.safeFloat (order, 'tta:' + market['quote']); + const taCost = this.safeNumber (order, 'ta:' + market['quote']); + const ttaCost = this.safeNumber (order, 'tta:' + market['quote']); cost = this.sum (taCost, ttaCost); const baseFee = 'fa:' + market['base']; const baseTakerFee = 'tfa:' + market['base']; const quoteFee = 'fa:' + market['quote']; const quoteTakerFee = 'tfa:' + market['quote']; - let feeRate = this.safeFloat (order, 'tradingFeeMaker'); + let feeRate = this.safeNumber (order, 'tradingFeeMaker'); if (!feeRate) { - feeRate = this.safeFloat (order, 'tradingFeeTaker', feeRate); + feeRate = this.safeNumber (order, 'tradingFeeTaker', feeRate); } if (feeRate) { feeRate /= 100.0; // convert to mathematically-correct percentage coefficients: 1.0 = 100% } if ((baseFee in order) || (baseTakerFee in order)) { - const baseFeeCost = this.safeFloat2 (order, baseFee, baseTakerFee); + const baseFeeCost = this.safeNumber2 (order, baseFee, baseTakerFee); fee = { 'currency': market['base'], 'rate': feeRate, 'cost': baseFeeCost, }; } else if ((quoteFee in order) || (quoteTakerFee in order)) { - const quoteFeeCost = this.safeFloat2 (order, quoteFee, quoteTakerFee); + const quoteFeeCost = this.safeNumber2 (order, quoteFee, quoteTakerFee); fee = { 'currency': market['quote'], 'rate': feeRate, @@ -47563,7 +47444,7 @@ module.exports = class cex extends Exchange { // ds: 0 } continue; } - const tradePrice = this.safeFloat (item, 'price'); + const tradePrice = this.safeNumber (item, 'price'); if (tradePrice === undefined) { // this represents the order // { @@ -47667,8 +47548,8 @@ module.exports = class cex extends Exchange { // "fee_amount": "0.03" // } const tradeTimestamp = this.parse8601 (this.safeString (item, 'time')); - const tradeAmount = this.safeFloat (item, 'amount'); - const feeCost = this.safeFloat (item, 'fee_amount'); + const tradeAmount = this.safeNumber (item, 'amount'); + const feeCost = this.safeNumber (item, 'fee_amount'); let absTradeAmount = (tradeAmount < 0) ? -tradeAmount : tradeAmount; let tradeCost = undefined; if (tradeSide === 'sell') { @@ -48013,12 +47894,12 @@ module.exports = class cex extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const side = this.safeString (order, 'type'); - const baseAmount = this.safeFloat (order, 'a:' + baseId + ':cds'); - const quoteAmount = this.safeFloat (order, 'a:' + quoteId + ':cds'); - const fee = this.safeFloat (order, 'f:' + quoteId + ':cds'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const remaining = this.safeFloat (order, 'remains'); + const baseAmount = this.safeNumber (order, 'a:' + baseId + ':cds'); + const quoteAmount = this.safeNumber (order, 'a:' + quoteId + ':cds'); + const fee = this.safeNumber (order, 'f:' + quoteId + ':cds'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const remaining = this.safeNumber (order, 'remains'); const filled = amount - remaining; let orderAmount = undefined; let cost = undefined; @@ -48030,10 +47911,10 @@ module.exports = class cex extends Exchange { cost = quoteAmount; average = orderAmount / cost; } else { - const ta = this.safeFloat (order, 'ta:' + quoteId, 0); - const tta = this.safeFloat (order, 'tta:' + quoteId, 0); - const fa = this.safeFloat (order, 'fa:' + quoteId, 0); - const tfa = this.safeFloat (order, 'tfa:' + quoteId, 0); + const ta = this.safeNumber (order, 'ta:' + quoteId, 0); + const tta = this.safeNumber (order, 'tta:' + quoteId, 0); + const fa = this.safeNumber (order, 'fa:' + quoteId, 0); + const tfa = this.safeNumber (order, 'tfa:' + quoteId, 0); if (side === 'sell') { cost = this.sum (this.sum (ta, tta), this.sum (fa, tfa)); } else { @@ -48172,47 +48053,14 @@ module.exports = class cex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],60:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const foxbit = require ('./foxbit.js'); - -// --------------------------------------------------------------------------- - -module.exports = class chilebit extends foxbit { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'chilebit', - 'name': 'ChileBit', - 'countries': [ 'CL' ], - 'has': { - 'CORS': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg', - 'api': { - 'public': 'https://api.blinktrade.com/api', - 'private': 'https://api.blinktrade.com/tapi', - }, - 'www': 'https://chilebit.net', - 'doc': 'https://blinktrade.com/docs', - }, - 'options': { - 'brokerId': '9', // https://blinktrade.com/docs/#brokers - }, - }); - } -}; - -},{"./foxbit.js":87}],61:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],60:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, RateLimitExceeded, InvalidNonce } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -48620,10 +48468,10 @@ module.exports = class coinbase extends Exchange { const timestamp = this.parse8601 (this.safeValue (transaction, 'created_at')); const updated = this.parse8601 (this.safeValue (transaction, 'updated_at')); const type = this.safeString (transaction, 'resource'); - const amount = this.safeFloat (subtotalObject, 'amount'); + const amount = this.safeNumber (subtotalObject, 'amount'); const currencyId = this.safeString (subtotalObject, 'currency'); const currency = this.safeCurrencyCode (currencyId); - const feeCost = this.safeFloat (feeObject, 'amount'); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -48699,15 +48547,12 @@ module.exports = class coinbase extends Exchange { const orderId = undefined; const side = this.safeString (trade, 'resource'); const type = undefined; - const cost = this.safeFloat (subtotalObject, 'amount'); - const amount = this.safeFloat (amountObject, 'amount'); - let price = undefined; - if (cost !== undefined) { - if ((amount !== undefined) && (amount > 0)) { - price = cost / amount; - } - } - const feeCost = this.safeFloat (feeObject, 'amount'); + const costString = this.safeString (subtotalObject, 'amount'); + const amountString = this.safeString (amountObject, 'amount'); + const cost = this.parseNumber (costString); + const amount = this.parseNumber (amountString); + const price = this.parseNumber (Precise.stringDiv (costString, amountString)); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -48775,7 +48620,7 @@ module.exports = class coinbase extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (quoteCurrency, 'min_size'), + 'min': this.safeNumber (quoteCurrency, 'min_size'), 'max': undefined, }, }, @@ -48857,7 +48702,7 @@ module.exports = class coinbase extends Exchange { 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min_size'), + 'min': this.safeNumber (currency, 'min_size'), 'max': undefined, }, 'price': { @@ -48888,9 +48733,9 @@ module.exports = class coinbase extends Exchange { const buy = await this.publicGetPricesSymbolBuy (request); const sell = await this.publicGetPricesSymbolSell (request); const spot = await this.publicGetPricesSymbolSpot (request); - const ask = this.safeFloat (buy['data'], 'amount'); - const bid = this.safeFloat (sell['data'], 'amount'); - const last = this.safeFloat (spot['data'], 'amount'); + const ask = this.safeNumber (buy['data'], 'amount'); + const bid = this.safeNumber (sell['data'], 'amount'); + const last = this.safeNumber (spot['data'], 'amount'); return { 'symbol': symbol, 'timestamp': timestamp, @@ -48933,7 +48778,7 @@ module.exports = class coinbase extends Exchange { if (this.inArray (balance['type'], accounts)) { const currencyId = this.safeString (balance['balance'], 'currency'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance['balance'], 'amount'); + const total = this.safeNumber (balance['balance'], 'amount'); const free = total; const used = undefined; if (code in result) { @@ -49234,7 +49079,7 @@ module.exports = class coinbase extends Exchange { // } // const amountInfo = this.safeValue (item, 'amount', {}); - let amount = this.safeFloat (amountInfo, 'amount'); + let amount = this.safeNumber (amountInfo, 'amount'); let direction = undefined; if (amount < 0) { direction = 'out'; @@ -49260,7 +49105,7 @@ module.exports = class coinbase extends Exchange { if (feeInfo !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId, currency); - const feeAmount = this.safeFloat (feeInfo, 'amount'); + const feeAmount = this.safeNumber (feeInfo, 'amount'); fee = { 'cost': feeAmount, 'currency': feeCurrencyCode, @@ -49424,7 +49269,7 @@ module.exports = class coinbase extends Exchange { }; -},{"./base/Exchange":6,"./base/errors":8}],62:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],61:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -49457,7 +49302,7 @@ module.exports = class coinbaseprime extends coinbasepro { } }; -},{"./coinbasepro.js":63}],63:[function(require,module,exports){ +},{"./coinbasepro.js":62}],62:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -49465,6 +49310,7 @@ module.exports = class coinbaseprime extends coinbasepro { const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ArgumentsRequired, ExchangeError, InvalidOrder, InvalidAddress, AuthenticationError, NotSupported, OrderNotFound, OnMaintenance, PermissionDenied, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -49699,7 +49545,7 @@ module.exports = class coinbasepro extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const details = this.safeValue (currency, 'details', {}); - const precision = this.safeFloat (currency, 'max_precision'); + const precision = this.safeNumber (currency, 'max_precision'); const status = this.safeString (currency, 'status'); const active = (status === 'online'); result[code] = { @@ -49713,7 +49559,7 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (details, 'min_size'), + 'min': this.safeNumber (details, 'min_size'), 'max': undefined, }, 'price': { @@ -49725,7 +49571,7 @@ module.exports = class coinbasepro extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (details, 'min_withdrawal_amount'), + 'min': this.safeNumber (details, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -49769,12 +49615,12 @@ module.exports = class coinbasepro extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const priceLimits = { - 'min': this.safeFloat (market, 'quote_increment'), + 'min': this.safeNumber (market, 'quote_increment'), 'max': undefined, }; const precision = { - 'amount': this.safeFloat (market, 'base_increment'), - 'price': this.safeFloat (market, 'quote_increment'), + 'amount': this.safeNumber (market, 'base_increment'), + 'price': this.safeNumber (market, 'quote_increment'), }; const status = this.safeString (market, 'status'); const active = (status === 'online'); @@ -49788,13 +49634,13 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': priceLimits, 'cost': { - 'min': this.safeFloat (market, 'min_market_funds'), - 'max': this.safeFloat (market, 'max_market_funds'), + 'min': this.safeNumber (market, 'min_market_funds'), + 'max': this.safeNumber (market, 'max_market_funds'), }, }, 'active': active, @@ -49851,14 +49697,13 @@ module.exports = class coinbasepro extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'hold'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'hold'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -49915,29 +49760,29 @@ module.exports = class coinbasepro extends Exchange { // } // const timestamp = this.parse8601 (this.safeValue (ticker, 'time')); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'price'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'price'); const symbol = (market === undefined) ? undefined : market['symbol']; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': undefined, 'ask': ask, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -50010,7 +49855,7 @@ module.exports = class coinbasepro extends Exchange { if (market !== undefined) { const feeCurrencyId = this.safeStringLower (market, 'quoteId'); const costField = feeCurrencyId + '_value'; - cost = this.safeFloat (trade, costField); + cost = this.safeNumber (trade, costField); feeCurrency = market['quote']; const liquidity = this.safeString (trade, 'liquidity'); if (liquidity !== undefined) { @@ -50018,7 +49863,7 @@ module.exports = class coinbasepro extends Exchange { feeRate = market[takerOrMaker]; } } - const feeCost = this.safeFloat2 (trade, 'fill_fees', 'fee'); + const feeCost = this.safeNumber2 (trade, 'fill_fees', 'fee'); const fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -50032,10 +49877,12 @@ module.exports = class coinbasepro extends Exchange { if (orderId !== undefined) { side = (trade['side'] === 'buy') ? 'buy' : 'sell'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - cost = amount * price; + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -50097,11 +49944,11 @@ module.exports = class coinbasepro extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -50181,17 +50028,11 @@ module.exports = class coinbasepro extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'filled_size'); - const amount = this.safeFloat (order, 'size', filled); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'executed_value'); - const feeCost = this.safeFloat (order, 'fill_fees'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'filled_size'); + const amount = this.safeNumber (order, 'size', filled); + const cost = this.safeNumber (order, 'executed_value'); + const feeCost = this.safeNumber (order, 'fill_fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -50209,9 +50050,9 @@ module.exports = class coinbasepro extends Exchange { const side = this.safeString (order, 'side'); const timeInForce = this.safeString (order, 'time_in_force'); const postOnly = this.safeValue (order, 'post_only'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -50229,11 +50070,11 @@ module.exports = class coinbasepro extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -50323,7 +50164,7 @@ module.exports = class coinbasepro extends Exchange { request['client_oid'] = clientOrderId; params = this.omit (params, [ 'clientOrderId', 'client_oid' ]); } - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop_price'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stop_price'); if (stopPrice !== undefined) { request['stop_price'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, [ 'stopPrice', 'stop_price' ]); @@ -50337,7 +50178,7 @@ module.exports = class coinbasepro extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['size'] = this.amountToPrecision (symbol, amount); } else if (type === 'market') { - let cost = this.safeFloat2 (params, 'cost', 'funds'); + let cost = this.safeNumber2 (params, 'cost', 'funds'); if (cost === undefined) { if (price !== undefined) { cost = amount * price; @@ -50408,19 +50249,6 @@ module.exports = class coinbasepro extends Exchange { return await this.privateDeleteOrders (this.extend (request, params)); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - const cost = amount * price; - const currency = market['quote']; - return { - 'type': takerOrMaker, - 'currency': currency, - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (currency, rate * cost)), - }; - } - async fetchPaymentMethods (params = {}) { return await this.privateGetPaymentMethods (params); } @@ -50559,7 +50387,7 @@ module.exports = class coinbasepro extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (transaction); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let type = this.safeString (transaction, 'type'); let address = this.safeString (details, 'crypto_address'); const tag = this.safeString (details, 'destination_tag'); @@ -50568,7 +50396,7 @@ module.exports = class coinbasepro extends Exchange { if (type === 'withdraw') { type = 'withdrawal'; address = this.safeString (details, 'sent_to_address', address); - const feeCost = this.safeFloat (details, 'fee'); + const feeCost = this.safeNumber (details, 'fee'); if (feeCost !== undefined) { if (amount !== undefined) { amount -= feeCost; @@ -50682,13 +50510,14 @@ module.exports = class coinbasepro extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],64:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],63:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -50812,12 +50641,12 @@ module.exports = class coincheck extends Exchange { if (currencyId in balances) { const account = this.account (); const reserved = currencyId + '_reserved'; - account['free'] = this.safeFloat (balances, currencyId); - account['used'] = this.safeFloat (balances, reserved); + account['free'] = this.safeString (balances, currencyId); + account['used'] = this.safeString (balances, reserved); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -50855,23 +50684,13 @@ module.exports = class coincheck extends Exchange { const id = this.safeString (order, 'id'); const side = this.safeString (order, 'order_type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const amount = this.safeFloat (order, 'pending_amount'); - const remaining = this.safeFloat (order, 'pending_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = Math.max (amount - remaining, 0); - if (price !== undefined) { - cost = filled * price; - } - } - } + const amount = this.safeNumber (order, 'pending_amount'); + const remaining = this.safeNumber (order, 'pending_amount'); + const price = this.safeNumber (order, 'rate'); const status = undefined; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -50879,7 +50698,7 @@ module.exports = class coincheck extends Exchange { 'lastTradeTimestamp': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'side': side, 'type': undefined, 'timeInForce': undefined, @@ -50888,12 +50707,12 @@ module.exports = class coincheck extends Exchange { 'symbol': symbol, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'info': order, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -50917,16 +50736,16 @@ module.exports = class coincheck extends Exchange { }; const ticker = await this.publicGetTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -50936,7 +50755,7 @@ module.exports = class coincheck extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -50945,7 +50764,7 @@ module.exports = class coincheck extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'rate'); + const priceString = this.safeString (trade, 'rate'); const marketId = this.safeString (trade, 'pair'); market = this.safeValue (this.markets_by_id, marketId, market); let symbol = undefined; @@ -50972,7 +50791,7 @@ module.exports = class coincheck extends Exchange { } } let takerOrMaker = undefined; - let amount = undefined; + let amountString = undefined; let cost = undefined; let side = undefined; let fee = undefined; @@ -50984,24 +50803,22 @@ module.exports = class coincheck extends Exchange { takerOrMaker = 'maker'; } const funds = this.safeValue (trade, 'funds', {}); - amount = this.safeFloat (funds, baseId); - cost = this.safeFloat (funds, quoteId); + amountString = this.safeString (funds, baseId); + cost = this.safeNumber (funds, quoteId); fee = { 'currency': this.safeString (trade, 'fee_currency'), - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), }; side = this.safeString (trade, 'side'); orderId = this.safeString (trade, 'order_id'); } else { - amount = this.safeFloat (trade, 'amount'); + amountString = this.safeString (trade, 'amount'); side = this.safeString (trade, 'order_type'); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -51072,6 +50889,10 @@ module.exports = class coincheck extends Exchange { return await this.privateDeleteExchangeOrdersId (this.extend (request, params)); } + nonce () { + return this.milliseconds (); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let url = this.urls['api'] + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); @@ -51118,13 +50939,14 @@ module.exports = class coincheck extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],65:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],64:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -51335,8 +51157,8 @@ module.exports = class coinegg extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; let change = undefined; let average = undefined; @@ -51350,11 +51172,11 @@ module.exports = class coinegg extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -51364,8 +51186,8 @@ module.exports = class coinegg extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVol'), 'info': ticker, }; } @@ -51394,15 +51216,12 @@ module.exports = class coinegg extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const type = 'limit'; const side = this.safeString (trade, 'type'); const id = this.safeString (trade, 'tid'); @@ -51449,9 +51268,9 @@ module.exports = class coinegg extends Exchange { result[code] = this.account (); } const type = (accountType === 'lock') ? 'used' : 'free'; - result[code][type] = this.safeFloat (balances, key); + result[code][type] = this.safeString (balances, key); } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -51460,15 +51279,9 @@ module.exports = class coinegg extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let status = this.safeString (order, 'status'); if (status === 'cancelled') { status = 'canceled'; @@ -51479,7 +51292,7 @@ module.exports = class coinegg extends Exchange { const type = 'limit'; const side = this.safeString (order, 'type'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -51495,13 +51308,13 @@ module.exports = class coinegg extends Exchange { 'stopPrice': undefined, 'cost': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'trades': undefined, 'fee': undefined, 'info': info, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -51637,13 +51450,14 @@ module.exports = class coinegg extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],66:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],65:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -51836,13 +51650,13 @@ module.exports = class coinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': this.safeFloat (market, 'taker_fee_rate'), - 'maker': this.safeFloat (market, 'maker_fee_rate'), + 'taker': this.safeNumber (market, 'taker_fee_rate'), + 'maker': this.safeNumber (market, 'maker_fee_rate'), 'info': market, 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -51862,16 +51676,16 @@ module.exports = class coinex extends Exchange { symbol = market['symbol']; } ticker = this.safeValue (ticker, 'ticker', {}); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -51881,7 +51695,7 @@ module.exports = class coinex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat2 (ticker, 'vol', 'volume'), + 'baseVolume': this.safeNumber2 (ticker, 'vol', 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -51941,16 +51755,18 @@ module.exports = class coinex extends Exchange { } const tradeId = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market); - let cost = this.safeFloat (trade, 'deal_money'); - if (!cost) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); + let cost = this.safeNumber (trade, 'deal_money'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_asset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -52003,11 +51819,11 @@ module.exports = class coinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -52068,11 +51884,11 @@ module.exports = class coinex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -52111,11 +51927,11 @@ module.exports = class coinex extends Exchange { // } // const timestamp = this.safeTimestamp (order, 'create_time'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'deal_money'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'deal_amount'); - const average = this.safeFloat (order, 'avg_price'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'deal_money'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'deal_amount'); + const average = this.safeNumber (order, 'avg_price'); let symbol = undefined; const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); @@ -52127,11 +51943,11 @@ module.exports = class coinex extends Exchange { feeCurrency = market['quote']; } } - const remaining = this.safeFloat (order, 'left'); + const remaining = this.safeNumber (order, 'left'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -52153,10 +51969,10 @@ module.exports = class coinex extends Exchange { 'trades': undefined, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'deal_fee'), + 'cost': this.safeNumber (order, 'deal_fee'), }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -52402,8 +52218,8 @@ module.exports = class coinex extends Exchange { const timestamp = this.safeTimestamp (transaction, 'create_time'); const type = ('coin_withdraw_id' in transaction) ? 'withdraw' : 'deposit'; const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'tx_fee'); + let amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'tx_fee'); if (type === 'deposit') { feeCost = 0; } @@ -52594,13 +52410,14 @@ module.exports = class coinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],67:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],66:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, RateLimitExceeded, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -52733,11 +52550,11 @@ module.exports = class coinfalcon extends Exchange { 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'change_in_24h'), + 'change': this.safeNumber (ticker, 'change_in_24h'), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -52774,20 +52591,17 @@ module.exports = class coinfalcon extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } const tradeId = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'order_id'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = this.safeString (trade, 'fee_currency_code'); fee = { @@ -52855,14 +52669,13 @@ module.exports = class coinfalcon extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available_balance'), - 'used': this.safeFloat (balance, 'hold_balance'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'hold_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -52897,19 +52710,9 @@ module.exports = class coinfalcon extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'size_filled'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (price !== undefined) { - cost = filled * price; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'size_filled'); const status = this.parseOrderStatus (this.safeString (order, 'status')); let type = this.safeString (order, 'operation_type'); if (type !== undefined) { @@ -52918,7 +52721,7 @@ module.exports = class coinfalcon extends Exchange { } const side = this.safeString (order, 'order_type'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -52931,16 +52734,16 @@ module.exports = class coinfalcon extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'lastTradeTimestamp': undefined, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -53050,13 +52853,14 @@ module.exports = class coinfalcon extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],68:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],67:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ExchangeError, InvalidNonce, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -53158,14 +52962,14 @@ module.exports = class coinfloor extends Exchange { const baseIdLower = this.safeStringLower (market, 'baseId'); const quoteIdLower = this.safeStringLower (market, 'quoteId'); result[base] = { - 'free': this.safeFloat (response, baseIdLower + '_available'), - 'used': this.safeFloat (response, baseIdLower + '_reserved'), - 'total': this.safeFloat (response, baseIdLower + '_balance'), + 'free': this.safeNumber (response, baseIdLower + '_available'), + 'used': this.safeNumber (response, baseIdLower + '_reserved'), + 'total': this.safeNumber (response, baseIdLower + '_balance'), }; result[quote] = { - 'free': this.safeFloat (response, quoteIdLower + '_available'), - 'used': this.safeFloat (response, quoteIdLower + '_reserved'), - 'total': this.safeFloat (response, quoteIdLower + '_balance'), + 'free': this.safeNumber (response, quoteIdLower + '_available'), + 'used': this.safeNumber (response, quoteIdLower + '_reserved'), + 'total': this.safeNumber (response, quoteIdLower + '_balance'), }; return this.parseBalance (result); } @@ -53186,22 +52990,22 @@ module.exports = class coinfloor extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -53230,14 +53034,11 @@ module.exports = class coinfloor extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -53355,8 +53156,8 @@ module.exports = class coinfloor extends Exchange { const parts = key.split ('_'); const numParts = parts.length; if (numParts === 2) { - const tmpBaseAmount = this.safeFloat (item, parts[0]); - const tmpQuoteAmount = this.safeFloat (item, parts[1]); + const tmpBaseAmount = this.safeNumber (item, parts[0]); + const tmpQuoteAmount = this.safeNumber (item, parts[1]); if (tmpBaseAmount !== undefined && tmpQuoteAmount !== undefined) { baseId = parts[0]; quoteId = parts[1]; @@ -53372,7 +53173,7 @@ module.exports = class coinfloor extends Exchange { const referenceId = this.safeString (item, 'id'); const timestamp = this.parse8601 (this.safeString (item, 'datetime')); let fee = undefined; - const feeCost = this.safeFloat (item, 'fee'); + const feeCost = this.safeNumber (item, 'fee'); const result = { 'id': undefined, 'timestamp': timestamp, @@ -53476,8 +53277,8 @@ module.exports = class coinfloor extends Exchange { 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, 'type': type, - 'price': this.safeFloat (response, 'price'), - 'remaining': this.safeFloat (response, 'amount'), + 'price': this.safeNumber (response, 'price'), + 'remaining': this.safeNumber (response, 'amount'), 'info': response, }; } @@ -53502,19 +53303,14 @@ module.exports = class coinfloor extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let side = undefined; const status = this.safeString (order, 'status'); - if (order['type'] === 0) { + const rawType = this.safeString (order, 'type'); + if (rawType === '0') { side = 'buy'; - } else if (order['type'] === 1) { + } else if (rawType === '1') { side = 'sell'; } let symbol = undefined; @@ -53522,7 +53318,7 @@ module.exports = class coinfloor extends Exchange { symbol = market['symbol']; } const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -53540,11 +53336,11 @@ module.exports = class coinfloor extends Exchange { 'amount': undefined, 'filled': undefined, 'remaining': amount, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -53603,13 +53399,14 @@ module.exports = class coinfloor extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],69:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],68:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -53771,14 +53568,14 @@ module.exports = class coingi extends Exchange { const currencyId = this.safeString (balance['currency'], 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - const blocked = this.safeFloat (balance, 'blocked'); - const inOrders = this.safeFloat (balance, 'inOrders'); - const withdrawing = this.safeFloat (balance, 'withdrawing'); - account['used'] = this.sum (blocked, inOrders, withdrawing); + account['free'] = this.safeString (balance, 'available'); + const blocked = this.safeString (balance, 'blocked'); + const inOrders = this.safeString (balance, 'inOrders'); + const withdrawing = this.safeString (balance, 'withdrawing'); + account['used'] = Precise.stringAdd (Precise.stringAdd (blocked, inOrders), withdrawing); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = 512, params = {}) { @@ -53804,11 +53601,11 @@ module.exports = class coingi extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -53818,8 +53615,8 @@ module.exports = class coingi extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'counterVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'counterVolume'), 'info': ticker, }; } @@ -53852,14 +53649,11 @@ module.exports = class coingi extends Exchange { } parseTrade (trade, market = undefined) { - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const id = this.safeString (trade, 'id'); const marketId = this.safeString (trade, 'currencyPair'); @@ -53953,7 +53747,7 @@ module.exports = class coingi extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],70:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],69:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -54164,16 +53958,16 @@ module.exports = class coinmarketcap extends Exchange { if (timestamp === undefined) { timestamp = this.milliseconds (); } - const change = this.safeFloat (ticker, 'percent_change_24h'); + const change = this.safeNumber (ticker, 'percent_change_24h'); let last = undefined; let symbol = undefined; let volume = undefined; if (market !== undefined) { symbol = market['symbol']; const priceKey = 'price_' + market['quoteId']; - last = this.safeFloat (ticker, priceKey); + last = this.safeNumber (ticker, priceKey); const volumeKey = '24h_volume_' + market['quoteId']; - volume = this.safeFloat (ticker, volumeKey); + volume = this.safeNumber (ticker, volumeKey); } return { 'symbol': symbol, @@ -54302,13 +54096,14 @@ module.exports = class coinmarketcap extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],71:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],70:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder, OrderNotFound, RateLimitExceeded, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -54535,7 +54330,7 @@ module.exports = class coinmate extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -54563,12 +54358,12 @@ module.exports = class coinmate extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -54591,16 +54386,16 @@ module.exports = class coinmate extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'data'); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'vwap': undefined, 'askVolume': undefined, 'open': undefined, @@ -54610,7 +54405,7 @@ module.exports = class coinmate extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'amount'), + 'baseVolume': this.safeNumber (ticker, 'amount'), 'quoteVolume': undefined, 'info': ticker, }; @@ -54679,8 +54474,8 @@ module.exports = class coinmate extends Exchange { // } // const timestamp = this.safeInteger (item, 'timestamp'); - const amount = this.safeFloat (item, 'amount'); - const fee = this.safeFloat (item, 'fee'); + const amount = this.safeNumber (item, 'amount'); + const fee = this.safeNumber (item, 'fee'); const txid = this.safeString (item, 'txid'); const address = this.safeString (item, 'destination'); const tag = this.safeString (item, 'destinationTag'); @@ -54758,21 +54553,18 @@ module.exports = class coinmate extends Exchange { // const marketId = this.safeString (trade, 'currencyPair'); market = this.safeMarket (marketId, market, '_'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeStringLower2 (trade, 'type', 'tradeType'); const type = this.safeStringLower (trade, 'orderType'); const orderId = this.safeString (trade, 'orderId'); const id = this.safeString (trade, 'transactionId'); const timestamp = this.safeInteger2 (trade, 'timestamp', 'createdTimestamp'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -54913,11 +54705,11 @@ module.exports = class coinmate extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.safeInteger (order, 'timestamp'); const side = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'originalAmount'); - let remaining = this.safeFloat (order, 'remainingAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'originalAmount'); + let remaining = this.safeNumber (order, 'remainingAmount'); if (remaining === undefined) { - remaining = this.safeFloat (order, 'amount'); + remaining = this.safeNumber (order, 'amount'); } let status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.parseOrderType (this.safeString (order, 'orderTradeType')); @@ -54932,11 +54724,11 @@ module.exports = class coinmate extends Exchange { cost = filled * price; } } - const average = this.safeFloat (order, 'avgPrice'); + const average = this.safeNumber (order, 'avgPrice'); const marketId = this.safeString (order, 'currencyPair'); const symbol = this.safeSymbol (marketId, market, '_'); const clientOrderId = this.safeString (order, 'clientOrderId'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); return { 'id': id, 'clientOrderId': clientOrderId, @@ -55064,13 +54856,14 @@ module.exports = class coinmate extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],72:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],71:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, BadRequest, ExchangeError, ArgumentsRequired, OrderNotFound, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -55209,11 +55002,11 @@ module.exports = class coinone extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'avail'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -55266,13 +55059,13 @@ module.exports = class coinone extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const first = this.safeFloat (ticker, 'first'); - const last = this.safeFloat (ticker, 'last'); + const first = this.safeNumber (ticker, 'first'); + const last = this.safeNumber (ticker, 'last'); let average = undefined; if (first !== undefined && last !== undefined) { average = this.sum (first, last) / 2; } - const previousClose = this.safeFloat (ticker, 'yesterday_last'); + const previousClose = this.safeNumber (ticker, 'yesterday_last'); let change = undefined; let percentage = undefined; if (last !== undefined && previousClose !== undefined) { @@ -55286,8 +55079,8 @@ module.exports = class coinone extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -55300,7 +55093,7 @@ module.exports = class coinone extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -55346,20 +55139,17 @@ module.exports = class coinone extends Exchange { side = 'buy'; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'fee'); + let feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); - let feeRate = this.safeFloat (trade, 'feeRate'); + let feeRate = this.safeNumber (trade, 'feeRate'); feeRate = Math.abs (feeRate); let feeCurrencyCode = undefined; if (market !== undefined) { @@ -55519,7 +55309,7 @@ module.exports = class coinone extends Exchange { // } // const id = this.safeString (order, 'orderId'); - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); const timestamp = this.safeTimestamp (order, 'timestamp'); let side = this.safeString (order, 'type'); if (side === 'ask') { @@ -55527,9 +55317,8 @@ module.exports = class coinone extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const remaining = this.safeFloat (order, 'remainQty'); - let filled = undefined; - const amount = this.safeFloat (order, 'qty'); + const remaining = this.safeNumber (order, 'remainQty'); + const amount = this.safeNumber (order, 'qty'); let status = this.safeString (order, 'status'); // https://github.com/ccxt/ccxt/pull/7067 if (status === 'live') { @@ -55539,14 +55328,7 @@ module.exports = class coinone extends Exchange { } } } - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (amount - remaining); - } status = this.parseOrderStatus (status); - let cost = undefined; - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } let symbol = undefined; let base = undefined; let quote = undefined; @@ -55566,16 +55348,16 @@ module.exports = class coinone extends Exchange { quote = market['quote']; } let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = (side === 'sell') ? quote : base; fee = { 'cost': feeCost, - 'rate': this.safeFloat (order, 'feeRate'), + 'rate': this.safeNumber (order, 'feeRate'), 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -55589,15 +55371,15 @@ module.exports = class coinone extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': amount, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -55672,8 +55454,8 @@ module.exports = class coinone extends Exchange { // eslint-disable-next-line quotes throw new ArgumentsRequired (this.id + " cancelOrder() requires a symbol argument. To cancel the order, pass a symbol argument and {'price': 12345, 'qty': 1.2345, 'is_ask': 0} in the params argument of cancelOrder."); } - const price = this.safeFloat (params, 'price'); - const qty = this.safeFloat (params, 'qty'); + const price = this.safeNumber (params, 'price'); + const qty = this.safeNumber (params, 'qty'); const isAsk = this.safeInteger (params, 'is_ask'); if ((price === undefined) || (qty === undefined) || (isAsk === undefined)) { // eslint-disable-next-line quotes @@ -55748,13 +55530,14 @@ module.exports = class coinone extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],73:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],72:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -55874,7 +55657,7 @@ module.exports = class coinspot extends Exchange { const balance = currencies[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } } @@ -55884,11 +55667,11 @@ module.exports = class coinspot extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -55908,16 +55691,16 @@ module.exports = class coinspot extends Exchange { id = id.toLowerCase (); const ticker = response['prices'][id]; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -55965,11 +55748,13 @@ module.exports = class coinspot extends Exchange { // "market":"BTC/AUD" // } // - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'total'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger (trade, 'solddate'); const marketId = this.safeString (trade, 'market'); @@ -56037,13 +55822,15 @@ module.exports = class coinspot extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],74:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],73:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, InvalidNonce, RequestTimeout, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, AuthenticationError, BadSymbol } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -56150,6 +55937,7 @@ module.exports = class crex24 extends Exchange { ], }, }, + 'precisionMode': TICK_SIZE, 'fees': { 'trading': { 'tierBased': true, @@ -56170,6 +55958,7 @@ module.exports = class crex24 extends Exchange { 'BIT': 'BitMoney', 'BULL': 'BuySell', 'CREDIT': 'TerraCredit', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'GHOST': 'GHOSTPRISM', 'IQ': 'IQ.Cash', 'PUT': 'PutinCoin', @@ -56203,6 +55992,7 @@ module.exports = class crex24 extends Exchange { 'API Key': AuthenticationError, // "API Key '9edc48de-d5b0-4248-8e7e-f59ffcd1c7f1' doesn't exist." 'Insufficient funds': InsufficientFunds, // "Insufficient funds: new order requires 10 ETH which is more than the available balance." 'has been delisted.': BadSymbol, // {"errorDescription":"Instrument '$PAC-BTC' has been delisted."} + 'is currently suspended.': BadSymbol, // {"errorDescription":"Trading in BITG-BTC is currently suspended."} 'Mandatory parameter': BadRequest, // {"errorDescription":"Mandatory parameter 'feeCurrency' is missing."} }, }, @@ -56244,12 +56034,12 @@ module.exports = class crex24 extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const tickSize = this.safeValue (market, 'tickSize'); - const minPrice = this.safeValue (market, 'minPrice'); - const minAmount = this.safeFloat (market, 'minVolume'); + const tickSize = this.safeNumber (market, 'tickSize'); + const minPrice = this.safeNumber (market, 'minPrice'); + const minAmount = this.safeNumber (market, 'minVolume'); const precision = { - 'amount': this.precisionFromString (this.numberToString (minAmount)), - 'price': this.precisionFromString (this.numberToString (tickSize)), + 'amount': minAmount, + 'price': tickSize, }; const active = (market['state'] === 'active'); result.push ({ @@ -56314,7 +56104,8 @@ module.exports = class crex24 extends Exchange { const currency = response[i]; const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); - const precision = this.safeInteger (currency, 'withdrawalPrecision'); + const withdrawalPrecision = this.safeInteger (currency, 'withdrawalPrecision'); + const precision = Math.pow (10, -withdrawalPrecision); const address = this.safeValue (currency, 'BaseAddress'); const active = (currency['depositsAllowed'] && currency['withdrawalsAllowed'] && !currency['isDelisted']); const type = currency['isFiat'] ? 'fiat' : 'crypto'; @@ -56326,7 +56117,7 @@ module.exports = class crex24 extends Exchange { 'type': type, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'flatWithdrawalFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'flatWithdrawalFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -56342,12 +56133,12 @@ module.exports = class crex24 extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -56377,11 +56168,11 @@ module.exports = class crex24 extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -56433,16 +56224,16 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); const marketId = this.safeString (ticker, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -56450,10 +56241,10 @@ module.exports = class crex24 extends Exchange { 'last': last, 'previousClose': undefined, // previous day close 'change': undefined, - 'percentage': this.safeFloat (ticker, 'percentChange'), + 'percentage': this.safeNumber (ticker, 'percentChange'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -56523,14 +56314,6 @@ module.exports = class crex24 extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - parseTrade (trade, market = undefined) { // // public fetchTrades @@ -56555,14 +56338,11 @@ module.exports = class crex24 extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'orderId'); @@ -56571,7 +56351,7 @@ module.exports = class crex24 extends Exchange { let fee = undefined; const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCode = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -56632,11 +56412,11 @@ module.exports = class crex24 extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -56705,50 +56485,19 @@ module.exports = class crex24 extends Exchange { const marketId = this.safeString (order, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remainingVolume'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remainingVolume'); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'lastUpdate')); - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = amount - remaining; - if (this.options['parseOrderToPrecision']) { - filled = parseFloat (this.amountToPrecision (symbol, filled)); - } - filled = Math.max (filled, 0.0); - if (price !== undefined) { - cost = price * filled; - } - } - } const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeString (order, 'side'); const fee = undefined; const trades = undefined; - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const average = undefined; const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -56762,14 +56511,14 @@ module.exports = class crex24 extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -56804,7 +56553,7 @@ module.exports = class crex24 extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -57223,8 +56972,8 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'createdAt')); const updated = this.parse8601 (this.safeString (transaction, 'processedAt')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); const fee = { 'cost': feeCost, 'currency': code, @@ -57349,14 +57098,15 @@ module.exports = class crex24 extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],75:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],74:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -57444,6 +57194,7 @@ module.exports = class currencycom extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.002, @@ -57602,7 +57353,7 @@ module.exports = class currencycom extends Exchange { const filtersByType = this.indexBy (filters, 'filterType'); const precision = { 'amount': 1 / Math.pow (1, this.safeInteger (market, 'baseAssetPrecision')), - 'price': this.safeFloat (market, 'tickSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'TRADING'); @@ -57635,14 +57386,14 @@ module.exports = class currencycom extends Exchange { 'max': undefined, }, 'cost': { - 'min': -1 * Math.log10 (precision['amount']), + 'min': -Math.log10 (precision['amount']), 'max': undefined, }, }, }; - const exchangeFee = this.safeFloat2 (market, 'exchangeFee', 'tradingFee'); - const makerFee = this.safeFloat (market, 'makerFee', exchangeFee); - const takerFee = this.safeFloat (market, 'takerFee', exchangeFee); + const exchangeFee = this.safeNumber2 (market, 'exchangeFee', 'tradingFee'); + const makerFee = this.safeNumber (market, 'makerFee', exchangeFee); + const takerFee = this.safeNumber (market, 'takerFee', exchangeFee); if (makerFee !== undefined) { entry['maker'] = makerFee / 100; } @@ -57651,65 +57402,44 @@ module.exports = class currencycom extends Exchange { } if ('PRICE_FILTER' in filtersByType) { const filter = this.safeValue (filtersByType, 'PRICE_FILTER', {}); - entry['precision']['price'] = this.safeFloat (filter, 'tickSize'); + entry['precision']['price'] = this.safeNumber (filter, 'tickSize'); // PRICE_FILTER reports zero values for maxPrice // since they updated filter types in November 2018 // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } } if ('LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'LOT_SIZE', {}); - entry['precision']['amount'] = this.safeFloat (filter, 'stepSize'); + entry['precision']['amount'] = this.safeNumber (filter, 'stepSize'); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat (filter, 'minNotional'); + entry['limits']['cost']['min'] = this.safeNumber (filter, 'minNotional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { const response = await this.privateGetAccount (params); // @@ -57756,8 +57486,8 @@ module.exports = class currencycom extends Exchange { const response = await this.privateGetAccount (params); return { 'info': response, - 'maker': this.safeFloat (response, 'makerCommission'), - 'taker': this.safeFloat (response, 'takerCommission'), + 'maker': this.safeNumber (response, 'makerCommission'), + 'taker': this.safeNumber (response, 'takerCommission'), }; } @@ -57791,11 +57521,11 @@ module.exports = class currencycom extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -57894,8 +57624,8 @@ module.exports = class currencycom extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); - const open = this.safeFloat (ticker, 'openPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); let average = undefined; if ((open !== undefined) && (last !== undefined)) { average = this.sum (open, last) / 2; @@ -57904,22 +57634,22 @@ module.exports = class currencycom extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), 'open': open, 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -57954,14 +57684,6 @@ module.exports = class currencycom extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24hr (params); @@ -57994,11 +57716,11 @@ module.exports = class currencycom extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -58064,8 +57786,11 @@ module.exports = class currencycom extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -58081,7 +57806,7 @@ module.exports = class currencycom extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -58103,7 +57828,7 @@ module.exports = class currencycom extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': fee, }; } @@ -58179,66 +57904,21 @@ module.exports = class currencycom extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); + const remaining = undefined; + const cost = this.safeNumber (order, 'cummulativeQuoteQty'); const id = this.safeString (order, 'orderId'); const type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeStringLower (order, 'side'); - let fee = undefined; let trades = undefined; const fills = this.safeValue (order, 'fills'); if (fills !== undefined) { trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'timestamp': timestamp, @@ -58252,13 +57932,13 @@ module.exports = class currencycom extends Exchange { 'stopPrice': undefined, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -58470,7 +58150,7 @@ module.exports = class currencycom extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],76:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],75:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -58478,6 +58158,7 @@ module.exports = class currencycom extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, BadRequest, BadSymbol, InvalidOrder, AuthenticationError, ArgumentsRequired, OrderNotFound, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -58731,14 +58412,14 @@ module.exports = class delta extends Exchange { 'name': this.safeString (currency, 'name'), 'info': currency, // the original payload 'active': active, - 'fee': this.safeFloat (currency, 'base_withdrawal_fee'), + 'fee': this.safeNumber (currency, 'base_withdrawal_fee'), 'precision': 1 / Math.pow (10, precision), 'limits': { 'amount': { 'min': undefined, 'max': undefined }, 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal_amount'), + 'min': this.safeNumber (currency, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -58872,26 +58553,26 @@ module.exports = class delta extends Exchange { } const precision = { 'amount': 1.0, // number of contracts - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; const limits = { 'amount': { 'min': 1.0, - 'max': this.safeFloat (market, 'position_size_limit'), + 'max': this.safeNumber (market, 'position_size_limit'), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; const state = this.safeString (market, 'state'); const active = (state === 'live'); - const maker = this.safeFloat (market, 'maker_commission_rate'); - const taker = this.safeFloat (market, 'taker_commission_rate'); + const maker = this.safeNumber (market, 'maker_commission_rate'); + const taker = this.safeNumber (market, 'taker_commission_rate'); result.push ({ 'id': id, 'numericId': numericId, @@ -58939,8 +58620,8 @@ module.exports = class delta extends Exchange { const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.001); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; let percentage = undefined; @@ -58951,15 +58632,15 @@ module.exports = class delta extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'turnover'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'turnover'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -59129,12 +58810,11 @@ module.exports = class delta extends Exchange { const orderId = this.safeString (trade, 'order_id'); let timestamp = this.parse8601 (this.safeString (trade, 'created_at')); timestamp = this.safeIntegerProduct (trade, 'timestamp', 0.001, timestamp); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const product = this.safeValue (trade, 'product', {}); const marketId = this.safeString (product, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -59153,7 +58833,7 @@ module.exports = class delta extends Exchange { if (type !== undefined) { type = type.replace ('_order', ''); } - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { const settlingAsset = this.safeValue (product, 'settling_asset', {}); @@ -59220,11 +58900,11 @@ module.exports = class delta extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -59294,11 +58974,11 @@ module.exports = class delta extends Exchange { const currency = this.safeValue (currenciesByNumericId, currencyId); const code = (currency === undefined) ? currencyId : currency['code']; const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchPosition (symbol, params = undefined) { @@ -59322,7 +59002,7 @@ module.exports = class delta extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPositionsMargined (params); // @@ -59403,20 +59083,12 @@ module.exports = class delta extends Exchange { const side = this.safeString (order, 'side'); let type = this.safeString (order, 'order_type'); type = type.replace ('_order', ''); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'unfilled_size'); - let filled = undefined; - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let cost = undefined; - const average = this.safeFloat (order, 'average_fill_price'); - if ((average !== undefined) && filled) { - cost = average * filled; - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'unfilled_size'); + const average = this.safeNumber (order, 'average_fill_price'); let fee = undefined; - const feeCost = this.safeFloat (order, 'paid_commission'); + const feeCost = this.safeNumber (order, 'paid_commission'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -59429,7 +59101,7 @@ module.exports = class delta extends Exchange { 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -59441,14 +59113,14 @@ module.exports = class delta extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -59847,9 +59519,9 @@ module.exports = class delta extends Exchange { const currenciesByNumericId = this.safeValue (this.options, 'currenciesByNumericId'); currency = this.safeValue (currenciesByNumericId, currencyId, currency); const code = (currency === undefined) ? undefined : currency['code']; - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'created_at')); - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const before = Math.max (0, after - amount); const status = 'ok'; return { @@ -59955,7 +59627,7 @@ module.exports = class delta extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],77:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],76:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -59963,6 +59635,7 @@ module.exports = class delta extends Exchange { const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, ExchangeError, ArgumentsRequired, PermissionDenied, InvalidOrder, OrderNotFound, DDoSProtection, NotSupported, ExchangeNotAvailable, InsufficientFunds, BadRequest, InvalidAddress, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -60393,8 +60066,8 @@ module.exports = class deribit extends Exchange { const future = (type === 'future'); const option = (type === 'option'); const active = this.safeValue (market, 'is_active'); - const minTradeAmount = this.safeFloat (market, 'min_trade_amount'); - const tickSize = this.safeFloat (market, 'tick_size'); + const minTradeAmount = this.safeNumber (market, 'min_trade_amount'); + const tickSize = this.safeNumber (market, 'tick_size'); const precision = { 'amount': minTradeAmount, 'price': tickSize, @@ -60406,8 +60079,8 @@ module.exports = class deribit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_commission'), - 'maker': this.safeFloat (market, 'maker_commission'), + 'taker': this.safeNumber (market, 'taker_commission'), + 'maker': this.safeNumber (market, 'maker_commission'), 'limits': { 'amount': { 'min': minTradeAmount, @@ -60490,11 +60163,11 @@ module.exports = class deribit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const currencyCode = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableFunds'); - account['used'] = this.safeFloat (balance, 'maintenanceMargin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'maintenanceMargin'); + account['total'] = this.safeString (balance, 'equity'); result[currencyCode] = account; - return this.parseBalance (result); + return this.parseBalance (result, false); } async createDepositAddress (code, params = {}) { @@ -60612,18 +60285,18 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger2 (ticker, 'timestamp', 'creation_timestamp'); const marketId = this.safeString (ticker, 'instrument_name'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat2 (ticker, 'last_price', 'last'); + const last = this.safeNumber2 (ticker, 'last_price', 'last'); const stats = this.safeValue (ticker, 'stats', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (stats, 'high', 'max_price'), - 'low': this.safeFloat2 (stats, 'low', 'min_price'), - 'bid': this.safeFloat2 (ticker, 'best_bid_price', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_amount'), - 'ask': this.safeFloat2 (ticker, 'best_ask_price', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_amount'), + 'high': this.safeNumber2 (stats, 'high', 'max_price'), + 'low': this.safeNumber2 (stats, 'low', 'min_price'), + 'bid': this.safeNumber2 (ticker, 'best_bid_price', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_amount'), + 'ask': this.safeNumber2 (ticker, 'best_ask_price', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_amount'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -60633,7 +60306,7 @@ module.exports = class deribit extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (stats, 'volume'), + 'quoteVolume': this.safeNumber (stats, 'volume'), 'info': ticker, }; } @@ -60820,21 +60493,18 @@ module.exports = class deribit extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const liquidity = this.safeString (trade, 'liquidity'); let takerOrMaker = undefined; if (liquidity !== undefined) { // M = maker, T = taker, MT = both takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -61014,31 +60684,21 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger (order, 'creation_timestamp'); const lastUpdate = this.safeInteger (order, 'last_update_timestamp'); const id = this.safeString (order, 'order_id'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); let lastTradeTimestamp = undefined; if (filled !== undefined) { if (filled > 0) { lastTradeTimestamp = lastUpdate; } } - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = price * filled; - } - } const status = this.parseOrderStatus (this.safeString (order, 'order_state')); const marketId = this.safeString (order, 'instrument_name'); market = this.safeMarket (marketId, market); const side = this.safeStringLower (order, 'direction'); - let feeCost = this.safeFloat (order, 'commission'); + let feeCost = this.safeNumber (order, 'commission'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); @@ -61056,7 +60716,7 @@ module.exports = class deribit extends Exchange { const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); const stopPrice = this.safeValue (order, 'stop_price'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -61071,14 +60731,14 @@ module.exports = class deribit extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -61155,7 +60815,7 @@ module.exports = class deribit extends Exchange { } } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price or stopPrice param for a ' + type + ' order'); } else { @@ -61554,7 +61214,7 @@ module.exports = class deribit extends Exchange { const updated = this.safeInteger (transaction, 'updated_timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let type = 'deposit'; let fee = undefined; if (feeCost !== undefined) { @@ -61577,7 +61237,7 @@ module.exports = class deribit extends Exchange { 'tagTo': undefined, 'tagFrom': undefined, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -61623,7 +61283,7 @@ module.exports = class deribit extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.codeFromOptions ('fetchPositions'); const currency = this.currency (code); @@ -61744,13 +61404,14 @@ module.exports = class deribit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],78:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],77:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); -const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -61808,11 +61469,6 @@ module.exports = class digifinex extends Exchange { 'referral': 'https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp', }, 'api': { - 'v2': { - 'get': [ - 'ticker', - ], - }, 'public': { 'get': [ '{market}/symbols', @@ -61938,6 +61594,7 @@ module.exports = class digifinex extends Exchange { }, 'commonCurrencies': { 'BHT': 'Black House Test', + 'EPS': 'Epanus', 'MBN': 'Mobilian Coin', 'TEL': 'TEL666', }, @@ -61992,7 +61649,7 @@ module.exports = class digifinex extends Exchange { const depositStatus = this.safeValue (currency, 'deposit_status', 1); const withdrawStatus = this.safeValue (currency, 'withdraw_status', 1); const active = depositStatus && withdrawStatus; - const fee = this.safeFloat (currency, 'withdraw_fee_rate'); + const fee = this.safeNumber (currency, 'withdraw_fee_rate'); if (code in result) { if (Array.isArray (result[code]['info'])) { result[code]['info'].push (currency); @@ -62023,7 +61680,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw_amount'), + 'min': this.safeNumber (currency, 'min_withdraw_amount'), 'max': undefined, }, }, @@ -62077,7 +61734,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), 'max': undefined, }, 'price': { @@ -62085,7 +61742,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), + 'min': this.safeNumber (market, 'minimum_value'), 'max': undefined, }, }; @@ -62099,7 +61756,7 @@ module.exports = class digifinex extends Exchange { // const status = this.safeString (market, 'status'); // const active = (status === 'TRADING'); // - const isAllowed = this.safeValue (market, 'is_allow', 1); + const isAllowed = this.safeInteger (market, 'is_allow', 1); const active = isAllowed ? true : false; const type = 'spot'; const spot = (type === 'spot'); @@ -62155,7 +61812,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), + 'min': this.safeNumber (market, 'min_volume'), 'max': undefined, }, 'price': { @@ -62163,7 +61820,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, }; @@ -62208,12 +61865,12 @@ module.exports = class digifinex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -62247,87 +61904,67 @@ module.exports = class digifinex extends Exchange { } async fetchTickers (symbols = undefined, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTickers() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); - const request = { - 'apiKey': apiKey, - }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (params); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const result = {}; - const tickers = this.safeValue (response, 'ticker', {}); + const tickers = this.safeValue (response, 'ticker', []); const date = this.safeInteger (response, 'date'); - const reversedMarketIds = Object.keys (tickers); - for (let i = 0; i < reversedMarketIds.length; i++) { - const reversedMarketId = reversedMarketIds[i]; - const ticker = this.extend ({ + for (let i = 0; i < tickers.length; i++) { + const rawTicker = this.extend ({ 'date': date, - }, tickers[reversedMarketId]); - const [ quoteId, baseId ] = reversedMarketId.split ('_'); - const marketId = baseId.toUpperCase () + '_' + quoteId.toUpperCase (); - const market = this.safeMarket (marketId, undefined, '_'); - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); + }, tickers[i]); + const ticker = this.parseTicker (rawTicker); + const symbol = ticker['symbol']; + result[symbol] = ticker; } return this.filterByArray (result, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTicker() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); const market = this.market (symbol); - // reversed base/quote in v2 - const marketId = market['quoteId'].toLowerCase () + '_' + market['baseId'].toLowerCase (); const request = { - 'symbol': marketId, - 'apiKey': apiKey, + 'symbol': market['id'], }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (this.extend (request, params)); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const date = this.safeInteger (response, 'date'); - const ticker = this.safeValue (response, 'ticker', {}); - let result = this.safeValue (ticker, marketId, {}); - result = this.extend ({ 'date': date }, result); + const tickers = this.safeValue (response, 'ticker', []); + const firstTicker = this.safeValue (tickers, 0, {}); + const result = this.extend ({ 'date': date }, firstTicker); return this.parseTicker (result, market); } @@ -62337,6 +61974,7 @@ module.exports = class digifinex extends Exchange { // // { // "last":0.021957, + // "symbol": "btc_usdt", // "base_vol":2249.3521732227, // "change":-0.6, // "vol":102443.5111, @@ -62347,22 +61985,20 @@ module.exports = class digifinex extends Exchange { // "date"1564518452, // injected from fetchTicker/fetchTickers // } // - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeStringUpper (ticker, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -62372,8 +62008,8 @@ module.exports = class digifinex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'base_vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'base_vol'), 'info': ticker, }; } @@ -62409,18 +62045,15 @@ module.exports = class digifinex extends Exchange { const orderId = this.safeString (trade, 'order_id'); const timestamp = this.safeTimestamp2 (trade, 'date', 'timestamp'); const side = this.safeString2 (trade, 'type', 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); const takerOrMaker = this.safeValue (trade, 'is_maker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -62522,11 +62155,11 @@ module.exports = class digifinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 5), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 1), // volume + this.safeNumber (ohlcv, 5), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 1), // volume ]; } @@ -62717,21 +62350,11 @@ module.exports = class digifinex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_price'); - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - return { + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -62747,13 +62370,13 @@ module.exports = class digifinex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'average': average, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -62947,7 +62570,7 @@ module.exports = class digifinex extends Exchange { const code = this.safeCurrencyCode (this.safeString (item, 'currency_mark'), currency); const timestamp = this.safeTimestamp (item, 'time'); const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -63010,16 +62633,6 @@ module.exports = class digifinex extends Exchange { return this.parseLedger (items, currency, since, limit); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -63172,8 +62785,8 @@ module.exports = class digifinex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_date')); const updated = this.parse8601 (this.safeString (transaction, 'finished_date')); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -63223,7 +62836,7 @@ module.exports = class digifinex extends Exchange { } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const version = (api === 'v2') ? api : this.version; + const version = this.version; let url = this.urls['api'] + '/' + version + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); const urlencoded = this.urlencode (this.keysort (query)); @@ -63275,1283 +62888,7 @@ module.exports = class digifinex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],79:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, BadRequest, InsufficientFunds, PermissionDenied, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class dsx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'dsx', - 'name': 'DSX', - 'countries': [ 'UK' ], - 'rateLimit': 1500, - 'version': 'v3', - 'has': { - 'cancelOrder': true, - 'CORS': false, - 'createDepositAddress': true, - 'createMarketOrder': false, - 'createOrder': true, - 'fetchBalance': true, - 'fetchClosedOrders': false, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOHLCV': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchOrderBooks': true, - 'fetchOrders': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTransactions': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg', - 'api': { - 'public': 'https://dsxglobal.com/mapi', // market data - 'private': 'https://dsxglobal.com/tapi', // trading - 'dwapi': 'https://dsxglobal.com/dwapi', // deposit/withdraw - }, - 'www': 'https://dsxglobal.com', - 'doc': [ - 'https://dsxglobal.com/developers/publicApi', - ], - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'maker': 0.15 / 100, - 'taker': 0.25 / 100, - }, - }, - 'timeframes': { - '1m': 'm', - '1h': 'h', - '1d': 'd', - }, - 'api': { - // market data (public) - 'public': { - 'get': [ - 'barsFromMoment/{pair}/{period}/{start}', - 'depth/{pair}', - 'info', - 'lastBars/{pair}/{period}/{amount}', // period is 'm', 'h' or 'd' - 'periodBars/{pair}/{period}/{start}/{end}', - 'ticker/{pair}', - 'trades/{pair}', - ], - }, - // trading (private) - 'private': { - 'post': [ - 'info/account', - 'history/transactions', - 'history/trades', - 'history/orders', - 'orders', - 'order/cancel', - // 'order/cancel/all', - 'order/status', - 'order/new', - 'volume', - 'fees', // trading fee schedule - ], - }, - // deposit / withdraw (private) - 'dwapi': { - 'post': [ - 'deposit/cryptoaddress', - 'withdraw/crypto', - 'withdraw/fiat', - 'withdraw/submit', - // 'withdraw/cancel', - 'transaction/status', // see 'history/transactions' in private tapi above - ], - }, - }, - 'exceptions': { - 'exact': { - 'Sign is invalid': AuthenticationError, // {"success":0,"error":"Sign is invalid"} - 'Order was rejected. Incorrect price.': InvalidOrder, // {"success":0,"error":"Order was rejected. Incorrect price."} - "Order was rejected. You don't have enough money.": InsufficientFunds, // {"success":0,"error":"Order was rejected. You don't have enough money."} - 'This method is blocked for your pair of keys': PermissionDenied, // {"success":0,"error":"This method is blocked for your pair of keys"} - }, - 'broad': { - 'INVALID_PARAMETER': BadRequest, - 'Invalid pair name': ExchangeError, // {"success":0,"error":"Invalid pair name: btc_eth"} - 'invalid api key': AuthenticationError, - 'invalid sign': AuthenticationError, - 'api key dont have trade permission': AuthenticationError, - 'invalid parameter': InvalidOrder, - 'invalid order': InvalidOrder, - 'Requests too often': DDoSProtection, - 'not available': ExchangeNotAvailable, - 'data unavailable': ExchangeNotAvailable, - 'external service unavailable': ExchangeNotAvailable, - 'nonce is invalid': InvalidNonce, // {"success":0,"error":"Parameter: nonce is invalid"} - 'Incorrect volume': InvalidOrder, // {"success": 0,"error":"Order was rejected. Incorrect volume."} - }, - }, - 'options': { - 'fetchTickersMaxLength': 250, - }, - 'commonCurrencies': { - 'DSH': 'DASH', - }, - }); - } - - async fetchMarkets (params = {}) { - const response = await this.publicGetInfo (params); - // - // { - // "server_time": 1522057909, - // "pairs": { - // "ethusd": { - // "decimal_places": 5, - // "min_price": 100, - // "max_price": 1500, - // "min_amount": 0.01, - // "hidden": 0, - // "fee": 0, - // "amount_decimal_places": 4, - // "quoted_currency": "USD", - // "base_currency": "ETH" - // } - // } - // } - // - const markets = this.safeValue (response, 'pairs'); - const keys = Object.keys (markets); - const result = []; - for (let i = 0; i < keys.length; i++) { - const id = keys[i]; - const market = markets[id]; - const baseId = this.safeString (market, 'base_currency'); - const quoteId = this.safeString (market, 'quoted_currency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const precision = { - 'amount': this.safeInteger (market, 'decimal_places'), - 'price': this.safeInteger (market, 'decimal_places'), - }; - const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), - }; - const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), - }; - const costLimits = { - 'min': this.safeFloat (market, 'min_total'), - }; - const limits = { - 'amount': amountLimits, - 'price': priceLimits, - 'cost': costLimits, - }; - const hidden = this.safeInteger (market, 'hidden'); - const active = (hidden === 0); - // see parseMarket below - // https://github.com/ccxt/ccxt/pull/5786 - const otherId = base.toLowerCase () + quote.toLowerCase (); - result.push ({ - 'id': id, - 'otherId': otherId, // https://github.com/ccxt/ccxt/pull/5786 - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': active, - 'precision': precision, - 'limits': limits, - 'info': market, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostInfoAccount (); - // - // { - // "success" : 1, - // "return" : { - // "funds" : { - // "BTC" : { - // "total" : 0, - // "available" : 0 - // }, - // "USD" : { - // "total" : 0, - // "available" : 0 - // }, - // "USDT" : { - // "total" : 0, - // "available" : 0 - // } - // }, - // "rights" : { - // "info" : 1, - // "trade" : 1 - // }, - // "transactionCount" : 0, - // "openOrders" : 0, - // "serverTime" : 1537451465 - // } - // } - // - const balances = this.safeValue (response, 'return'); - const result = { 'info': response }; - const funds = this.safeValue (balances, 'funds'); - const currencyIds = Object.keys (funds); - for (let i = 0; i < currencyIds.length; i++) { - const currencyId = currencyIds[i]; - const code = this.safeCurrencyCode (currencyId); - const balance = this.safeValue (funds, currencyId, {}); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseTicker (ticker, market = undefined) { - // - // { high: 0.03492, - // low: 0.03245, - // avg: 29.46133, - // vol: 500.8661, - // vol_cur: 17.000797104, - // last: 0.03364, - // buy: 0.03362, - // sell: 0.03381, - // updated: 1537521993, - // pair: "ethbtc" } - // - const timestamp = this.safeTimestamp (ticker, 'updated'); - let symbol = undefined; - const marketId = this.safeString (ticker, 'pair'); - market = this.parseMarket (marketId); - if (market !== undefined) { - symbol = market['symbol']; - } - // dsx average is inverted, liqui average is not - let average = this.safeFloat (ticker, 'avg'); - if (average !== undefined) { - if (average > 0) { - average = 1 / average; - } - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_cur'), - 'info': ticker, - }; - } - - parseTrade (trade, market = undefined) { - // - // fetchTrades (public) - // - // { - // "amount" : 0.0128, - // "price" : 6483.99000, - // "timestamp" : 1540334614, - // "tid" : 35684364, - // "type" : "ask" - // } - // - // fetchMyTrades (private) - // - // { - // "number": "36635882", // <-- this is present if the trade has come from the '/order/status' call - // "id": "36635882", // <-- this may have been artifically added by the parseTrades method - // "pair": "btcusd", - // "type": "buy", - // "volume": 0.0595, - // "rate": 9750, - // "orderId": 77149299, - // "timestamp": 1519612317, - // "commission": 0.00020825, - // "commissionCurrency": "btc" - // } - // - const timestamp = this.safeTimestamp (trade, 'timestamp'); - let side = this.safeString (trade, 'type'); - if (side === 'ask') { - side = 'sell'; - } else if (side === 'bid') { - side = 'buy'; - } - const price = this.safeFloat2 (trade, 'rate', 'price'); - const id = this.safeString2 (trade, 'number', 'id'); - const orderId = this.safeString (trade, 'orderId'); - const marketId = this.safeString (trade, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const amount = this.safeFloat2 (trade, 'amount', 'volume'); - const type = 'limit'; // all trades are still limit trades - let takerOrMaker = undefined; - let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const isYourOrder = this.safeValue (trade, 'is_your_order'); - if (isYourOrder !== undefined) { - takerOrMaker = 'taker'; - if (isYourOrder) { - takerOrMaker = 'maker'; - } - if (fee === undefined) { - fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); - } - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - return { - 'id': id, - 'order': orderId, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': type, - 'side': side, - 'takerOrMaker': takerOrMaker, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - 'info': trade, - }; - } - - parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - let result = []; - if (Array.isArray (trades)) { - for (let i = 0; i < trades.length; i++) { - result.push (this.parseTrade (trades[i], market)); - } - } else { - const ids = Object.keys (trades); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const trade = this.parseTrade (trades[id], market); - result.push (this.extend (trade, { 'id': id }, params)); - } - } - result = this.sortBy (result, 'timestamp'); - const symbol = (market !== undefined) ? market['symbol'] : undefined; - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const market_id_in_reponse = (market['id'] in response); - if (!market_id_in_reponse) { - throw new ExchangeError (this.id + ' ' + market['symbol'] + ' order book is empty or not available'); - } - const orderbook = response[market['id']]; - return this.parseOrderBook (orderbook); - } - - async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let ids = undefined; - if (symbols === undefined) { - ids = this.ids.join ('-'); - // max URL length is 2083 symbols, including http schema, hostname, tld, etc... - if (ids.length > 2048) { - const numIds = this.ids.length; - throw new ExchangeError (this.id + ' has ' + numIds.toString () + ' symbols exceeding max URL length, you are required to specify a list of symbols in the first argument to fetchOrderBooks'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const result = {}; - ids = Object.keys (response); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let symbol = id; - if (id in this.markets_by_id) { - const market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseOrderBook (response[id]); - } - return result; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - let ids = this.ids; - if (symbols === undefined) { - const numIds = ids.length; - ids = ids.join ('-'); - const maxLength = this.safeInteger (this.options, 'fetchTickersMaxLength', 2048); - // max URL length is 2048 symbols, including http schema, hostname, tld, etc... - if (ids.length > this.options['fetchTickersMaxLength']) { - throw new ArgumentsRequired (this.id + ' has ' + numIds.toString () + ' markets exceeding max URL length for this endpoint (' + maxLength.toString () + ' characters), please, specify a list of symbols of interest in the first argument to fetchTickers'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - const tickers = await this.publicGetTickerPair (this.extend (request, params)); - // - // { - // "bchbtc" : { - // "high" : 0.02989, - // "low" : 0.02736, - // "avg" : 33.90585, - // "vol" : 0.65982205, - // "vol_cur" : 0.0194604180960, - // "last" : 0.03000, - // "buy" : 0.02980, - // "sell" : 0.03001, - // "updated" : 1568104614, - // "pair" : "bchbtc" - // }, - // "ethbtc" : { - // "high" : 0.01772, - // "low" : 0.01742, - // "avg" : 56.89082, - // "vol" : 229.247115044, - // "vol_cur" : 4.02959737298943, - // "last" : 0.01769, - // "buy" : 0.01768, - // "sell" : 0.01776, - // "updated" : 1568104614, - // "pair" : "ethbtc" - // } - // } - // - const result = {}; - const keys = Object.keys (tickers); - for (let k = 0; k < keys.length; k++) { - const id = keys[k]; - const ticker = tickers[id]; - let symbol = id; - let market = undefined; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseTicker (ticker, market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - const tickers = await this.fetchTickers ([ symbol ], params); - return tickers[symbol]; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; - } - const response = await this.publicGetTradesPair (this.extend (request, params)); - if (Array.isArray (response)) { - const numElements = response.length; - if (numElements === 0) { - return []; - } - } - return this.parseTrades (response[market['id']], market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // } - // - return [ - this.safeInteger (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - 'period': this.timeframes[timeframe], - }; - let method = 'publicGetLastBarsPairPeriodAmount'; - if (since === undefined) { - if (limit === undefined) { - limit = 100; // required, max 2000 - } - request['amount'] = limit; - } else { - method = 'publicGetPeriodBarsPairPeriodStartEnd'; - // in their docs they expect milliseconds - // but it returns empty arrays with milliseconds - // however, it does work properly with seconds - request['start'] = parseInt (since / 1000); - if (limit === undefined) { - request['end'] = this.seconds (); - } else { - const duration = this.parseTimeframe (timeframe) * 1000; - const end = this.sum (since, duration * limit); - request['end'] = parseInt (end / 1000); - } - } - const response = await this[method] (this.extend (request, params)); - // - // { - // "ethbtc": [ - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // }, - // { - // "high" : 0.01967, - // "open" : 0.01967, - // "low" : 0.01967, - // "close" : 0.01967, - // "amount" : 0, - // "timestamp" : 1565155680000 - // } - // ] - // } - // - const candles = this.safeValue (response, market['id'], []); - return this.parseOHLCVs (candles, market, timeframe, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (type === 'market' && price === undefined) { - throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument even for market orders, that is the worst price that you agree to fill your order for'); - } - const request = { - 'pair': market['id'], - 'type': side, - 'volume': this.amountToPrecision (symbol, amount), - 'rate': this.priceToPrecision (symbol, price), - 'orderType': type, - }; - price = parseFloat (price); - amount = parseFloat (amount); - const response = await this.privatePostOrderNew (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "received": 0, - // "remains": 10, - // "funds": { - // "BTC": { - // "total": 100, - // "available": 95 - // }, - // "USD": { - // "total": 10000, - // "available": 9995 - // }, - // "EUR": { - // "total": 1000, - // "available": 995 - // }, - // "LTC": { - // "total": 1000, - // "available": 995 - // } - // }, - // "orderId": 0, // https://github.com/ccxt/ccxt/issues/3677 - // } - // } - // - let status = 'open'; - let filled = 0.0; - let remaining = amount; - const responseReturn = this.safeValue (response, 'return'); - let id = this.safeString2 (responseReturn, 'orderId', 'order_id'); - if (id === '0') { - id = this.safeString (responseReturn, 'initOrderId', 'init_order_id'); - status = 'closed'; - } - filled = this.safeFloat (responseReturn, 'received', 0.0); - remaining = this.safeFloat (responseReturn, 'remains', amount); - const timestamp = this.milliseconds (); - return { - 'info': response, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'side': side, - 'price': price, - 'cost': price * filled, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'fee': undefined, - // 'trades': this.parseTrades (order['trades'], market), - }; - } - - parseOrderStatus (status) { - const statuses = { - '0': 'open', // Active - '1': 'closed', // Filled - '2': 'canceled', // Killed - '3': 'canceling', // Killing - '7': 'canceled', // Rejected - }; - return this.safeString (statuses, status, status); - } - - parseMarket (id) { - if (id in this.markets_by_id) { - return this.markets_by_id[id]; - } else { - // the following is a fix for - // https://github.com/ccxt/ccxt/pull/5786 - // https://github.com/ccxt/ccxt/issues/5770 - let markets_by_other_id = this.safeValue (this.options, 'markets_by_other_id'); - if (markets_by_other_id === undefined) { - this.options['markets_by_other_id'] = this.indexBy (this.markets, 'otherId'); - markets_by_other_id = this.options['markets_by_other_id']; - } - if (id in markets_by_other_id) { - return markets_by_other_id[id]; - } - } - return undefined; - } - - parseOrder (order, market = undefined) { - // - // fetchOrder - // - // { - // "number": 36635882, - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // - const id = this.safeString (order, 'id'); - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const timestamp = this.safeTimestamp (order, 'timestampCreated'); - const marketId = this.safeString (order, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const remaining = this.safeFloat (order, 'remainingVolume'); - const amount = this.safeFloat (order, 'volume'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } - } - const orderType = this.safeString (order, 'orderType'); - const side = this.safeString (order, 'type'); - let fee = undefined; - const deals = this.safeValue (order, 'deals', []); - const numDeals = deals.length; - let trades = undefined; - let lastTradeTimestamp = undefined; - if (numDeals > 0) { - trades = this.parseTrades (deals); - let feeCost = undefined; - let feeCurrency = undefined; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - if (feeCost === undefined) { - feeCost = 0; - } - feeCost = this.sum (feeCost, trade['fee']['cost']); - feeCurrency = trade['fee']['currency']; - lastTradeTimestamp = trade['timestamp']; - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'type': orderType, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': undefined, - 'cost': cost, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'status': status, - 'fee': fee, - 'trades': trades, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': parseInt (id), - }; - const response = await this.privatePostOrderStatus (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // } - // - return this.parseOrder (this.extend ({ - 'id': id, - }, response['return'])); - } - - parseOrdersById (orders, symbol = undefined, since = undefined, limit = undefined) { - const ids = Object.keys (orders); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.parseOrder (this.extend ({ - 'id': id.toString (), - }, orders[id])); - result.push (order); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - const response = await this.privatePostOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': id, - }; - const response = await this.privatePostOrderCancel (this.extend (request, params)); - return response; - } - - parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { - const result = []; - const ids = Object.keys (orders); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.extend ({ 'id': id }, orders[id]); - result.push (this.extend (this.parseOrder (order, market), params)); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - const orders = await this.fetchOrders (symbol, since, limit, params); - return this.filterBy (orders, 'status', 'closed'); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let market = undefined; - // some derived classes use camelcase notation for request fields - const request = { - // 'from': 123456789, // trade ID, from which the display starts numerical 0 (test result: liqui ignores this field) - // 'count': 1000, // the number of trades for display numerical, default = 1000 - // 'from_id': trade ID, from which the display starts numerical 0 - // 'end_id': trade ID on which the display ends numerical ∞ - // 'order': 'ASC', // sorting, default = DESC (test result: liqui ignores this field, most recent trade always goes last) - // 'since': 1234567890, // UTC start time, default = 0 (test result: liqui ignores this field) - // 'end': 1234567890, // UTC end time, default = ∞ (test result: liqui ignores this field) - // 'pair': 'eth_btc', // default = all markets - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['pair'] = market['id']; - } - if (limit !== undefined) { - request['count'] = parseInt (limit); - } - if (since !== undefined) { - request['since'] = parseInt (since / 1000); - } - const response = await this.privatePostHistoryTrades (this.extend (request, params)); - let trades = []; - if ('return' in response) { - trades = response['return']; - } - return this.parseTrades (trades, market, since, limit); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let currency = undefined; - const request = {}; - if (code !== undefined) { - currency = this.currency (code); - request['currency'] = currency['id']; - } - if (since !== undefined) { - request['since'] = since; - } - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryTransactions (this.extend (request, params)); - // - // { - // "success": 1, - // "return": [ - // { - // "id": 1, - // "timestamp": 11, - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // ] - // } - // - const transactions = this.safeValue (response, 'return', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - '1': 'failed', - '2': 'ok', - '3': 'pending', - '4': 'failed', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // "id": 1, - // "timestamp": 11, // 11 in their docs ( - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // - const timestamp = this.safeTimestamp (transaction, 'timestamp'); - let type = this.safeString (transaction, 'type'); - if (type !== undefined) { - if (type === 'Incoming') { - type = 'deposit'; - } else if (type === 'Withdraw') { - type = 'withdrawal'; - } - } - const currencyId = this.safeString (transaction, 'currency'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - return { - 'id': this.safeString (transaction, 'id'), - 'txid': this.safeString (transaction, 'txid'), - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'address': this.safeString (transaction, 'address'), - 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), - 'currency': code, - 'status': status, - 'fee': { - 'currency': code, - 'cost': this.safeFloat (transaction, 'commission'), - 'rate': undefined, - }, - 'info': transaction, - }; - } - - async createDepositAddress (code, params = {}) { - const request = { - 'new': 1, - }; - const response = await this.fetchDepositAddress (code, this.extend (request, params)); - return response; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency': currency['id'], - }; - const response = await this.dwapiPostDepositCryptoaddress (this.extend (request, params)); - const result = this.safeValue (response, 'return', {}); - const address = this.safeString (result, 'address'); - this.checkAddress (address); - return { - 'currency': code, - 'address': address, - 'tag': undefined, // not documented in DSX API - 'info': response, - }; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - const commission = this.safeValue (params, 'commission'); - if (commission === undefined) { - throw new ArgumentsRequired (this.id + ' withdraw() requires a `commission` (withdrawal fee) parameter (string)'); - } - params = this.omit (params, commission); - const request = { - 'currency': currency['id'], - 'amount': parseFloat (amount), - 'address': address, - 'commission': commission, - }; - if (tag !== undefined) { - request['address'] += ':' + tag; - } - const response = await this.dwapiPostWithdrawCrypto (this.extend (request, params)); - // - // [ - // { - // "success": 1, - // "return": { - // "transactionId": 2863073 - // } - // } - // ] - // - const data = this.safeValue (response, 'return', {}); - const id = this.safeString (data, 'transactionId'); - return { - 'info': response, - 'id': id, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'][api]; - const query = this.omit (params, this.extractParams (path)); - if (api === 'private' || api === 'dwapi') { - url += '/' + this.version + '/' + this.implodeParams (path, params); - this.checkRequiredCredentials (); - const nonce = this.nonce (); - body = this.urlencode (this.extend ({ - 'nonce': nonce, - }, query)); - const signature = this.hmac (this.encode (body), this.encode (this.secret), 'sha512', 'base64'); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': signature, - }; - } else if (api === 'public') { - url += '/' + this.implodeParams (path, params); - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - url += '/' + this.implodeParams (path, params); - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - if (Object.keys (query).length) { - body = this.json (query); - headers = { - 'Content-Type': 'application/json', - }; - } - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - if ('success' in response) { - // - // 1 - Liqui only returns the integer 'success' key from their private API - // - // { "success": 1, ... } httpCode === 200 - // { "success": 0, ... } httpCode === 200 - // - // 2 - However, exchanges derived from Liqui, can return non-integers - // - // It can be a numeric string - // { "sucesss": "1", ... } - // { "sucesss": "0", ... }, httpCode >= 200 (can be 403, 502, etc) - // - // Or just a string - // { "success": "true", ... } - // { "success": "false", ... }, httpCode >= 200 - // - // Or a boolean - // { "success": true, ... } - // { "success": false, ... }, httpCode >= 200 - // - // 3 - Oversimplified, Python PEP8 forbids comparison operator (===) of different types - // - // 4 - We do not want to copy-paste and duplicate the code of this handler to other exchanges derived from Liqui - // - // To cover points 1, 2, 3 and 4 combined this handler should work like this: - // - let success = this.safeValue (response, 'success', false); - if (typeof success === 'string') { - if ((success === 'true') || (success === '1')) { - success = true; - } else { - success = false; - } - } - if (!success) { - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'error'); - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],80:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],78:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -64775,7 +63112,7 @@ module.exports = class equos extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeVol'), + 'min': this.safeNumber (market, 'minTradeVol'), 'max': undefined, }, 'price': { @@ -64841,7 +63178,7 @@ module.exports = class equos extends Exchange { const name = this.safeString (currency, 6); const status = this.safeInteger (currency, 4); const active = (status === 1); - const fee = this.safeFloat (currency, 5); // withdraw_fee + const fee = this.safeNumber (currency, 5); // withdraw_fee return { 'id': id, 'info': currency, @@ -64933,8 +63270,8 @@ module.exports = class equos extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); return [ this.convertFromScale (price, market['precision']['price']), this.convertFromScale (amount, market['precision']['amount']), @@ -65080,9 +63417,9 @@ module.exports = class equos extends Exchange { orderId = this.safeString (trade, 'orderId'); side = this.safeStringLower (trade, 'side'); type = this.parseOrderType (this.safeString (trade, 'ordType')); - price = this.safeFloat (trade, 'lastPx'); - amount = this.safeFloat (trade, 'quoteQty'); - let feeCost = this.safeFloat (trade, 'commission'); + price = this.safeNumber (trade, 'lastPx'); + amount = this.safeNumber (trade, 'quoteQty'); + let feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { feeCost = -feeCost; const feeCurrencyId = this.safeString (trade, 'commCurrency'); @@ -65153,8 +63490,8 @@ module.exports = class equos extends Exchange { if (assetType === 'ASSET') { const currencyId = this.safeString (position, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const quantity = this.safeFloat (position, 'quantity'); - const availableQuantity = this.safeFloat (position, 'availableQuantity'); + const quantity = this.safeNumber (position, 'quantity'); + const availableQuantity = this.safeNumber (position, 'availableQuantity'); const scale = this.safeInteger (position, 'quantity_scale'); const account = this.account (); account['free'] = this.convertFromScale (availableQuantity, scale); @@ -65200,7 +63537,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -65297,7 +63634,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -65670,7 +64007,7 @@ module.exports = class equos extends Exchange { address = undefined; } const type = this.safeString (transaction, 'type'); - let amount = this.safeFloat (transaction, 'balance_change'); + let amount = this.safeNumber (transaction, 'balance_change'); if (amount === undefined) { amount = this.safeInteger (transaction, 'quantity'); const amountScale = this.safeInteger (transaction, 'quantity_scale'); @@ -65753,8 +64090,8 @@ module.exports = class equos extends Exchange { for (let i = 0; i < tradingFees.length; i++) { const tradingFee = tradingFees[i]; if (this.safeString (tradingFee, 'tier') !== undefined) { - taker[tradingFee['tier']] = this.safeFloat (tradingFee, 'taker'); - maker[tradingFee['tier']] = this.safeFloat (tradingFee, 'maker'); + taker[tradingFee['tier']] = this.safeNumber (tradingFee, 'taker'); + maker[tradingFee['tier']] = this.safeNumber (tradingFee, 'maker'); } } return { @@ -65885,28 +64222,6 @@ module.exports = class equos extends Exchange { let remaining = this.safeInteger (order, 'leavesQty'); const remainingScale = this.safeInteger (order, 'leavesQty_scale'); remaining = this.convertFromScale (remaining, remainingScale); - if (remaining <= 0) { - if ((filled !== undefined) && (amount !== undefined) && (filled < amount)) { - remaining = undefined; - } - } - if ((remaining === undefined) && (amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0); - } - let average = this.safeInteger (order, 'price', 0); - if (average === 0) { - average = undefined; - } - const averageScale = this.safeInteger (order, 'price_scale'); - average = this.convertFromScale (average, averageScale); - let cost = undefined; - if (filled !== 0) { - if (average > 0) { - cost = average * filled; - } else if (price > 0) { - cost = price * filled; - } - } let fee = undefined; const currencyId = this.safeInteger (order, 'feeInstrumentId'); const feeCurrencyCode = this.safeCurrencyCode (currencyId); @@ -65929,7 +64244,7 @@ module.exports = class equos extends Exchange { } const stopPriceScale = this.safeInteger (order, 'stopPx_scale', 0); const stopPrice = this.convertFromScale (this.safeInteger (order, 'stopPx'), stopPriceScale); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -65944,14 +64259,14 @@ module.exports = class equos extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -66101,7 +64416,7 @@ module.exports = class equos extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],81:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],79:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -66109,6 +64424,7 @@ module.exports = class equos extends Exchange { const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, InvalidOrder, ExchangeError, BadRequest, BadSymbol } = require ('./base/errors'); const { TRUNCATE, SIGNIFICANT_DIGITS } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -66321,7 +64637,7 @@ module.exports = class eterbase extends Exchange { const rule = rules[i]; const attribute = this.safeString (rule, 'attribute'); const condition = this.safeString (rule, 'condition'); - const value = this.safeFloat (rule, 'value'); + const value = this.safeNumber (rule, 'value'); if ((attribute === 'Qty') && (condition === 'Min')) { minAmount = value; } else if ((attribute === 'Qty') && (condition === 'Max')) { @@ -66411,7 +64727,7 @@ module.exports = class eterbase extends Exchange { 'type': type, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -66427,8 +64743,8 @@ module.exports = class eterbase extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMin'), - 'max': this.safeFloat (currency, 'withdrawalMax'), + 'min': this.safeNumber (currency, 'withdrawalMin'), + 'max': this.safeNumber (currency, 'withdrawalMax'), }, }, }; @@ -66455,17 +64771,17 @@ module.exports = class eterbase extends Exchange { const marketId = this.safeString (ticker, 'marketId'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const last = this.safeFloat (ticker, 'price'); - const baseVolume = this.safeFloat (ticker, 'volumeBase'); - const quoteVolume = this.safeFloat (ticker, 'volume'); + const last = this.safeNumber (ticker, 'price'); + const baseVolume = this.safeNumber (ticker, 'volumeBase'); + const quoteVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const percentage = this.safeFloat (ticker, 'change'); + const percentage = this.safeNumber (ticker, 'change'); const result = { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -66507,14 +64823,6 @@ module.exports = class eterbase extends Exchange { return this.parseTicker (response, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { @@ -66569,10 +64877,12 @@ module.exports = class eterbase extends Exchange { // "filledAt": 1556355722341 // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -66581,9 +64891,9 @@ module.exports = class eterbase extends Exchange { 'currency': feeCurrencyCode, }; } - let cost = this.safeFloat (trade, 'qty'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + let cost = this.safeNumber (trade, 'qty'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger2 (trade, 'executedAt', 'filledAt'); const tradeSide = this.safeString (trade, 'side'); @@ -66681,11 +64991,11 @@ module.exports = class eterbase extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -66748,14 +65058,13 @@ module.exports = class eterbase extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetId'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'reserved'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -66882,18 +65191,18 @@ module.exports = class eterbase extends Exchange { } else { type = 'stoplimit'; } - let price = this.safeFloat (order, 'limitPrice'); - const amount = this.safeFloat (order, 'qty'); - let remaining = this.safeFloat (order, 'remainingQty'); + let price = this.safeNumber (order, 'limitPrice'); + const amount = this.safeNumber (order, 'qty'); + let remaining = this.safeNumber (order, 'remainingQty'); let filled = undefined; - const remainingCost = this.safeFloat (order, 'remainingCost'); + const remainingCost = this.safeNumber (order, 'remainingCost'); if ((remainingCost !== undefined) && (remainingCost === 0.0)) { remaining = 0; } if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); } - const cost = this.safeFloat (order, 'cost'); + const cost = this.safeNumber (order, 'cost'); if (type === 'market') { if (price === 0.0) { if ((cost !== undefined) && (filled !== undefined)) { @@ -66910,7 +65219,7 @@ module.exports = class eterbase extends Exchange { } } const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -67083,7 +65392,7 @@ module.exports = class eterbase extends Exchange { } if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) { // for market buy it requires the amount of quote currency to spend - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); if (this.options['createMarketBuyOrderRequiresPrice']) { if (cost === undefined) { if (price !== undefined) { @@ -67246,7 +65555,7 @@ module.exports = class eterbase extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],82:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],80:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -67361,6 +65670,7 @@ module.exports = class exmo extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.2 / 100, @@ -67830,18 +66140,18 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = marketId.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const maxAmount = this.safeFloat (limit, 'max_q'); - const maxPrice = this.safeFloat (limit, 'max_p'); - const maxCost = this.safeFloat (limit, 'max_a'); - const minAmount = this.safeFloat (limit, 'min_q'); - const minPrice = this.safeFloat (limit, 'min_p'); - const minCost = this.safeFloat (limit, 'min_a'); - minAmounts[base] = Math.min (this.safeFloat (minAmounts, base, minAmount), minAmount); - maxAmounts[base] = Math.max (this.safeFloat (maxAmounts, base, maxAmount), maxAmount); - minPrices[quote] = Math.min (this.safeFloat (minPrices, quote, minPrice), minPrice); - minCosts[quote] = Math.min (this.safeFloat (minCosts, quote, minCost), minCost); - maxPrices[quote] = Math.max (this.safeFloat (maxPrices, quote, maxPrice), maxPrice); - maxCosts[quote] = Math.max (this.safeFloat (maxCosts, quote, maxCost), maxCost); + const maxAmount = this.safeNumber (limit, 'max_q'); + const maxPrice = this.safeNumber (limit, 'max_p'); + const maxCost = this.safeNumber (limit, 'max_a'); + const minAmount = this.safeNumber (limit, 'min_q'); + const minPrice = this.safeNumber (limit, 'min_p'); + const minCost = this.safeNumber (limit, 'min_a'); + minAmounts[base] = Math.min (this.safeNumber (minAmounts, base, minAmount), minAmount); + maxAmounts[base] = Math.max (this.safeNumber (maxAmounts, base, maxAmount), maxAmount); + minPrices[quote] = Math.min (this.safeNumber (minPrices, quote, minPrice), minPrice); + minCosts[quote] = Math.min (this.safeNumber (minCosts, quote, minCost), minCost); + maxPrices[quote] = Math.max (this.safeNumber (maxPrices, quote, maxPrice), maxPrice); + maxCosts[quote] = Math.max (this.safeNumber (maxCosts, quote, maxCost), maxCost); } const result = {}; for (let i = 0; i < ids.length; i++) { @@ -67858,16 +66168,16 @@ module.exports = class exmo extends Exchange { 'precision': 8, 'limits': { 'amount': { - 'min': this.safeFloat (minAmounts, code), - 'max': this.safeFloat (maxAmounts, code), + 'min': this.safeNumber (minAmounts, code), + 'max': this.safeNumber (maxAmounts, code), }, 'price': { - 'min': this.safeFloat (minPrices, code), - 'max': this.safeFloat (maxPrices, code), + 'min': this.safeNumber (minPrices, code), + 'max': this.safeNumber (maxPrices, code), }, 'cost': { - 'min': this.safeFloat (minCosts, code), - 'max': this.safeFloat (maxCosts, code), + 'min': this.safeNumber (minCosts, code), + 'max': this.safeNumber (maxCosts, code), }, }, 'info': id, @@ -67902,8 +66212,8 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = symbol.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const taker = this.safeFloat (market, 'commission_taker_percent'); - const maker = this.safeFloat (market, 'commission_maker_percent'); + const taker = this.safeNumber (market, 'commission_taker_percent'); + const maker = this.safeNumber (market, 'commission_maker_percent'); result.push ({ 'id': id, 'symbol': symbol, @@ -67916,16 +66226,16 @@ module.exports = class exmo extends Exchange { 'maker': maker / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, }, 'precision': { @@ -67998,11 +66308,11 @@ module.exports = class exmo extends Exchange { // return [ this.safeInteger (ohlcv, 't'), - this.safeFloat (ohlcv, 'o'), - this.safeFloat (ohlcv, 'h'), - this.safeFloat (ohlcv, 'l'), - this.safeFloat (ohlcv, 'c'), - this.safeFloat (ohlcv, 'v'), + this.safeNumber (ohlcv, 'o'), + this.safeNumber (ohlcv, 'h'), + this.safeNumber (ohlcv, 'l'), + this.safeNumber (ohlcv, 'c'), + this.safeNumber (ohlcv, 'v'), ]; } @@ -68018,14 +66328,14 @@ module.exports = class exmo extends Exchange { const currencyId = this.currencyId (code); const account = this.account (); if (currencyId in free) { - account['free'] = this.safeFloat (free, currencyId); + account['free'] = this.safeString (free, currencyId); } if (currencyId in used) { - account['used'] = this.safeFloat (used, currencyId); + account['used'] = this.safeString (used, currencyId); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -68083,16 +66393,16 @@ module.exports = class exmo extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -68101,9 +66411,9 @@ module.exports = class exmo extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_curr'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'vol_curr'), 'info': ticker, }; } @@ -68164,9 +66474,9 @@ module.exports = class exmo extends Exchange { let symbol = undefined; const id = this.safeString (trade, 'trade_id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'quantity'); + const cost = this.safeNumber (trade, 'amount'); const side = this.safeString (trade, 'type'); const type = undefined; const marketId = this.safeString (trade, 'pair'); @@ -68185,11 +66495,11 @@ module.exports = class exmo extends Exchange { } const takerOrMaker = this.safeString (trade, 'exec_type'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission_amount'); + const feeCost = this.safeNumber (trade, 'commission_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commission_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (trade, 'commission_percent'); + let feeRate = this.safeNumber (trade, 'commission_percent'); if (feeRate !== undefined) { feeRate /= 1000; } @@ -68488,13 +66798,13 @@ module.exports = class exmo extends Exchange { market = this.markets_by_id[marketId]; } } - let amount = this.safeFloat (order, 'quantity'); + let amount = this.safeNumber (order, 'quantity'); if (amount === undefined) { const amountField = (side === 'buy') ? 'in_amount' : 'out_amount'; - amount = this.safeFloat (order, amountField); + amount = this.safeNumber (order, amountField); } - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'amount'); + let price = this.safeNumber (order, 'price'); + let cost = this.safeNumber (order, 'amount'); let filled = 0.0; const trades = []; const transactions = this.safeValue (order, 'trades', []); @@ -68615,24 +66925,6 @@ module.exports = class exmo extends Exchange { return undefined; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -68677,7 +66969,7 @@ module.exports = class exmo extends Exchange { // } // const timestamp = this.safeTimestamp (transaction, 'dt'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -68707,7 +66999,7 @@ module.exports = class exmo extends Exchange { // fixed funding fees only (for now) if (!this.fees['funding']['percentage']) { const key = (type === 'withdrawal') ? 'withdraw' : 'deposit'; - let feeCost = this.safeFloat (this.options['fundingFees'][key], code); + let feeCost = this.safeNumber (this.options['fundingFees'][key], code); // users don't pay for cashbacks, no fees for that const provider = this.safeString (transaction, 'provider'); if (provider === 'cashback') { @@ -68854,13 +67146,14 @@ module.exports = class exmo extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],83:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],81:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ExchangeNotAvailable, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -69005,26 +67298,26 @@ module.exports = class exx extends Exchange { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); ticker = ticker['ticker']; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'riseRate'), + 'change': this.safeNumber (ticker, 'riseRate'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -69074,14 +67367,11 @@ module.exports = class exx extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -69126,14 +67416,13 @@ module.exports = class exx extends Exchange { const currencyId = currencies[i]; const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'balance'), - 'used': this.safeFloat (balance, 'freeze'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -69153,11 +67442,10 @@ module.exports = class exx extends Exchange { // const symbol = market['symbol']; const timestamp = parseInt (order['trade_date']); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'trade_money'); - const amount = this.safeFloat (order, 'total_amount'); - const filled = this.safeFloat (order, 'trade_amount', 0.0); - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'trade_money'); + const amount = this.safeNumber (order, 'total_amount'); + const filled = this.safeNumber (order, 'trade_amount', 0.0); let status = this.safeInteger (order, 'status'); if (status === 1) { status = 'canceled'; @@ -69169,11 +67457,11 @@ module.exports = class exx extends Exchange { let fee = undefined; if ('fees' in order) { fee = { - 'cost': this.safeFloat (order, 'fees'), + 'cost': this.safeNumber (order, 'fees'), 'currency': market['quote'], }; } - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -69190,12 +67478,12 @@ module.exports = class exx extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -69320,13 +67608,14 @@ module.exports = class exx extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],84:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],82:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, ArgumentsRequired, InsufficientFunds, InvalidOrder, RateLimitExceeded, InvalidNonce, AuthenticationError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -69546,8 +67835,8 @@ module.exports = class fcoin extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'limit_amount_min'), - 'max': this.safeFloat (market, 'limit_amount_max'), + 'min': this.safeNumber (market, 'limit_amount_min'), + 'max': this.safeNumber (market, 'limit_amount_max'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -69642,12 +67931,12 @@ module.exports = class fcoin extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidsAsks (orders, priceKey = 0, amountKey = 1) { @@ -69660,8 +67949,8 @@ module.exports = class fcoin extends Exchange { const priceField = this.sum (index, priceKey); const amountField = this.sum (index, amountKey); result.push ([ - this.safeFloat (orders, priceField), - this.safeFloat (orders, amountField), + this.safeNumber (orders, priceField), + this.safeNumber (orders, amountField), ]); } return result; @@ -69709,17 +67998,17 @@ module.exports = class fcoin extends Exchange { } } const values = ticker['ticker']; - const last = this.safeFloat (values, 0); + const last = this.safeNumber (values, 0); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (values, 7), - 'low': this.safeFloat (values, 8), - 'bid': this.safeFloat (values, 2), - 'bidVolume': this.safeFloat (values, 3), - 'ask': this.safeFloat (values, 4), - 'askVolume': this.safeFloat (values, 5), + 'high': this.safeNumber (values, 7), + 'low': this.safeNumber (values, 8), + 'bid': this.safeNumber (values, 2), + 'bidVolume': this.safeNumber (values, 3), + 'ask': this.safeNumber (values, 4), + 'askVolume': this.safeNumber (values, 5), 'vwap': undefined, 'open': undefined, 'close': last, @@ -69728,8 +68017,8 @@ module.exports = class fcoin extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (values, 9), - 'quoteVolume': this.safeFloat (values, 10), + 'baseVolume': this.safeNumber (values, 9), + 'quoteVolume': this.safeNumber (values, 10), 'info': ticker, }; } @@ -69742,14 +68031,11 @@ module.exports = class fcoin extends Exchange { const timestamp = this.safeInteger (trade, 'ts'); const side = this.safeStringLower (trade, 'side'); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = undefined; return { 'id': id, @@ -69874,38 +68160,25 @@ module.exports = class fcoin extends Exchange { const symbol = market['symbol']; const orderType = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'created_at'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'executed_value'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'executed_value'); let feeCurrency = undefined; let feeCost = undefined; - const feeRebate = this.safeFloat (order, 'fees_income'); + const feeRebate = this.safeNumber (order, 'fees_income'); if ((feeRebate !== undefined) && (feeRebate > 0)) { if (market !== undefined) { feeCurrency = (side === 'buy') ? market['quote'] : market['base']; } feeCost = -feeRebate; } else { - feeCost = this.safeFloat (order, 'fill_fees'); + feeCost = this.safeNumber (order, 'fill_fees'); if (market !== undefined) { feeCurrency = (side === 'buy') ? market['base'] : market['quote']; } } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -69921,7 +68194,7 @@ module.exports = class fcoin extends Exchange { 'stopPrice': undefined, 'cost': cost, 'amount': amount, - 'remaining': remaining, + 'remaining': undefined, 'filled': filled, 'average': undefined, 'status': status, @@ -69930,7 +68203,7 @@ module.exports = class fcoin extends Exchange { 'currency': feeCurrency, }, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -69972,11 +68245,11 @@ module.exports = class fcoin extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_vol'), ]; } @@ -70065,7 +68338,7 @@ module.exports = class fcoin extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],85:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],83:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -70091,13 +68364,14 @@ module.exports = class fcoinjp extends fcoin { } }; -},{"./fcoin.js":84}],86:[function(require,module,exports){ +},{"./fcoin.js":82}],84:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70225,11 +68499,11 @@ module.exports = class flowbtc extends Exchange { const currencyId = balance['name']; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['total'] = this.safeFloat (balance, 'hold'); + account['free'] = this.safeString (balance, 'balance'); + account['total'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -70250,16 +68524,16 @@ module.exports = class flowbtc extends Exchange { }; const ticker = await this.publicPostGetTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -70269,8 +68543,8 @@ module.exports = class flowbtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume24hr'), - 'quoteVolume': this.safeFloat (ticker, 'volume24hrProduct2'), + 'baseVolume': this.safeNumber (ticker, 'volume24hr'), + 'quoteVolume': this.safeNumber (ticker, 'volume24hrProduct2'), 'info': ticker, }; } @@ -70279,14 +68553,11 @@ module.exports = class flowbtc extends Exchange { const timestamp = this.safeTimestamp (trade, 'unixtime'); const side = (trade['incomingOrderSide'] === 0) ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'px'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'px'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'timestamp': timestamp, @@ -70377,13 +68648,14 @@ module.exports = class flowbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],87:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],85:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70469,11 +68741,11 @@ module.exports = class foxbit extends Exchange { // otherwise we will lose the info if the currency balance has been funded or traded or not if (currencyId in balances) { const account = this.account (); - let used = this.safeFloat (balances, currencyId + '_locked'); + let used = this.safeNumber (balances, currencyId + '_locked'); if (used !== undefined) { used *= 1e-8; } - let total = this.safeFloat (balances, currencyId); + let total = this.safeNumber (balances, currencyId); if (total !== undefined) { total *= 1e-8; } @@ -70508,16 +68780,16 @@ module.exports = class foxbit extends Exchange { const timestamp = this.milliseconds (); const lowercaseQuote = market['quote'].toLowerCase (); const quoteVolume = 'vol_' + lowercaseQuote; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -70527,8 +68799,8 @@ module.exports = class foxbit extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -70541,14 +68813,11 @@ module.exports = class foxbit extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -70642,14 +68911,15 @@ module.exports = class foxbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],88:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],86:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending } = require ('./base/errors'); +const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending, ArgumentsRequired, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -70888,6 +69158,7 @@ module.exports = class ftx extends Exchange { 'An unexpected error occurred': ExchangeNotAvailable, // {"error":"An unexpected error occurred, please try again later (58BC21C795).","success":false} 'Please retry request': ExchangeNotAvailable, // {"error":"Please retry request","success":false} 'Please try again': ExchangeNotAvailable, // {"error":"Please try again","success":false} + 'Only have permissions for subaccount': PermissionDenied, // {"success":false,"error":"Only have permissions for subaccount *sub_name*"} }, }, 'precisionMode': TICK_SIZE, @@ -71011,8 +69282,8 @@ module.exports = class ftx extends Exchange { // check if a market is a spot or future market const symbol = (type === 'future') ? this.safeString (market, 'name') : (base + '/' + quote); const active = this.safeValue (market, 'enabled'); - const sizeIncrement = this.safeFloat (market, 'sizeIncrement'); - const priceIncrement = this.safeFloat (market, 'priceIncrement'); + const sizeIncrement = this.safeNumber (market, 'sizeIncrement'); + const priceIncrement = this.safeNumber (market, 'priceIncrement'); const precision = { 'amount': sizeIncrement, 'price': priceIncrement, @@ -71090,28 +69361,28 @@ module.exports = class ftx extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); const timestamp = this.safeTimestamp (ticker, 'time', this.milliseconds ()); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'change24h'), + 'percentage': this.safeNumber (ticker, 'change24h'), 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24h'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24h'), 'info': ticker, }; } @@ -71151,14 +69422,6 @@ module.exports = class ftx extends Exchange { return this.parseTicker (result, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetMarkets (params); @@ -71237,11 +69500,11 @@ module.exports = class ftx extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -71362,6 +69625,45 @@ module.exports = class ftx extends Exchange { // "type": "otc" // } // + // with -ve fee + // { + // "id": 1171258927, + // "fee": -0.0000713875, + // "side": "sell", + // "size": 1, + // "time": "2021-03-11T13:34:35.523627+00:00", + // "type": "order", + // "price": 14.2775, + // "future": null, + // "market": "SOL/USD", + // "feeRate": -0.000005, + // "orderId": 33182929044, + // "tradeId": 582936801, + // "liquidity": "maker", + // "feeCurrency": "USD", + // "baseCurrency": "SOL", + // "quoteCurrency": "USD" + // } + // + // // from OTC order + // { + // "id": 1172129651, + // "fee": 0, + // "side": "sell", + // "size": 1.47568846, + // "time": "2021-03-11T15:04:46.893383+00:00", + // "type": "otc", + // "price": 14.60932598, + // "future": null, + // "market": null, + // "feeRate": 0, + // "orderId": null, + // "tradeId": null, + // "liquidity": "taker", + // "feeCurrency": "USD", + // "baseCurrency": "BCHA", + // "quoteCurrency": "USD" + // } const id = this.safeString (trade, 'id'); const takerOrMaker = this.safeString (trade, 'liquidity'); const marketId = this.safeString (trade, 'market'); @@ -71379,25 +69681,24 @@ module.exports = class ftx extends Exchange { } } const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } const orderId = this.safeString (trade, 'orderId'); @@ -71503,8 +69804,8 @@ module.exports = class ftx extends Exchange { const result = this.safeValue (response, 'result', {}); return { 'info': response, - 'maker': this.safeFloat (result, 'makerFee'), - 'taker': this.safeFloat (result, 'takerFee'), + 'maker': this.safeNumber (result, 'makerFee'), + 'taker': this.safeNumber (result, 'takerFee'), }; } @@ -71531,11 +69832,11 @@ module.exports = class ftx extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'coin')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -71658,9 +69959,9 @@ module.exports = class ftx extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); let status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filledSize'); - let remaining = this.safeFloat (order, 'remainingSize'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filledSize'); + let remaining = this.safeNumber (order, 'remainingSize'); if ((remaining === 0.0) && (amount !== undefined) && (filled !== undefined)) { remaining = Math.max (amount - filled, 0); if (remaining > 0) { @@ -71684,15 +69985,15 @@ module.exports = class ftx extends Exchange { } const side = this.safeString (order, 'side'); const type = this.safeString (order, 'type'); - const average = this.safeFloat (order, 'avgFillPrice'); - const price = this.safeFloat2 (order, 'price', 'triggerPrice', average); + const average = this.safeNumber (order, 'avgFillPrice'); + const price = this.safeNumber2 (order, 'price', 'triggerPrice', average); let cost = undefined; if (filled !== undefined && price !== undefined) { cost = filled * price; } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'triggeredAt')); const clientOrderId = this.safeString (order, 'clientId'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -71738,22 +70039,28 @@ module.exports = class ftx extends Exchange { request['clientId'] = clientOrderId; params = this.omit (params, [ 'clientId', 'clientOrderId' ]); } - let priceToPrecision = undefined; - if (price !== undefined) { - priceToPrecision = parseFloat (this.priceToPrecision (symbol, price)); - } - let method = 'privatePostConditionalOrders'; + let method = undefined; if (type === 'limit') { method = 'privatePostOrders'; - request['price'] = priceToPrecision; + request['price'] = parseFloat (this.priceToPrecision (symbol, price)); } else if (type === 'market') { method = 'privatePostOrders'; request['price'] = null; } else if ((type === 'stop') || (type === 'takeProfit')) { - request['triggerPrice'] = priceToPrecision; - // request['orderPrice'] = number; // optional, order type is limit if this is specified, otherwise market + method = 'privatePostConditionalOrders'; + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerPrice'); + if (stopPrice === undefined) { + throw new ArgumentsRequired (this.id + ' createOrder () requires a stopPrice parameter or a triggerPrice parameter for ' + type + ' orders'); + } else { + params = this.omit (params, [ 'stopPrice', 'triggerPrice' ]); + request['triggerPrice'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + } + if (price !== undefined) { + request['orderPrice'] = parseFloat (this.priceToPrecision (symbol, price)); // optional, order type is limit if this is specified, otherwise market + } } else if (type === 'trailingStop') { - request['trailValue'] = priceToPrecision; // negative for "sell", positive for "buy" + method = 'privatePostConditionalOrders'; + request['trailValue'] = parseFloat (this.priceToPrecision (symbol, price)); // negative for "sell", positive for "buy" } else { throw new InvalidOrder (this.id + ' createOrder () does not support order type ' + type + ', only limit, market, stop, trailingStop, or takeProfit orders are supported'); } @@ -71819,9 +70126,9 @@ module.exports = class ftx extends Exchange { const request = {}; let method = undefined; const clientOrderId = this.safeString2 (params, 'client_order_id', 'clientOrderId'); - const triggerPrice = this.safeFloat (params, 'triggerPrice'); - const orderPrice = this.safeFloat (params, 'orderPrice'); - const trailValue = this.safeFloat (params, 'trailValue'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); + const orderPrice = this.safeNumber (params, 'orderPrice'); + const trailValue = this.safeNumber (params, 'trailValue'); params = this.omit (params, [ 'client_order_id', 'clientOrderId', 'triggerPrice', 'orderPrice', 'trailValue' ]); const triggerPriceIsDefined = (triggerPrice !== undefined); const orderPriceIsDefined = (orderPrice !== undefined); @@ -72184,7 +70491,7 @@ module.exports = class ftx extends Exchange { return this.parseTransaction (result, currency); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetAccount (params); // @@ -72317,7 +70624,7 @@ module.exports = class ftx extends Exchange { // const code = this.safeCurrencyCode (this.safeString (transaction, 'coin')); const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'size'); + const amount = this.safeNumber (transaction, 'size'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const txid = this.safeString (transaction, 'txid'); @@ -72334,7 +70641,7 @@ module.exports = class ftx extends Exchange { address = notes.slice (12); } } - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -72469,13 +70776,14 @@ module.exports = class ftx extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],89:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],87:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, ArgumentsRequired, InvalidAddress, OrderNotFound, NotSupported, DDoSProtection, InsufficientFunds, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -72636,9 +70944,12 @@ module.exports = class gateio extends Exchange { }, }, 'commonCurrencies': { + '88MPH': 'MPH', + 'BIFI': 'Bitcoin File', 'BOX': 'DefiBox', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', + 'MPH': 'Morpher', // conflict with 88MPH 'SBTC': 'Super Bitcoin', 'TNC': 'Trinity Network Credit', }, @@ -72685,9 +70996,9 @@ module.exports = class gateio extends Exchange { const currency = coin[id]; const code = this.safeCurrencyCode (id); const delisted = this.safeValue (currency, 'delisted', 0); - const withdrawDisabled = this.safeValue (currency, 'withdraw_disabled', 0); - const depositDisabled = this.safeValue (currency, 'deposit_disabled', 0); - const tradeDisabled = this.safeValue (currency, 'trade_disabled', 0); + const withdrawDisabled = this.safeInteger2 (currency, 'withdraw_disabled', 0); + const depositDisabled = this.safeInteger2 (currency, 'deposit_disabled', 0); + const tradeDisabled = this.safeInteger2 (currency, 'trade_disabled', 0); const listed = (delisted === 0); const withdrawEnabled = (withdrawDisabled === 0); const depositEnabled = (depositDisabled === 0); @@ -72776,7 +71087,7 @@ module.exports = class gateio extends Exchange { 'price': this.safeInteger (details, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (details, 'min_amount'), + 'min': this.safeNumber (details, 'min_amount'), 'max': undefined, }; const priceLimits = { @@ -72784,7 +71095,7 @@ module.exports = class gateio extends Exchange { 'max': undefined, }; const defaultCost = amountLimits['min'] * priceLimits['min']; - const minCost = this.safeFloat (this.options['limits']['cost']['min'], quote, defaultCost); + const minCost = this.safeNumber (this.options['limits']['cost']['min'], quote, defaultCost); const costLimits = { 'min': minCost, 'max': undefined, @@ -72794,10 +71105,10 @@ module.exports = class gateio extends Exchange { 'price': priceLimits, 'cost': costLimits, }; - const disabled = this.safeValue (details, 'trade_disabled'); + const disabled = this.safeInteger (details, 'trade_disabled'); const active = !disabled; const uppercaseId = id.toUpperCase (); - const fee = this.safeFloat (details, 'fee'); + const fee = this.safeNumber (details, 'fee'); result.push ({ 'id': id, 'uppercaseId': uppercaseId, @@ -72831,11 +71142,11 @@ module.exports = class gateio extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (available, currencyId); - account['used'] = this.safeFloat (locked, currencyId); + account['free'] = this.safeString (available, currencyId); + account['used'] = this.safeString (locked, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -72851,11 +71162,11 @@ module.exports = class gateio extends Exchange { // they return [ Timestamp, Volume, Close, High, Low, Open ] return [ this.safeInteger (ohlcv, 0), // t - this.safeFloat (ohlcv, 5), // o - this.safeFloat (ohlcv, 3), // h - this.safeFloat (ohlcv, 4), // l - this.safeFloat (ohlcv, 2), // c - this.safeFloat (ohlcv, 1), // v + this.safeNumber (ohlcv, 5), // o + this.safeNumber (ohlcv, 3), // h + this.safeNumber (ohlcv, 4), // l + this.safeNumber (ohlcv, 2), // c + this.safeNumber (ohlcv, 1), // v ]; } @@ -72867,11 +71178,11 @@ module.exports = class gateio extends Exchange { 'group_sec': this.timeframes[timeframe], }; // max limit = 1001 - if (limit !== undefined) { - const periodDurationInSeconds = this.parseTimeframe (timeframe); - const hours = parseInt ((periodDurationInSeconds * limit) / 3600); - request['range_hour'] = Math.max (0, hours - 1); - } + // if (limit !== undefined) { + // const periodDurationInSeconds = this.parseTimeframe (timeframe); + // const hours = parseInt ((periodDurationInSeconds * limit) / 3600); + // request['range_hour'] = Math.max (1, hours - 1); + // } const response = await this.publicGetCandlestick2Id (this.extend (request, params)); // // { @@ -72895,8 +71206,8 @@ module.exports = class gateio extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'percentChange'); let open = undefined; let change = undefined; let average = undefined; @@ -72906,17 +71217,17 @@ module.exports = class gateio extends Exchange { change = last - open; average = this.sum (last, open) / 2; } - open = this.safeFloat (ticker, 'open', open); - change = this.safeFloat (ticker, 'change', change); + open = this.safeNumber (ticker, 'open', open); + change = this.safeNumber (ticker, 'change', change); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high24hr', 'high'), - 'low': this.safeFloat2 (ticker, 'low24hr', 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber2 (ticker, 'high24hr', 'high'), + 'low': this.safeNumber2 (ticker, 'low24hr', 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -72926,8 +71237,8 @@ module.exports = class gateio extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), // gateio has them reversed - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), // gateio has them reversed + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -72973,27 +71284,24 @@ module.exports = class gateio extends Exchange { const id = this.safeString2 (trade, 'tradeID', 'id'); // take either of orderid or orderId const orderId = this.safeString2 (trade, 'orderid', 'orderNumber'); - const price = this.safeFloat2 (trade, 'rate', 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString2 (trade, 'rate', 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'role'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } let fee = undefined; let feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee_coin')); - let feeCost = this.safeFloat (trade, 'point_fee'); + let feeCost = this.safeNumber (trade, 'point_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'gt_fee'); + feeCost = this.safeNumber (trade, 'gt_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'fee'); + feeCost = this.safeNumber (trade, 'fee'); } else { feeCurrency = this.safeCurrencyCode ('GT'); } @@ -73137,23 +71445,20 @@ module.exports = class gateio extends Exchange { } else if (side === '2') { side = 'buy'; } - const price = this.safeFloat2 (order, 'initialRate', 'rate'); - const average = this.safeFloat (order, 'filledRate'); - const amount = this.safeFloat2 (order, 'initialAmount', 'amount'); - const filled = this.safeFloat (order, 'filledAmount'); + const price = this.safeNumber2 (order, 'initialRate', 'rate'); + const average = this.safeNumber (order, 'filledRate'); + const amount = this.safeNumber2 (order, 'initialAmount', 'amount'); + const filled = this.safeNumber (order, 'filledAmount'); // In the order status response, this field has a different name. - let remaining = this.safeFloat2 (order, 'leftAmount', 'left'); - if (remaining === undefined) { - remaining = amount - filled; - } - const feeCost = this.safeFloat (order, 'feeValue'); + const remaining = this.safeNumber2 (order, 'leftAmount', 'left'); + const feeCost = this.safeNumber (order, 'feeValue'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (order, 'feePercentage'); + let feeRate = this.safeNumber (order, 'feePercentage'); if (feeRate !== undefined) { feeRate = feeRate / 100; } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -73179,7 +71484,7 @@ module.exports = class gateio extends Exchange { 'rate': feeRate, }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -73370,7 +71675,7 @@ module.exports = class gateio extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'txid'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); if (address === 'false') { address = undefined; @@ -73378,7 +71683,7 @@ module.exports = class gateio extends Exchange { const timestamp = this.safeTimestamp (transaction, 'timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.parseTransactionType (id[0]); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -73467,7 +71772,7 @@ module.exports = class gateio extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],90:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],88:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -73475,6 +71780,7 @@ module.exports = class gateio extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidOrder, InvalidNonce, InsufficientFunds, AuthenticationError, PermissionDenied, NotSupported, OnMaintenance, RateLimitExceeded, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -73691,16 +71997,16 @@ module.exports = class gemini extends Exchange { // const base = this.safeCurrencyCode (baseId); const minAmountString = cells[1].replace ('', ''); const minAmountParts = minAmountString.split (' '); - const minAmount = this.safeFloat (minAmountParts, 0); + const minAmount = this.safeNumber (minAmountParts, 0); const amountPrecisionString = cells[2].replace ('', ''); const amountPrecisionParts = amountPrecisionString.split (' '); - const amountPrecision = this.safeFloat (amountPrecisionParts, 0); + const amountPrecision = this.safeNumber (amountPrecisionParts, 0); const idLength = marketId.length - 0; const quoteId = marketId.slice (idLength - 3, idLength); const quote = this.safeCurrencyCode (quoteId); const pricePrecisionString = cells[3].replace ('', ''); const pricePrecisionParts = pricePrecisionString.split (' '); - const pricePrecision = this.safeFloat (pricePrecisionParts, 0); + const pricePrecision = this.safeNumber (pricePrecisionParts, 0); const baseId = marketId.replace (quoteId, ''); const base = this.safeCurrencyCode (baseId); const symbol = base + '/' + quote; @@ -73928,11 +72234,11 @@ module.exports = class gemini extends Exchange { base = market['base']; quote = market['quote']; } - const price = this.safeFloat (ticker, 'price'); - const last = this.safeFloat2 (ticker, 'last', 'close', price); - let percentage = this.safeFloat (ticker, 'percentChange24h'); + const price = this.safeNumber (ticker, 'price'); + const last = this.safeNumber2 (ticker, 'last', 'close', price); + let percentage = this.safeNumber (ticker, 'percentChange24h'); let change = undefined; - let open = this.safeFloat (ticker, 'open'); + let open = this.safeNumber (ticker, 'open'); let average = undefined; if (last !== undefined) { if (open !== undefined) { @@ -73949,18 +72255,18 @@ module.exports = class gemini extends Exchange { average = this.sum (last, open) / 2; } } - const baseVolume = this.safeFloat (volume, baseId); - const quoteVolume = this.safeFloat (volume, quoteId); + const baseVolume = this.safeNumber (volume, baseId); + const quoteVolume = this.safeNumber (volume, quoteId); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -73976,14 +72282,6 @@ module.exports = class gemini extends Exchange { }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetV1Pricefeed (params); @@ -74024,17 +72322,14 @@ module.exports = class gemini extends Exchange { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); const fee = { - 'cost': this.safeFloat (trade, 'fee_amount'), + 'cost': this.safeNumber (trade, 'fee_amount'), 'currency': feeCurrencyCode, }; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeStringLower (trade, 'type'); const symbol = this.safeSymbol (undefined, market); @@ -74087,18 +72382,18 @@ module.exports = class gemini extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'timestampms'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const filled = this.safeFloat (order, 'executed_amount'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const filled = this.safeNumber (order, 'executed_amount'); let status = 'closed'; if (order['is_live']) { status = 'open'; @@ -74106,14 +72401,8 @@ module.exports = class gemini extends Exchange { if (order['is_cancelled']) { status = 'canceled'; } - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_execution_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_execution_price'); let type = this.safeString (order, 'type'); if (type === 'exchange limit') { type = 'limit'; @@ -74128,7 +72417,7 @@ module.exports = class gemini extends Exchange { const id = this.safeString (order, 'order_id'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'client_order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -74144,13 +72433,13 @@ module.exports = class gemini extends Exchange { 'price': price, 'stopPrice': undefined, 'average': average, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -74265,7 +72554,7 @@ module.exports = class gemini extends Exchange { status = 'ok'; } let fee = undefined; - const feeAmount = this.safeFloat (transaction, 'feeAmount'); + const feeAmount = this.safeNumber (transaction, 'feeAmount'); if (feeAmount !== undefined) { fee = { 'cost': feeAmount, @@ -74281,7 +72570,7 @@ module.exports = class gemini extends Exchange { 'address': address, 'tag': undefined, // or is it defined? 'type': type, // direction of the transaction, ('deposit' | 'withdraw') - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': undefined, @@ -74380,7 +72669,7 @@ module.exports = class gemini extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],91:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],89:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -74388,6 +72677,7 @@ module.exports = class gemini extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound, InvalidAddress, BadRequest } = require ('./base/errors'); const { TRUNCATE, ROUND, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -74601,8 +72891,8 @@ module.exports = class gopax extends Exchange { const minimums = this.safeValue (market, 'restApiOrderAmountMin', {}); const marketAsk = this.safeValue (minimums, 'marketAsk', {}); const marketBid = this.safeValue (minimums, 'marketBid', {}); - const takerFeePercent = this.safeFloat (market, 'takerFeePercent'); - const makerFeePercent = this.safeFloat (market, 'makerFeePercent'); + const takerFeePercent = this.safeNumber (market, 'takerFeePercent'); + const makerFeePercent = this.safeNumber (market, 'makerFeePercent'); const taker = parseFloat (this.decimalToPrecision (takerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); const maker = parseFloat (this.decimalToPrecision (makerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); result.push ({ @@ -74620,15 +72910,15 @@ module.exports = class gopax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (marketAsk, 'amount'), + 'min': this.safeNumber (marketAsk, 'amount'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'priceMin'), + 'min': this.safeNumber (market, 'priceMin'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (marketBid, 'amount'), + 'min': this.safeNumber (marketBid, 'amount'), 'max': undefined, }, }, @@ -74663,8 +72953,8 @@ module.exports = class gopax extends Exchange { const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'name'); - const fee = this.safeFloat (currency, 'withdrawalFee'); - const precision = this.safeFloat (currency, 'scale'); + const fee = this.safeNumber (currency, 'withdrawalFee'); + const precision = this.safeNumber (currency, 'scale'); result[code] = { 'id': id, 'info': currency, @@ -74687,7 +72977,7 @@ module.exports = class gopax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalAmountMin'), + 'min': this.safeNumber (currency, 'withdrawalAmountMin'), 'max': undefined, }, }, @@ -74755,8 +73045,8 @@ module.exports = class gopax extends Exchange { const marketId = this.safeString (ticker, 'name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (ticker, 'time')); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat2 (ticker, 'price', 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'price', 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -74767,20 +73057,20 @@ module.exports = class gopax extends Exchange { percentage = change / open * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidVolume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askVolume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidVolume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askVolume'), 'vwap': vwap, 'open': open, 'close': last, @@ -74816,14 +73106,6 @@ module.exports = class gopax extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTradingPairsStats (params); @@ -74845,8 +73127,8 @@ module.exports = class gopax extends Exchange { parsePublicTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let symbol = undefined; if ('symbol' in market) { symbol = this.safeString (market, 'symbol'); @@ -74872,14 +73154,14 @@ module.exports = class gopax extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const symbol = this.safeString (trade, 'tradingPairName').replace ('-', '/'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'baseAmount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'baseAmount'); let feeCurrency = symbol.slice (0, 3); if (side === 'sell') { feeCurrency = symbol.slice (4); } const fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': feeCurrency, 'rate': undefined, }; @@ -74961,15 +73243,15 @@ module.exports = class gopax extends Exchange { } else if (type === '2') { type = 'market'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'baseAmount'); - let cost = this.safeFloat (trade, 'quoteAmount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'baseAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteAmount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -75036,11 +73318,11 @@ module.exports = class gopax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -75080,14 +73362,14 @@ module.exports = class gopax extends Exchange { const balance = response[i]; const currencyId = this.safeString2 (balance, 'asset', 'isoAlpha3'); const code = this.safeCurrencyCode (currencyId); - const hold = this.safeFloat (balance, 'hold'); - const pendingWithdrawal = this.safeFloat (balance, 'pendingWithdrawal'); + const hold = this.safeString (balance, 'hold'); + const pendingWithdrawal = this.safeString (balance, 'pendingWithdrawal'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.sum (hold, pendingWithdrawal); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = Precise.stringAdd (hold, pendingWithdrawal); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -75164,42 +73446,36 @@ module.exports = class gopax extends Exchange { const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); const timeInForce = this.safeStringUpper (order, 'timeInForce'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - const remaining = this.safeFloat (order, 'remaining'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const stopPrice = this.safeNumber (order, 'stopPrice'); + const remaining = this.safeNumber (order, 'remaining'); const marketId = this.safeString (order, 'tradingPairName'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const balanceChange = this.safeValue (order, 'balanceChange', {}); - let filled = this.safeFloat (balanceChange, 'baseNet'); - let cost = this.safeFloat (balanceChange, 'quoteNet'); + const filled = this.safeNumber (balanceChange, 'baseNet'); + let cost = this.safeNumber (balanceChange, 'quoteNet'); if (cost !== undefined) { cost = Math.abs (cost); } let updated = undefined; - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } if ((filled !== undefined) && (filled > 0)) { updated = this.parse8601 (this.safeString (order, 'updatedAt')); } - if ((cost === undefined) && (price !== undefined) && (filled !== undefined)) { - cost = filled * price; - } let fee = undefined; if (side === 'buy') { const baseFee = this.safeValue (balanceChange, 'baseFee', {}); - const taking = this.safeFloat (baseFee, 'taking'); - const making = this.safeFloat (baseFee, 'making'); + const taking = this.safeNumber (baseFee, 'taking'); + const making = this.safeNumber (baseFee, 'making'); fee = { 'currency': market['base'], 'cost': this.sum (taking, making), }; } else { const quoteFee = this.safeValue (balanceChange, 'quoteFee', {}); - const taking = this.safeFloat (quoteFee, 'taking'); - const making = this.safeFloat (quoteFee, 'making'); + const taking = this.safeNumber (quoteFee, 'taking'); + const making = this.safeNumber (quoteFee, 'making'); fee = { 'currency': market['quote'], 'cost': this.sum (taking, making), @@ -75209,7 +73485,7 @@ module.exports = class gopax extends Exchange { if (timeInForce !== undefined) { postOnly = (timeInForce === 'PO'); } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'datetime': this.iso8601 (timestamp), @@ -75231,7 +73507,7 @@ module.exports = class gopax extends Exchange { 'trades': undefined, 'fee': fee, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -75379,7 +73655,7 @@ module.exports = class gopax extends Exchange { request['clientOrderId'] = clientOrderId; params = this.omit (params, 'clientOrderId'); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -75508,18 +73784,6 @@ module.exports = class gopax extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetCryptoDepositAddresses (params); @@ -75584,8 +73848,8 @@ module.exports = class gopax extends Exchange { } else if ((type === 'crypto_deposit' || type === 'fiat_deposit')) { type = 'deposit'; } - const amount = this.safeFloat (transaction, 'netAmount'); - const feeCost = this.safeFloat (transaction, 'feeAmount'); + const amount = this.safeNumber (transaction, 'netAmount'); + const feeCost = this.safeNumber (transaction, 'feeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -75729,7 +73993,7 @@ module.exports = class gopax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],92:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],90:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -75737,6 +74001,7 @@ module.exports = class gopax extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, OrderNotFound, ArgumentsRequired, BadSymbol, BadRequest, NullResponse, InvalidOrder, BadResponse, NotSupported, ExchangeNotAvailable, RequestTimeout, RateLimitExceeded, PermissionDenied, InsufficientFunds, InvalidAddress } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -76036,23 +74301,23 @@ module.exports = class hbtc extends Exchange { const filter = filters[j]; const filterType = this.safeString (filter, 'filterType'); if (filterType === 'LOT_SIZE') { - amountMin = this.safeFloat (filter, 'minQty'); - amountMax = this.safeFloat (filter, 'maxQty'); + amountMin = this.safeNumber (filter, 'minQty'); + amountMax = this.safeNumber (filter, 'maxQty'); } if (filterType === 'PRICE_FILTER') { - priceMin = this.safeFloat (filter, 'minPrice'); - priceMax = this.safeFloat (filter, 'maxPrice'); + priceMin = this.safeNumber (filter, 'minPrice'); + priceMax = this.safeNumber (filter, 'maxPrice'); } if (filterType === 'MIN_NOTIONAL') { - costMin = this.safeFloat (filter, 'minNotional'); + costMin = this.safeNumber (filter, 'minNotional'); } } if ((costMin === undefined) && (amountMin !== undefined) && (priceMin !== undefined)) { costMin = amountMin * priceMin; } const precision = { - 'price': this.safeFloat2 (market, 'quotePrecision', 'quoteAssetPrecision'), - 'amount': this.safeFloat (market, 'baseAssetPrecision'), + 'price': this.safeNumber2 (market, 'quotePrecision', 'quoteAssetPrecision'), + 'amount': this.safeNumber (market, 'baseAssetPrecision'), }; const limits = { 'amount': { @@ -76290,14 +74555,6 @@ module.exports = class hbtc extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidAsk (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -76449,8 +74706,8 @@ module.exports = class hbtc extends Exchange { const currencyId = this.safeString2 (balance, 'asset', 'tokenName'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -76460,12 +74717,12 @@ module.exports = class hbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = response[currencyId]; const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableMargin'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'availableMargin'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTrades (symbol, since = undefined, limit = 50, params = {}) { @@ -76506,11 +74763,11 @@ module.exports = class hbtc extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -77196,8 +75453,8 @@ module.exports = class hbtc extends Exchange { // const currencyId = this.safeString (item, 'tokenId'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'change'); - const after = this.safeFloat (item, 'total'); + const amount = this.safeNumber (item, 'change'); + const after = this.safeNumber (item, 'total'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -77337,8 +75594,8 @@ module.exports = class hbtc extends Exchange { } else { type = 'withdrawal'; } - const amount = this.safeFloat (transaction, 'quantity'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'quantity'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'feeTokenId'); @@ -77399,8 +75656,8 @@ module.exports = class hbtc extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'openPrice'); - const close = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; let average = undefined; @@ -77411,19 +75668,19 @@ module.exports = class hbtc extends Exchange { percentage = (change / open) * 100; } } - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat2 (ticker, 'bestBidPrice', 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat2 (ticker, 'bestAskPrice', 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber2 (ticker, 'bestBidPrice', 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber2 (ticker, 'bestAskPrice', 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': vwap, 'open': open, 'close': close, @@ -77473,17 +75730,14 @@ module.exports = class hbtc extends Exchange { // } // const id = this.safeString (trade, 'id'); - const timestamp = this.safeFloat (trade, 'time'); + const timestamp = this.safeNumber (trade, 'time'); const type = undefined; const orderId = this.safeString (trade, 'orderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let side = undefined; let takerOrMaker = undefined; if ('isBuyerMaker' in trade) { @@ -77497,7 +75751,7 @@ module.exports = class hbtc extends Exchange { side = isBuyer ? 'buy' : 'sell'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -77603,30 +75857,30 @@ module.exports = class hbtc extends Exchange { const symbol = this.safeSymbol (marketId, market); let type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'avgPrice'); + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'avgPrice'); let amount = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); + let cost = this.safeNumber (order, 'cummulativeQuoteQty'); let filled = undefined; let remaining = undefined; if (type === undefined) { type = this.safeStringLower (order, 'orderType'); if ((market !== undefined) && market['inverse']) { - cost = this.safeFloat (order, 'executedQty'); + cost = this.safeNumber (order, 'executedQty'); amount = undefined; } if (cost === 0.0) { filled = 0; } } else { - amount = this.safeFloat (order, 'origQty'); + amount = this.safeNumber (order, 'origQty'); if (type === 'market') { price = undefined; if (side === 'buy') { amount = undefined; } } - filled = this.safeFloat (order, 'executedQty'); + filled = this.safeNumber (order, 'executedQty'); if (filled !== undefined) { if (amount !== undefined) { remaining = amount - filled; @@ -77638,7 +75892,7 @@ module.exports = class hbtc extends Exchange { } const status = this.parseOrderStatus (this.safeString (order, 'status')); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const result = { 'info': order, 'id': id, @@ -77667,7 +75921,7 @@ module.exports = class hbtc extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'fee'); + const feeCost = this.safeNumber (fees[i], 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'feeToken'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -77740,7 +75994,7 @@ module.exports = class hbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],93:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],91:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -77748,6 +76002,7 @@ module.exports = class hbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, PermissionDenied, ExchangeError, ExchangeNotAvailable, OrderNotFound, InsufficientFunds, InvalidOrder, RequestTimeout, AuthenticationError } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -77787,6 +76042,7 @@ module.exports = class hitbtc extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': 'M1', @@ -77824,10 +76080,10 @@ module.exports = class hitbtc extends Exchange { 'api': { 'public': { 'get': [ - 'symbol', // Available Currency Symbols - 'symbol/{symbol}', // Get symbol info 'currency', // Available Currencies 'currency/{currency}', // Get currency info + 'symbol', // Available Currency Symbols + 'symbol/{symbol}', // Get symbol info 'ticker', // Ticker list for all symbols 'ticker/{symbol}', // Ticker for symbol 'trades', @@ -77845,11 +76101,20 @@ module.exports = class hitbtc extends Exchange { 'order/{clientOrderId}', // Get a single order by clientOrderId 'trading/fee/all', // Get trading fee rate 'trading/fee/{symbol}', // Get trading fee rate + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', 'history/order', // Get historical orders 'history/trades', // Get historical trades 'history/order/{orderId}/trades', // Get historical trades by specified order 'account/balance', // Get main acccount balance - 'account/crypto/address/{currency}', // Get deposit crypro address + 'account/crypto/address/{currency}', // Get current address + 'account/crypto/addresses/{currency}', // Get last 10 deposit addresses for currency + 'account/crypto/used-addresses/{currency}', // Get last 10 unique addresses used for withdraw by currency + 'account/crypto/estimate-withdraw', 'account/crypto/is-mine/{address}', 'account/transactions', // Get account transactions 'account/transactions/{id}', // Get account transaction by id @@ -77860,23 +76125,33 @@ module.exports = class hitbtc extends Exchange { ], 'post': [ 'order', // Create new order - 'account/crypto/address/{currency}', // Create new deposit crypro address - 'account/crypto/withdraw', // Withdraw crypro + 'margin/order', + 'account/crypto/address/{currency}', // Create new crypto deposit address + 'account/crypto/withdraw', // Withdraw crypto 'account/crypto/transfer-convert', - 'account/transfer', // Transfer amount to trading + 'account/transfer', // Transfer amount to trading account or to main account + 'account/transfer/internal', 'sub-acc/freeze', 'sub-acc/activate', 'sub-acc/transfer', ], 'put': [ 'order/{clientOrderId}', // Create new order - 'account/crypto/withdraw/{id}', // Commit withdraw crypro + 'margin/account/{symbol}', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Commit crypto withdrawal 'sub-acc/acl/{subAccountUserId}', ], 'delete': [ 'order', // Cancel all open orders 'order/{clientOrderId}', // Cancel order - 'account/crypto/withdraw/{id}', // Rollback withdraw crypro + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Rollback crypto withdrawal ], // outdated? 'patch': [ @@ -77895,8 +76170,20 @@ module.exports = class hitbtc extends Exchange { }, 'options': { 'defaultTimeInForce': 'FOK', + 'accountsByType': { + 'bank': 'bank', + 'exchange': 'exchange', + 'main': 'bank', // alias of the above + 'trading': 'exchange', + }, + 'fetchBalanceMethod': { + 'account': 'account', + 'main': 'account', + 'trading': 'trading', + }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BCC': 'BCC', // initial symbol for Bitcoin Cash, now inactive 'BET': 'DAO.Casino', 'BOX': 'BOX Token', @@ -77923,7 +76210,6 @@ module.exports = class hitbtc extends Exchange { '20002': OrderNotFound, // canceling non-existent order '20001': InsufficientFunds, // {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}} }, - 'orders': {}, // orders cache / emulation }); } @@ -77960,14 +76246,14 @@ module.exports = class hitbtc extends Exchange { if (id.indexOf ('_') >= 0) { symbol = id; } - const lot = this.safeFloat (market, 'quantityIncrement'); - const step = this.safeFloat (market, 'tickSize'); + const lot = this.safeNumber (market, 'quantityIncrement'); + const step = this.safeNumber (market, 'tickSize'); const precision = { 'price': step, 'amount': lot, }; - const taker = this.safeFloat (market, 'takeLiquidityRate'); - const maker = this.safeFloat (market, 'provideLiquidityRate'); + const taker = this.safeNumber (market, 'takeLiquidityRate'); + const maker = this.safeNumber (market, 'provideLiquidityRate'); const feeCurrencyId = this.safeString (market, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); result.push (this.extend (this.fees['trading'], { @@ -78002,6 +76288,49 @@ module.exports = class hitbtc extends Exchange { return result; } + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // account can be "exchange" or "bank", with aliases "main" or "trading" respectively + await this.loadMarkets (); + const currency = this.currency (code); + const requestAmount = this.currencyToPrecision (code, amount); + const request = { + 'currency': currency['id'], + 'amount': requestAmount, + }; + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + const keys = Object.keys (accountsByType); + if (fromId === undefined) { + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ') + ' instead of ' + fromId); + } + if (toId === undefined) { + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ') + ' instead of ' + toId); + } + if (fromId === toId) { + throw new ExchangeError (this.id + ' from and to cannot be the same account'); + } + type = fromId + 'To' + this.capitalize (toId); + } + request['type'] = type; + const response = await this.privatePostAccountTransfer (this.extend (request, params)); + // { id: '2db6ebab-fb26-4537-9ef8-1a689472d236' } + const id = this.safeString (response, 'id'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'amount': requestAmount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': undefined, + }; + } + async fetchCurrencies (params = {}) { const response = await this.publicGetCurrency (params); // @@ -78057,7 +76386,7 @@ module.exports = class hitbtc extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'payoutFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'payoutFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -78097,15 +76426,20 @@ module.exports = class hitbtc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } async fetchBalance (params = {}) { await this.loadMarkets (); const type = this.safeString (params, 'type', 'trading'); - const method = 'privateGet' + this.capitalize (type) + 'Balance'; + const fetchBalanceAccounts = this.safeValue (this.options, 'fetchBalanceMethod', {}); + const typeId = this.safeString (fetchBalanceAccounts, type); + if (typeId === undefined) { + throw new ExchangeError (this.id + ' fetchBalance account type must be either main or trading'); + } + const method = 'privateGet' + this.capitalize (typeId) + 'Balance'; const query = this.omit (params, 'type'); const response = await this[method] (query); const result = { 'info': response }; @@ -78114,11 +76448,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -78135,11 +76469,11 @@ module.exports = class hitbtc extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'max'), - this.safeFloat (ohlcv, 'min'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'max'), + this.safeNumber (ohlcv, 'min'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -78185,10 +76519,10 @@ module.exports = class hitbtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); let change = undefined; let percentage = undefined; let average = undefined; @@ -78204,11 +76538,11 @@ module.exports = class hitbtc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -78284,7 +76618,7 @@ module.exports = class hitbtc extends Exchange { market = this.safeMarket (marketId, market); const symbol = market['symbol']; let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = market ? market['feeCurrency'] : undefined; fee = { @@ -78296,9 +76630,11 @@ module.exports = class hitbtc extends Exchange { // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const orderId = this.safeString (trade, 'clientOrderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); const id = this.safeString (trade, 'id'); return { @@ -78397,11 +76733,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'hash'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -78589,66 +76925,25 @@ module.exports = class hitbtc extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'cumQuantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'cumQuantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); // we use clientOrderId as the order id with this exchange intentionally // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const id = this.safeString (order, 'clientOrderId'); const clientOrderId = id; - let price = this.safeFloat (order, 'price'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - if (price !== undefined) { - cost = filled * price; - } - } - } + const price = this.safeNumber (order, 'price'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); let trades = this.safeValue (order, 'tradesReport'); - let fee = undefined; - let average = this.safeValue (order, 'avgPrice'); + const fee = undefined; + const average = this.safeNumber (order, 'avgPrice'); if (trades !== undefined) { trades = this.parseTrades (trades, market); - let feeCost = undefined; - const numTrades = trades.length; - let tradesCost = 0; - for (let i = 0; i < numTrades; i++) { - if (feeCost === undefined) { - feeCost = 0; - } - tradesCost = this.sum (tradesCost, trades[i]['cost']); - const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); - if (tradeFeeCost !== undefined) { - feeCost = this.sum (feeCost, tradeFeeCost); - } - } - cost = tradesCost; - if ((filled !== undefined) && (filled > 0)) { - if (average === undefined) { - average = cost / filled; - } - if (type === 'market') { - if (price === undefined) { - price = average; - } - } - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, // https://github.com/ccxt/ccxt/issues/5674 'timestamp': created, @@ -78663,13 +76958,13 @@ module.exports = class hitbtc extends Exchange { 'stopPrice': undefined, 'average': average, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -78930,7 +77225,7 @@ module.exports = class hitbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],94:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],92:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -78938,6 +77233,7 @@ module.exports = class hitbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { BadRequest, AuthenticationError, NetworkError, ArgumentsRequired, OrderNotFound, InsufficientFunds } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -78948,7 +77244,7 @@ module.exports = class hollaex extends Exchange { 'name': 'HollaEx', 'countries': [ 'KR' ], 'rateLimit': 333, - 'version': 'v1', + 'version': 'v2', 'has': { 'CORS': false, 'fetchMarkets': true, @@ -78968,13 +77264,13 @@ module.exports = class hollaex extends Exchange { 'cancelOrder': true, 'cancelAllOrders': true, 'fetchOpenOrders': true, - 'fetchClosedOrders': false, + 'fetchClosedOrders': true, 'fetchOpenOrder': true, 'fetchOrder': false, 'fetchDeposits': true, 'fetchWithdrawals': true, 'fetchTransactions': false, - 'fetchOrders': false, + 'fetchOrders': true, 'fetchMyTrades': true, 'withdraw': true, 'fetchDepositAddress': true, @@ -78999,13 +77295,17 @@ module.exports = class hollaex extends Exchange { 'public': { 'get': [ 'health', - 'constant', + 'constants', + 'kit', + 'tiers', 'ticker', - 'ticker/all', + 'tickers', + 'orderbook', 'orderbooks', 'trades', 'chart', - // TradingView data + 'charts', + // TradingView 'udf/config', 'udf/history', 'udf/symbols', @@ -79015,20 +77315,20 @@ module.exports = class hollaex extends Exchange { 'get': [ 'user', 'user/balance', - 'user/trades', - 'user/orders', - 'user/orders/{order_id}', 'user/deposits', 'user/withdrawals', - 'user/withdraw/{currency}/fee', + 'user/withdrawal/fee', + 'user/trades', + 'orders', + 'orders/{order_id}', ], 'post': [ 'user/request-withdrawal', 'order', ], 'delete': [ - 'user/orders', - 'user/orders/{order_id}', + 'order/all', + 'order', ], }, }, @@ -79063,7 +77363,7 @@ module.exports = class hollaex extends Exchange { } async fetchMarkets (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); // // { // coins: { @@ -79130,17 +77430,17 @@ module.exports = class hollaex extends Exchange { 'quoteId': quoteId, 'active': active, 'precision': { - 'price': this.safeFloat (market, 'increment_price'), - 'amount': this.safeFloat (market, 'increment_size'), + 'price': this.safeNumber (market, 'increment_price'), + 'amount': this.safeNumber (market, 'increment_size'), }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, 'max': undefined }, }, @@ -79151,7 +77451,7 @@ module.exports = class hollaex extends Exchange { } async fetchCurrencies (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); const coins = this.safeValue (response, 'coins', {}); const keys = Object.keys (coins); const result = {}; @@ -79163,8 +77463,8 @@ module.exports = class hollaex extends Exchange { const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'fullname'); const active = this.safeValue (currency, 'active'); - const fee = this.safeFloat (currency, 'withdrawal_fee'); - const precision = this.safeFloat (currency, 'increment_unit'); + const fee = this.safeNumber (currency, 'withdrawal_fee'); + const precision = this.safeNumber (currency, 'increment_unit'); const withdrawalLimits = this.safeValue (currency, 'withdrawal_limits', []); result[code] = { 'id': id, @@ -79177,8 +77477,8 @@ module.exports = class hollaex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min'), - 'max': this.safeFloat (currency, 'max'), + 'min': this.safeNumber (currency, 'min'), + 'max': this.safeNumber (currency, 'max'), }, 'price': { 'min': undefined, @@ -79267,7 +77567,7 @@ module.exports = class hollaex extends Exchange { async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.publicGetTickerAll (this.extend (params)); + const response = await this.publicGetTickers (this.extend (params)); // // { // "bch-usdt": { @@ -79330,27 +77630,27 @@ module.exports = class hollaex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString2 (ticker, 'time', 'timestamp')); - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const result = { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, - 'last': this.safeFloat (ticker, 'last', close), + 'last': this.safeNumber (ticker, 'last', close), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, }; return result; @@ -79408,15 +77708,12 @@ module.exports = class hollaex extends Exchange { const datetime = this.safeString (trade, 'timestamp'); const timestamp = this.parse8601 (datetime); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const quote = market['quote']; @@ -79501,11 +77798,11 @@ module.exports = class hollaex extends Exchange { // return [ this.parse8601 (this.safeString (response, 'time')), - this.safeFloat (response, 'open'), - this.safeFloat (response, 'high'), - this.safeFloat (response, 'low'), - this.safeFloat (response, 'close'), - this.safeFloat (response, 'volume'), + this.safeNumber (response, 'open'), + this.safeNumber (response, 'high'), + this.safeNumber (response, 'low'), + this.safeNumber (response, 'close'), + this.safeNumber (response, 'volume'), ]; } @@ -79530,11 +77827,11 @@ module.exports = class hollaex extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (response, currencyId + '_available'); - account['total'] = this.safeFloat (response, currencyId + '_balance'); + account['free'] = this.safeString (response, currencyId + '_available'); + account['total'] = this.safeString (response, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrder (id, symbol = undefined, params = {}) { @@ -79542,67 +77839,146 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateGetUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateGetOrdersOrderId (this.extend (request, params)); // // { - // "created_at": "2018-03-23T04:14:08.663Z", - // "title": "string", - // "side": "sell", - // "type": "limit", - // "price": 0, - // "size": 0, - // "symbol": "xht-usdt", // "id": "string", - // "created_by": 1, - // "filled": 0 + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } // } // return this.parseOrder (response); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'open': true, + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'status': 'filled', + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = undefined; - const request = {}; + const request = { + // 'symbol': market['id'], + // 'side': 'buy', // 'sell' + // 'status': 'new', // 'filled', 'pfilled', 'canceled' + // 'open': true, + // 'limit': limit, // default 50, max 100 + // 'page': 1, + // 'order_by': 'created_at', // id, ... + // 'order': 'asc', // 'desc' + // 'start_date': this.iso8601 (since), + // 'end_date': this.iso8601 (this.milliseconds ()), + }; if (symbol !== undefined) { market = this.market (symbol); request['symbol'] = market['id']; } - const response = await this.privateGetUserOrders (this.extend (request, params)); + if (since !== undefined) { + request['start_date'] = this.iso8601 (since); + } + if (limit !== undefined) { + request['limit'] = limit; // default 50, max 100 + } + const response = await this.privateGetOrders (this.extend (request, params)); // - // [ - // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 - // } - // ] + // { + // "count": 1, + // "data": [ + // { + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } + // } + // ] + // } // - return this.parseOrders (response, market); + const data = this.safeValue (response, 'data', []); + return this.parseOrders (data, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'new': 'open', + 'pfilled': 'open', + 'filled': 'closed', + 'canceled': 'canceled', + }; + return this.safeString (statuses, status, status); } parseOrder (order, market = undefined) { // - // fetchOpenOrder, fetchOpenOrders + // createOrder, fetchOpenOrder, fetchOpenOrders // // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // }, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, // } // const marketId = this.safeString (order, 'symbol'); @@ -79611,21 +77987,11 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filled'); - let cost = undefined; - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = filled * price; - } - } - const status = (type === 'market') ? 'closed' : 'open'; - const result = { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filled'); + const status = this.parseOrderStatus (this.safeString (order, 'status')); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -79641,40 +78007,56 @@ module.exports = class hollaex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; - return result; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); - const order = { + const request = { 'symbol': market['id'], 'side': side, 'size': amount, 'type': type, + // 'stop': parseFloat (this.priceToPrecision (symbol, stopPrice)), + // 'meta': {}, // other options such as post_only }; if (type !== 'market') { - order['price'] = price; + request['price'] = price; } - const response = await this.privatePostOrder (this.extend (order, params)); + const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop'); + if (stopPrice !== undefined) { + request['stop'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + params = this.omit (params, [ 'stopPrice', 'stop' ]); + } + const response = await this.privatePostOrder (this.extend (request, params)); // // { + // "fee": 0, + // "meta": {}, // "symbol": "xht-usdt", // "side": "sell", - // "size": 1, + // "size": 0.1, // "type": "limit", - // "price": 0.1, + // "price": 1, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, + // "fee_coin": "usdt", // "id": "string", - // "created_by": 34, + // "created_by": 116, // "filled": 0, - // "status": "pending" + // "status": "new", + // "updated_at": "2021-02-17T03:03:19.231Z", + // "created_at": "2021-02-17T03:03:19.231Z", + // "stop": null // } // return this.parseOrder (response, market); @@ -79685,7 +78067,7 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateDeleteUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateDeleteOrder (this.extend (request, params)); // // { // "title": "string", @@ -79710,7 +78092,7 @@ module.exports = class hollaex extends Exchange { market = this.markets (symbol); request['symbol'] = market['id']; } - const response = await this.privateDeleteUserOrders (this.extend (request, params)); + const response = await this.privateDeleteOrderAll (this.extend (request, params)); // // [ // { @@ -79976,7 +78358,7 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_at')); const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const type = this.safeString (transaction, 'type'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); let addressTo = undefined; const addressFrom = undefined; @@ -80006,7 +78388,7 @@ module.exports = class hollaex extends Exchange { } const fee = { 'currency': code, - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), }; return { 'info': transaction, @@ -80105,7 +78487,7 @@ module.exports = class hollaex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],95:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],93:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -80146,7 +78528,7 @@ module.exports = class huobijp extends huobipro { } }; -},{"./base/errors":8,"./huobipro.js":96}],96:[function(require,module,exports){ +},{"./base/errors":9,"./huobipro.js":94}],94:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -80154,6 +78536,7 @@ module.exports = class huobijp extends huobipro { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, ArgumentsRequired, BadSymbol, BadRequest, RequestTimeout, NetworkError } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -80171,7 +78554,9 @@ module.exports = class huobipro extends Exchange { 'hostname': 'api.huobi.pro', // api.testnet.huobi.pro 'pro': true, 'has': { + 'cancelAllOrders': true, 'cancelOrder': true, + 'cancelOrders': true, 'CORS': false, 'createOrder': true, 'fetchBalance': true, @@ -80338,6 +78723,7 @@ module.exports = class huobipro extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.002, @@ -80401,6 +78787,7 @@ module.exports = class huobipro extends Exchange { // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/ 'PNT': 'Penta', 'SBTC': 'Super Bitcoin', + 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706 }, }); } @@ -80465,8 +78852,8 @@ module.exports = class huobipro extends Exchange { 'info': limits, 'limits': { 'amount': { - 'min': this.safeFloat (limits, 'limit-order-must-greater-than'), - 'max': this.safeFloat (limits, 'limit-order-must-less-than'), + 'min': this.safeNumber (limits, 'limit-order-must-greater-than'), + 'max': this.safeNumber (limits, 'limit-order-must-less-than'), }, }, }; @@ -80500,9 +78887,9 @@ module.exports = class huobipro extends Exchange { }; const maker = (base === 'OMG') ? 0 : 0.2 / 100; const taker = (base === 'OMG') ? 0 : 0.2 / 100; - const minAmount = this.safeFloat (market, 'min-order-amt', Math.pow (10, -precision['amount'])); - const maxAmount = this.safeFloat (market, 'max-order-amt'); - const minCost = this.safeFloat (market, 'min-order-value', 0); + const minAmount = this.safeNumber (market, 'min-order-amt', Math.pow (10, -precision['amount'])); + const maxAmount = this.safeNumber (market, 'max-order-amt'); + const minCost = this.safeNumber (market, 'min-order-value', 0); const state = this.safeString (market, 'state'); const active = (state === 'online'); result.push ({ @@ -80581,24 +78968,24 @@ module.exports = class huobipro extends Exchange { let askVolume = undefined; if ('bid' in ticker) { if (Array.isArray (ticker['bid'])) { - bid = this.safeFloat (ticker['bid'], 0); - bidVolume = this.safeFloat (ticker['bid'], 1); + bid = this.safeNumber (ticker['bid'], 0); + bidVolume = this.safeNumber (ticker['bid'], 1); } else { - bid = this.safeFloat (ticker, 'bid'); + bid = this.safeNumber (ticker, 'bid'); bidVolume = this.safeValue (ticker, 'bidSize'); } } if ('ask' in ticker) { if (Array.isArray (ticker['ask'])) { - ask = this.safeFloat (ticker['ask'], 0); - askVolume = this.safeFloat (ticker['ask'], 1); + ask = this.safeNumber (ticker['ask'], 0); + askVolume = this.safeNumber (ticker['ask'], 1); } else { - ask = this.safeFloat (ticker, 'ask'); + ask = this.safeNumber (ticker, 'ask'); askVolume = this.safeValue (ticker, 'askSize'); } } - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -80609,15 +78996,15 @@ module.exports = class huobipro extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -80706,7 +79093,7 @@ module.exports = class huobipro extends Exchange { // } // const ticker = this.parseTicker (response['tick'], market); - const timestamp = this.safeValue (response, 'ts'); + const timestamp = this.safeInteger (response, 'ts'); ticker['timestamp'] = timestamp; ticker['datetime'] = this.iso8601 (timestamp); return ticker; @@ -80775,21 +79162,18 @@ module.exports = class huobipro extends Exchange { type = typeParts[1]; } const takerOrMaker = this.safeString (trade, 'role'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'filled-amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'filled-amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - let feeCost = this.safeFloat (trade, 'filled-fees'); + let feeCost = this.safeNumber (trade, 'filled-fees'); let feeCurrency = undefined; if (market !== undefined) { feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-currency')); } - const filledPoints = this.safeFloat (trade, 'filled-points'); + const filledPoints = this.safeNumber (trade, 'filled-points'); if (filledPoints !== undefined) { if ((feeCost === undefined) || (feeCost === 0.0)) { feeCost = filledPoints; @@ -80903,11 +79287,11 @@ module.exports = class huobipro extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -81004,11 +79388,11 @@ module.exports = class huobipro extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'deposit-min-amount'), + 'min': this.safeNumber (currency, 'deposit-min-amount'), 'max': Math.pow (10, precision), }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw-min-amount'), + 'min': this.safeNumber (currency, 'withdraw-min-amount'), 'max': Math.pow (10, precision), }, }, @@ -81039,14 +79423,14 @@ module.exports = class huobipro extends Exchange { account = this.account (); } if (balance['type'] === 'trade') { - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); } if (balance['type'] === 'frozen') { - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrdersByStates (states, symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -81221,28 +79605,14 @@ module.exports = class huobipro extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (order, 'created-at'); - let amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount - if ((type === 'market') && (side === 'buy')) { - amount = (status === 'closed') ? filled : undefined; - } - let price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - const cost = this.safeFloat2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - // if cost is defined and filled is not zero - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - const feeCost = this.safeFloat2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees + const cost = this.safeNumber2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo + const feeCost = this.safeNumber2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -81254,7 +79624,7 @@ module.exports = class huobipro extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -81268,15 +79638,15 @@ module.exports = class huobipro extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -81350,26 +79720,82 @@ module.exports = class huobipro extends Exchange { }); } - currencyToPrecision (currency, fee) { - return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); + async cancelOrders (ids, symbol = undefined, params = {}) { + await this.loadMarkets (); + const clientOrderIds = this.safeValue2 (params, 'clientOrderIds', 'client-order-ids'); + params = this.omit (params, [ 'clientOrderIds', 'client-order-ids' ]); + const request = {}; + if (clientOrderIds === undefined) { + request['order-ids'] = ids; + } else { + request['client-order-ids'] = clientOrderIds; + } + const response = await this.privatePostOrderOrdersBatchcancel (this.extend (request, params)); + // + // { + // "status": "ok", + // "data": { + // "success": [ + // "5983466" + // ], + // "failed": [ + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "first" + // }, + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "second" + // }, + // { + // "err-msg": "The record is not found.", + // "order-id": "", + // "err-code": "base-not-found", + // "client-order-id": "third" + // } + // ] + // } + // } + // + return response; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (market[key], cost)), + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts + // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default + // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok + // 'side': 'buy', // or 'sell' + // 'size': 100, // the number of orders to cancel 1-100 }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.privatePostOrderOrdersBatchCancelOpenOrders (this.extend (request, params)); + // + // { + // code: 200, + // data: { + // "success-count": 2, + // "failed-count": 0, + // "next-id": 5454600 + // } + // } + // + return response; + } + + currencyToPrecision (currency, fee) { + return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); } parseDepositAddress (depositAddress, currency = undefined) { @@ -81511,7 +79937,7 @@ module.exports = class huobipro extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const tag = this.safeString (transaction, 'address-tag'); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -81524,7 +79950,7 @@ module.exports = class huobipro extends Exchange { 'address': this.safeString (transaction, 'address'), 'tag': tag, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -81654,504 +80080,7 @@ module.exports = class huobipro extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],97:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class ice3x extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'ice3x', - 'name': 'ICE3X', - 'countries': [ 'ZA' ], // South Africa - 'rateLimit': 1000, - 'version': 'v1', - 'has': { - 'cancelOrder': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchCurrencies': true, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTrades': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg', - 'api': 'https://ice3x.com/api', - 'www': 'https://ice3x.com', // 'https://ice3x.co.za', - 'doc': 'https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017', - 'fees': [ - 'https://help.ice3.com/support/solutions/articles/11000033293-trading-fees', - 'https://help.ice3.com/support/solutions/articles/11000033288-fees-explained', - 'https://help.ice3.com/support/solutions/articles/11000008131-what-are-your-fiat-deposit-and-withdrawal-fees-', - 'https://help.ice3.com/support/solutions/articles/11000033289-deposit-fees', - ], - 'referral': 'https://ice3x.com?ref=14341802', - }, - 'api': { - 'public': { - 'get': [ - 'currency/list', - 'currency/info', - 'pair/list', - 'pair/info', - 'stats/marketdepthfull', - 'stats/marketdepthbtcav', - 'stats/marketdepth', - 'orderbook/info', - 'trade/list', - 'trade/info', - ], - }, - 'private': { - 'post': [ - 'balance/list', - 'balance/info', - 'order/new', - 'order/cancel', - 'order/list', - 'order/info', - 'trade/list', - 'trade/info', - 'transaction/list', - 'transaction/info', - 'invoice/list', - 'invoice/info', - 'invoice/pdf', - ], - }, - }, - 'fees': { - 'trading': { - 'maker': 0.005, - 'taker': 0.005, - }, - }, - 'precision': { - 'amount': 8, - 'price': 8, - }, - }); - } - - async fetchCurrencies (params = {}) { - const response = await this.publicGetCurrencyList (params); - const currencies = response['response']['entities']; - const precision = this.precision['amount']; - const result = {}; - for (let i = 0; i < currencies.length; i++) { - const currency = currencies[i]; - const id = this.safeString (currency, 'currency_id'); - const currencyId = this.safeString (currency, 'iso'); - const code = this.safeCurrencyCode (currencyId); - result[code] = { - 'id': id, - 'code': code, - 'name': currency['name'], - 'active': true, - 'precision': precision, - 'limits': { - 'amount': { - 'min': undefined, - 'max': Math.pow (10, precision), - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': Math.pow (10, precision), - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - }, - 'info': currency, - 'fee': undefined, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - if (this.currencies_by_id === undefined) { - this.currencies = await this.fetchCurrencies (); - this.currencies_by_id = this.indexBy (this.currencies, 'id'); - } - const response = await this.publicGetPairList (params); - const markets = this.safeValue (response['response'], 'entities'); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = this.safeString (market, 'pair_id'); - const baseId = this.safeString (market, 'currency_id_from'); - const quoteId = this.safeString (market, 'currency_id_to'); - const baseCurrency = this.currencies_by_id[baseId]; - const quoteCurrency = this.currencies_by_id[quoteId]; - const base = baseCurrency['code']; - const quote = quoteCurrency['code']; - const symbol = base + '/' + quote; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': undefined, - 'info': market, - 'precision': this.precision, - 'limits': this.limits, - }); - } - return result; - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.milliseconds (); - const symbol = market['symbol']; - const last = this.safeFloat (ticker, 'last_price'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'max_bid'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'min_ask'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'vol'), - 'info': ticker, - }; - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetStatsMarketdepthfull (this.extend (request, params)); - const ticker = this.safeValue (response['response'], 'entity'); - return this.parseTicker (ticker, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetStatsMarketdepthfull (params); - const tickers = this.safeValue (response['response'], 'entities'); - const result = {}; - for (let i = 0; i < tickers.length; i++) { - const ticker = tickers[i]; - const marketId = this.safeString (ticker, 'pair_id'); - const market = this.safeValue (this.marketsById, marketId); - if (market !== undefined) { - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); - } - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'pair_id': this.marketId (symbol), - }; - if (limit !== undefined) { - const type = this.safeString (params, 'type'); - if ((type !== 'ask') && (type !== 'bid')) { - // eslint-disable-next-line quotes - throw new ArgumentsRequired (this.id + " fetchOrderBook() requires an exchange-specific extra 'type' param ('bid' or 'ask') when used with a limit"); - } else { - request['items_per_page'] = limit; - } - } - const response = await this.publicGetOrderbookInfo (this.extend (request, params)); - const orderbook = this.safeValue (response['response'], 'entities'); - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.safeTimestamp (trade, 'created'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } - const type = 'limit'; - const side = this.safeString (trade, 'type'); - const id = this.safeString (trade, 'trade_id'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'id': id, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': type, - 'side': side, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetTradeList (this.extend (request, params)); - const trades = this.safeValue (response['response'], 'entities'); - return this.parseTrades (trades, market, since, limit); - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostBalanceList (params); - const result = { 'info': response }; - const balances = this.safeValue (response['response'], 'entities', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - // currency ids are numeric strings - const currencyId = this.safeString (balance, 'currency_id'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseOrder (order, market = undefined) { - const pairId = this.safeInteger (order, 'pair_id'); - let symbol = undefined; - if (pairId && !market && (pairId in this.marketsById)) { - market = this.marketsById[pairId]; - symbol = market['symbol']; - } - const timestamp = this.safeTimestamp (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - let status = this.safeInteger (order, 'active'); - let remaining = this.safeFloat (order, 'remaining'); - let filled = undefined; - if (status === 1) { - status = 'open'; - } else { - status = 'closed'; - remaining = 0; - filled = amount; - } - let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - }; - if (market !== undefined) { - fee['currency'] = market['quote']; - } - } - return { - 'id': this.safeString (order, 'order_id'), - 'clientOrderId': undefined, - 'datetime': this.iso8601 (timestamp), - 'timestamp': timestamp, - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': 'limit', - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': this.safeString (order, 'type'), - 'price': price, - 'stopPrice': undefined, - 'cost': undefined, - 'amount': amount, - 'filled': filled, - 'remaining': remaining, - 'trades': undefined, - 'fee': fee, - 'info': order, - 'average': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - 'type': side, - 'amount': amount, - 'price': price, - }; - const response = await this.privatePostOrderNew (this.extend (request, params)); - const order = this.parseOrder ({ - 'order_id': response['response']['entity']['order_id'], - 'created': this.seconds (), - 'active': 1, - 'type': side, - 'price': price, - 'volume': amount, - 'remaining': amount, - 'info': response, - }, market); - return order; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - const request = { - 'order_id': id, - }; - return await this.privatePostOrderCancel (this.extend (request, params)); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'order _id': id, - }; - const response = await this.privatePostOrderInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const order = this.safeValue (data, 'entity'); - return this.parseOrder (order); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.privatePostOrderList (params); - const data = this.safeValue (response, 'response', {}); - const orders = this.safeValue (data, 'entities', []); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - return this.parseOrders (orders, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - if (limit !== undefined) { - request['items_per_page'] = limit; - } - if (since !== undefined) { - request['date_from'] = parseInt (since / 1000); - } - const response = await this.privatePostTradeList (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const trades = this.safeValue (data, 'entities', []); - return this.parseTrades (trades, market, since, limit); - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency_id': currency['id'], - }; - const response = await this.privatePostBalanceInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const balance = this.safeValue (data, 'entity', {}); - const address = this.safeString (balance, 'address'); - const status = address ? 'ok' : 'none'; - return { - 'currency': code, - 'address': address, - 'tag': undefined, - 'status': status, - 'info': response, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/' + this.version + '/' + path; - if (api === 'public') { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } - } else { - this.checkRequiredCredentials (); - body = this.urlencode (this.extend ({ - 'nonce': this.nonce (), - }, params)); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': this.hmac (this.encode (body), this.encode (this.secret), 'sha512'), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const response = await this.fetch2 (path, api, method, params, headers, body); - const errors = this.safeValue (response, 'errors'); - const data = this.safeValue (response, 'response'); - if (errors || !data) { - const authErrorKeys = [ 'Key', 'user_id', 'Sign' ]; - for (let i = 0; i < authErrorKeys.length; i++) { - const errorKey = authErrorKeys[i]; - const errorMessage = this.safeString (errors, errorKey); - if (!errorMessage) { - continue; - } - if (errorKey === 'user_id' && errorMessage.indexOf ('authorization') < 0) { - continue; - } - throw new AuthenticationError (errorMessage); - } - throw new ExchangeError (this.json (errors)); - } - return response; - } -}; - -},{"./base/Exchange":6,"./base/errors":8}],98:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],95:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -82159,6 +80088,7 @@ module.exports = class ice3x extends Exchange { const Exchange = require ('./base/Exchange'); const { PAD_WITH_ZERO } = require ('./base/functions/number'); const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported, InvalidAddress, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -82395,14 +80325,6 @@ module.exports = class idex extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // { // market: 'DIL-ETH', @@ -82422,16 +80344,16 @@ module.exports = class idex extends Exchange { // } const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'baseVolume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'baseVolume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'open'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const close = this.safeFloat (ticker, 'close'); - const ask = this.safeFloat (ticker, 'ask'); - const bid = this.safeFloat (ticker, 'bid'); - let percentage = this.safeFloat (ticker, 'percentChange'); + const open = this.safeNumber (ticker, 'open'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const close = this.safeNumber (ticker, 'close'); + const ask = this.safeNumber (ticker, 'ask'); + const bid = this.safeNumber (ticker, 'bid'); + let percentage = this.safeNumber (ticker, 'percentChange'); if (percentage !== undefined) { percentage = 1 + percentage / 100; } @@ -82507,11 +80429,11 @@ module.exports = class idex extends Exchange { // sequence: 3853 // } const timestamp = this.safeInteger (ohlcv, 'start'); - const open = this.safeFloat (ohlcv, 'open'); - const high = this.safeFloat (ohlcv, 'high'); - const low = this.safeFloat (ohlcv, 'low'); - const close = this.safeFloat (ohlcv, 'close'); - const volume = this.safeFloat (ohlcv, 'volume'); + const open = this.safeNumber (ohlcv, 'open'); + const high = this.safeNumber (ohlcv, 'high'); + const low = this.safeNumber (ohlcv, 'low'); + const close = this.safeNumber (ohlcv, 'close'); + const volume = this.safeNumber (ohlcv, 'volume'); return [ timestamp, open, high, low, close, volume ]; } @@ -82573,9 +80495,14 @@ module.exports = class idex extends Exchange { // txStatus: 'mined' // } const id = this.safeString (trade, 'fillId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'quoteQuantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteQuantity'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const timestamp = this.safeInteger (trade, 'time'); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); @@ -82584,7 +80511,7 @@ module.exports = class idex extends Exchange { const oppositeSide = (makerSide === 'buy') ? 'sell' : 'buy'; const side = this.safeString (trade, 'side', oppositeSide); const takerOrMaker = this.safeString (trade, 'liquidity', 'taker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); @@ -82657,8 +80584,8 @@ module.exports = class idex extends Exchange { const result = []; for (let i = 0; i < bookSide.length; i++) { const order = bookSide[i]; - const price = this.safeFloat (order, 0); - const amount = this.safeFloat (order, 1); + const price = this.safeNumber (order, 0); + const amount = this.safeNumber (order, 1); const orderCount = this.safeInteger (order, 2); result.push ([ price, amount, orderCount ]); } @@ -82745,16 +80672,13 @@ module.exports = class idex extends Exchange { const entry = response[i]; const currencyId = this.safeString (entry, 'asset'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (entry, 'quantity'); - const free = this.safeFloat (entry, 'availableForTrade'); - const used = this.safeFloat (entry, 'locked'); - result[code] = { - 'free': free, - 'used': used, - 'total': total, - }; + const account = this.account (); + account['total'] = this.safeString (entry, 'quantity'); + account['free'] = this.safeString (entry, 'availableForTrade'); + account['used'] = this.safeString (entry, 'locked'); + result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -82975,10 +80899,10 @@ module.exports = class idex extends Exchange { const symbol = this.safeSymbol (marketId, market, '-'); const trades = this.parseTrades (fills, market); const type = this.safeString (order, 'type'); - const amount = this.safeFloat (order, 'originalQuantity'); - const filled = this.safeFloat (order, 'executedQuantity'); - const average = this.safeFloat (order, 'avgExecutionPrice'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'originalQuantity'); + const filled = this.safeNumber (order, 'executedQuantity'); + const average = this.safeNumber (order, 'avgExecutionPrice'); + const price = this.safeNumber (order, 'price'); const rawStatus = this.safeString (order, 'status'); const status = this.parseOrderStatus (rawStatus); const fee = { @@ -83087,7 +81011,7 @@ module.exports = class idex extends Exchange { throw new NotSupported (this.id + ' quoteOrderQuantity is not supported for ' + type + ' orders, only supported for market orders'); } amountEnum = 1; - amount = this.safeFloat (params, 'quoteOrderQuantity'); + amount = this.safeNumber (params, 'quoteOrderQuantity'); } const sideEnum = (side === 'buy') ? 0 : 1; const walletBytes = this.remove0xPrefix (this.walletAddress); @@ -83390,13 +81314,13 @@ module.exports = class idex extends Exchange { } const id = this.safeString2 (transaction, 'depositId', 'withdrawId'); const code = this.safeCurrencyCode (this.safeString (transaction, 'asset'), currency); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const txid = this.safeString (transaction, 'txId'); const timestamp = this.safeInteger (transaction, 'txTime'); let fee = undefined; if ('fee' in transaction) { fee = { - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), 'currency': 'ETH', }; } @@ -83454,12 +81378,13 @@ module.exports = class idex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],99:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],96:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -83583,11 +81508,11 @@ module.exports = class independentreserve extends Exchange { const currencyId = this.safeString (balance, 'CurrencyCode'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'AvailableBalance'); - account['total'] = this.safeFloat (balance, 'TotalBalance'); + account['free'] = this.safeString (balance, 'AvailableBalance'); + account['total'] = this.safeString (balance, 'TotalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -83608,16 +81533,16 @@ module.exports = class independentreserve extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'LastPrice'); + const last = this.safeNumber (ticker, 'LastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'DayHighestPrice'), - 'low': this.safeFloat (ticker, 'DayLowestPrice'), - 'bid': this.safeFloat (ticker, 'CurrentHighestBidPrice'), + 'high': this.safeNumber (ticker, 'DayHighestPrice'), + 'low': this.safeNumber (ticker, 'DayLowestPrice'), + 'bid': this.safeNumber (ticker, 'CurrentHighestBidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'CurrentLowestOfferPrice'), + 'ask': this.safeNumber (ticker, 'CurrentLowestOfferPrice'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -83626,8 +81551,8 @@ module.exports = class independentreserve extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'DayAvgPrice'), - 'baseVolume': this.safeFloat (ticker, 'DayVolumeXbtInSecondaryCurrrency'), + 'average': this.safeNumber (ticker, 'DayAvgPrice'), + 'baseVolume': this.safeNumber (ticker, 'DayVolumeXbtInSecondaryCurrrency'), 'quoteVolume': undefined, 'info': ticker, }; @@ -83706,20 +81631,10 @@ module.exports = class independentreserve extends Exchange { orderType = 'limit'; } const timestamp = this.parse8601 (this.safeString (order, 'CreatedTimestampUtc')); - const amount = this.safeFloat2 (order, 'VolumeOrdered', 'Volume'); - let filled = this.safeFloat (order, 'VolumeFilled'); - let remaining = this.safeFloat (order, 'Outstanding'); - if (filled === undefined) { - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (0, amount - remaining); - } - } - if (remaining === undefined) { - if ((filled !== undefined) && (amount !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const feeRate = this.safeFloat (order, 'FeePercent'); + const amount = this.safeNumber2 (order, 'VolumeOrdered', 'Volume'); + const filled = this.safeNumber (order, 'VolumeFilled'); + const remaining = this.safeNumber (order, 'Outstanding'); + const feeRate = this.safeNumber (order, 'FeePercent'); let feeCost = undefined; if (feeRate !== undefined) { feeCost = feeRate * filled; @@ -83731,10 +81646,10 @@ module.exports = class independentreserve extends Exchange { }; const id = this.safeString (order, 'OrderGuid'); const status = this.parseOrderStatus (this.safeString (order, 'Status')); - const cost = this.safeFloat (order, 'Value'); - const average = this.safeFloat (order, 'AvgPrice'); - const price = this.safeFloat (order, 'Price', average); - return { + const cost = this.safeNumber (order, 'Value'); + const average = this.safeNumber (order, 'AvgPrice'); + const price = this.safeNumber (order, 'Price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -83756,7 +81671,7 @@ module.exports = class independentreserve extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -83844,14 +81759,11 @@ module.exports = class independentreserve extends Exchange { const timestamp = this.parse8601 (trade['TradeTimestampUtc']); const id = this.safeString (trade, 'TradeGuid'); const orderId = this.safeString (trade, 'OrderGuid'); - const price = this.safeFloat2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); - const amount = this.safeFloat2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); + const amountString = this.safeString2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const baseId = this.safeString (trade, 'PrimaryCurrencyCode'); const quoteId = this.safeString (trade, 'SecondaryCurrencyCode'); let marketId = undefined; @@ -83964,13 +81876,14 @@ module.exports = class independentreserve extends Exchange { } }; -},{"./base/Exchange":6}],100:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],97:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, InvalidOrder, OrderNotFound, AuthenticationError, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -84131,7 +82044,7 @@ module.exports = class indodax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const taker = this.safeFloat (market, 'trade_fee_percent'); + const taker = this.safeNumber (market, 'trade_fee_percent'); const isMaintenance = this.safeInteger (market, 'is_maintenance'); const active = (isMaintenance) ? false : true; const pricePrecision = this.safeInteger (market, 'price_round'); @@ -84141,11 +82054,11 @@ module.exports = class indodax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'trade_min_traded_currency'), + 'min': this.safeNumber (market, 'trade_min_traded_currency'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'trade_min_base_currency'), + 'min': this.safeNumber (market, 'trade_min_base_currency'), 'max': undefined, }, 'cost': { @@ -84183,11 +82096,11 @@ module.exports = class indodax extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (used, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (used, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -84224,16 +82137,16 @@ module.exports = class indodax extends Exchange { const timestamp = this.safeTimestamp (ticker, 'server_time'); const baseVolume = 'vol_' + market['baseId'].toLowerCase (); const quoteVolume = 'vol_' + market['quoteId'].toLowerCase (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -84243,8 +82156,8 @@ module.exports = class indodax extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, baseVolume), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, baseVolume), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -84258,14 +82171,11 @@ module.exports = class indodax extends Exchange { } const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -84320,7 +82230,7 @@ module.exports = class indodax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status', 'open')); let symbol = undefined; let cost = undefined; - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let amount = undefined; let remaining = undefined; let filled = undefined; @@ -84334,18 +82244,18 @@ module.exports = class indodax extends Exchange { if ((market['baseId'] === 'idr') && ('remain_rp' in order)) { baseId = 'rp'; } - cost = this.safeFloat (order, 'order_' + quoteId); + cost = this.safeNumber (order, 'order_' + quoteId); if (cost) { amount = cost / price; - const remainingCost = this.safeFloat (order, 'remain_' + quoteId); + const remainingCost = this.safeNumber (order, 'remain_' + quoteId); if (remainingCost !== undefined) { remaining = remainingCost / price; filled = amount - remaining; } } else { - amount = this.safeFloat (order, 'order_' + baseId); + amount = this.safeNumber (order, 'order_' + baseId); cost = price * amount; - remaining = this.safeFloat (order, 'remain_' + baseId); + remaining = this.safeNumber (order, 'remain_' + baseId); filled = amount - remaining; } } @@ -84585,13 +82495,14 @@ module.exports = class indodax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],101:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],98:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -84702,25 +82613,25 @@ module.exports = class itbit extends Exchange { throw new ExchangeError (this.id + ' fetchTicker returned a bad response: ' + this.json (ticker)); } const timestamp = this.parse8601 (serverTimeUTC); - const vwap = this.safeFloat (ticker, 'vwap24h'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); + const vwap = this.safeNumber (ticker, 'vwap24h'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'openToday'), + 'open': this.safeNumber (ticker, 'openToday'), 'close': last, 'last': last, 'previousClose': undefined, @@ -84767,23 +82678,20 @@ module.exports = class itbit extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const side = this.safeString (trade, 'direction'); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'commissionPaid'); + let feeCost = this.safeNumber (trade, 'commissionPaid'); const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - let rebatesApplied = this.safeFloat (trade, 'rebatesApplied'); + let rebatesApplied = this.safeNumber (trade, 'rebatesApplied'); if (rebatesApplied !== undefined) { rebatesApplied = -rebatesApplied; } const rebateCurrencyId = this.safeString (trade, 'rebateCurrency'); const rebateCurrency = this.safeCurrencyCode (rebateCurrencyId); - const price = this.safeFloat2 (trade, 'price', 'rate'); - const amount = this.safeFloat2 (trade, 'currency1Amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'price', 'rate'); + const amountString = this.safeString2 (trade, 'currency1Amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; const marketId = this.safeString (trade, 'instrument'); if (marketId !== undefined) { @@ -84905,7 +82813,7 @@ module.exports = class itbit extends Exchange { 'txid': txnHash, 'type': transactionType, 'status': status, - 'amount': this.safeFloat (item, 'amount'), + 'amount': this.safeNumber (item, 'amount'), 'fee': undefined, 'info': item, }); @@ -85005,11 +82913,11 @@ module.exports = class itbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchWallets (params = {}) { @@ -85100,26 +83008,16 @@ module.exports = class itbit extends Exchange { const type = this.safeString (order, 'type'); const symbol = this.markets_by_id[order['instrument']]['symbol']; const timestamp = this.parse8601 (order['createdTime']); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'amountFilled'); - let remaining = undefined; - let cost = undefined; + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'amountFilled'); const fee = undefined; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'volumeWeightedAveragePrice'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'volumeWeightedAveragePrice'); const clientOrderId = this.safeString (order, 'clientOrderIdentifier'); const id = this.safeString (order, 'id'); const postOnlyString = this.safeString (order, 'postOnly'); const postOnly = (postOnlyString === 'True'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -85134,15 +83032,15 @@ module.exports = class itbit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, // 'trades': this.parseTrades (order['trades'], market), 'trades': undefined, - }; + }); } nonce () { @@ -85240,7 +83138,7 @@ module.exports = class itbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],102:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],99:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -85248,6 +83146,7 @@ module.exports = class itbit extends Exchange { const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeNotAvailable, ArgumentsRequired, PermissionDenied, AuthenticationError, ExchangeError, OrderNotFound, DDoSProtection, InvalidNonce, InsufficientFunds, CancelPending, InvalidOrder, InvalidAddress, RateLimitExceeded } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -85540,26 +83439,38 @@ module.exports = class kraken extends Exchange { // } // } // - const keys = Object.keys (response['result']); + const markets = this.safeValue (response, 'result', {}); + const keys = Object.keys (markets); let result = []; for (let i = 0; i < keys.length; i++) { const id = keys[i]; - const market = response['result'][id]; - const baseId = market['base']; - const quoteId = market['quote']; + const market = markets[id]; + const baseId = this.safeString (market, 'base'); + const quoteId = this.safeString (market, 'quote'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const darkpool = id.indexOf ('.d') >= 0; - const symbol = darkpool ? market['altname'] : (base + '/' + quote); + const altname = this.safeString (market, 'altname'); + const symbol = darkpool ? altname : (base + '/' + quote); + const makerFees = this.safeValue (market, 'fees_maker', []); + const firstMakerFee = this.safeValue (makerFees, 0, []); + const firstMakerFeeRate = this.safeNumber (firstMakerFee, 1); let maker = undefined; - if ('fees_maker' in market) { - maker = parseFloat (market['fees_maker'][0][1]) / 100; + if (firstMakerFeeRate !== undefined) { + maker = parseFloat (firstMakerFeeRate) / 100; + } + const takerFees = this.safeValue (market, 'fees', []); + const firstTakerFee = this.safeValue (takerFees, 0, []); + const firstTakerFeeRate = this.safeNumber (firstTakerFee, 1); + let taker = undefined; + if (firstTakerFeeRate !== undefined) { + taker = parseFloat (firstTakerFeeRate) / 100; } const precision = { - 'amount': market['lot_decimals'], - 'price': market['pair_decimals'], + 'amount': this.safeInteger (market, 'lot_decimals'), + 'price': this.safeInteger (market, 'pair_decimals'), }; - const minAmount = this.safeFloat (market, 'ordermin'); + const minAmount = this.safeNumber (market, 'ordermin'); result.push ({ 'id': id, 'symbol': symbol, @@ -85571,7 +83482,7 @@ module.exports = class kraken extends Exchange { 'info': market, 'altname': market['altname'], 'maker': maker, - 'taker': parseFloat (market['fees'][0][1]) / 100, + 'taker': taker, 'active': true, 'precision': precision, 'limits': { @@ -85694,7 +83605,7 @@ module.exports = class kraken extends Exchange { await this.loadMarkets (); this.checkRequiredCredentials (); const response = await this.privatePostTradeVolume (params); - const tradedVolume = this.safeFloat (response['result'], 'volume'); + const tradedVolume = this.safeNumber (response['result'], 'volume'); const tiers = this.fees['trading']['tiers']; let taker = tiers['taker'][1]; let maker = tiers['maker'][1]; @@ -85716,8 +83627,8 @@ module.exports = class kraken extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); const timestamp = this.safeInteger (bidask, 2); return [ price, amount, timestamp ]; } @@ -85755,7 +83666,14 @@ module.exports = class kraken extends Exchange { // } // const result = this.safeValue (response, 'result', {}); - const orderbook = this.safeValue (result, market['id']); + let orderbook = this.safeValue (result, market['id']); + // sometimes kraken returns wsname instead of market id + // https://github.com/ccxt/ccxt/issues/8662 + const marketInfo = this.safeValue (market, 'info', {}); + const wsName = this.safeValue (marketInfo, 'wsname'); + if (wsName !== undefined) { + orderbook = this.safeValue (result, wsName, orderbook); + } return this.parseOrderBook (orderbook); } @@ -85783,7 +83701,7 @@ module.exports = class kraken extends Exchange { 'ask': parseFloat (ticker['a'][0]), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'o'), + 'open': this.safeNumber (ticker, 'o'), 'close': last, 'last': last, 'previousClose': undefined, @@ -85854,11 +83772,11 @@ module.exports = class kraken extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 6), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 6), ]; } @@ -85925,24 +83843,24 @@ module.exports = class kraken extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'asset'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); } else { direction = 'in'; } - const time = this.safeFloat (item, 'time'); + const time = this.safeNumber (item, 'time'); let timestamp = undefined; if (time !== undefined) { timestamp = parseInt (time * 1000); } const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -86066,9 +83984,8 @@ module.exports = class kraken extends Exchange { let timestamp = undefined; let side = undefined; let type = undefined; - let price = undefined; - let amount = undefined; - let cost = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; let orderId = undefined; let fee = undefined; @@ -86077,8 +83994,8 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 2); side = (trade[3] === 's') ? 'sell' : 'buy'; type = (trade[4] === 'l') ? 'limit' : 'market'; - price = this.safeFloat (trade, 0); - amount = this.safeFloat (trade, 1); + priceString = this.safeString (trade, 0); + amountString = this.safeString (trade, 1); const tradeLength = trade.length; if (tradeLength > 6) { id = this.safeString (trade, 6); // artificially added as per #1794 @@ -86099,15 +84016,15 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 'time'); side = this.safeString (trade, 'type'); type = this.safeString (trade, 'ordertype'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'vol'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'vol'); if ('fee' in trade) { let currency = undefined; if (market !== undefined) { currency = market['quote']; } fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': currency, }; } @@ -86115,11 +84032,9 @@ module.exports = class kraken extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': orderId, @@ -86194,10 +84109,10 @@ module.exports = class kraken extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -86226,15 +84141,15 @@ module.exports = class kraken extends Exchange { if (type === 'limit') { request['price'] = this.priceToPrecision (symbol, price); } else if ((type === 'stop-loss') || (type === 'take-profit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice', price); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice', price); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a price/stopPrice parameter for a ' + type + ' order'); } else { request['price'] = this.priceToPrecision (symbol, stopPrice); } } else if ((type === 'stop-loss-limit') || (type === 'take-profit-limit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice'); - const limitPrice = this.safeFloat (params, 'price2'); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice'); + const limitPrice = this.safeNumber (params, 'price2'); const stopPriceDefined = (stopPrice !== undefined); const limitPriceDefined = (limitPrice !== undefined); if (stopPriceDefined && limitPriceDefined) { @@ -86343,10 +84258,10 @@ module.exports = class kraken extends Exchange { if (orderDescription !== undefined) { const parts = orderDescription.split (' '); side = this.safeString (parts, 0); - amount = this.safeFloat (parts, 1); + amount = this.safeNumber (parts, 1); marketId = this.safeString (parts, 2); type = this.safeString (parts, 4); - price = this.safeFloat (parts, 5); + price = this.safeNumber (parts, 5); } side = this.safeString (description, 'type', side); type = this.safeString (description, 'ordertype', type); @@ -86360,27 +84275,23 @@ module.exports = class kraken extends Exchange { market = this.getDelistedMarketById (marketId); } const timestamp = this.safeTimestamp (order, 'opentm'); - amount = this.safeFloat (order, 'vol', amount); - const filled = this.safeFloat (order, 'vol_exec'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = amount - filled; - } + amount = this.safeNumber (order, 'vol', amount); + const filled = this.safeNumber (order, 'vol_exec'); let fee = undefined; - const cost = this.safeFloat (order, 'cost'); - price = this.safeFloat (description, 'price', price); + const cost = this.safeNumber (order, 'cost'); + price = this.safeNumber (description, 'price', price); if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (description, 'price2'); + price = this.safeNumber (description, 'price2'); } if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (order, 'price', price); + price = this.safeNumber (order, 'price', price); } - const average = this.safeFloat (order, 'price'); + const average = this.safeNumber (order, 'price'); if (market !== undefined) { symbol = market['symbol']; if ('fee' in order) { const flags = order['oflags']; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); fee = { 'cost': feeCost, 'rate': undefined, @@ -86404,8 +84315,8 @@ module.exports = class kraken extends Exchange { if (rawTrades !== undefined) { trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id }); } - const stopPrice = this.safeFloat (order, 'stopprice'); - return { + const stopPrice = this.safeNumber (order, 'stopprice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -86424,10 +84335,10 @@ module.exports = class kraken extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -86777,10 +84688,10 @@ module.exports = class kraken extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const address = this.safeString (transaction, 'info'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.safeString (transaction, 'type'); // injected from the outside - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost === undefined) { if (type === 'deposit') { feeCost = 0; @@ -86957,7 +84868,7 @@ module.exports = class kraken extends Exchange { throw new ExchangeError (this.id + " withdraw() requires a 'key' parameter (withdrawal key name, as set up on your account)"); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { // 'txid': 'comma delimited list of transaction ids to restrict output to', @@ -87091,13 +85002,14 @@ module.exports = class kraken extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],103:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],100:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, InvalidNonce, NotSupported, BadRequest, AuthenticationError, BadSymbol, RateLimitExceeded, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -87139,6 +85051,7 @@ module.exports = class kucoin extends Exchange { 'fetchTrades': true, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg', @@ -87146,6 +85059,7 @@ module.exports = class kucoin extends Exchange { 'api': { 'public': 'https://openapi-v2.kucoin.com', 'private': 'https://openapi-v2.kucoin.com', + 'futuresPrivate': 'https://api-futures.kucoin.com', }, 'test': { 'public': 'https://openapi-sandbox.kucoin.com', @@ -87254,6 +85168,15 @@ module.exports = class kucoin extends Exchange { 'stop-order/cancel', ], }, + 'futuresPrivate': { + 'get': [ + 'account-overview', + 'positions', + ], + 'post': [ + 'transfer-out', + ], + }, }, 'timeframes': { '1m': '1min', @@ -87278,6 +85201,7 @@ module.exports = class kucoin extends Exchange { 'order_not_exist_or_not_allow_to_cancel': InvalidOrder, // {"code":"400100","msg":"order_not_exist_or_not_allow_to_cancel"} 'Order size below the minimum requirement.': InvalidOrder, // {"code":"400100","msg":"Order size below the minimum requirement."} 'The withdrawal amount is below the minimum requirement.': ExchangeError, // {"code":"400100","msg":"The withdrawal amount is below the minimum requirement."} + 'Unsuccessful! Exceeded the max. funds out-transfer limit': InsufficientFunds, // {"code":"200000","msg":"Unsuccessful! Exceeded the max. funds out-transfer limit"} '400': BadRequest, '401': AuthenticationError, '403': NotSupported, @@ -87334,9 +85258,7 @@ module.exports = class kucoin extends Exchange { 'version': 'v1', 'symbolSeparator': '-', 'fetchMyTradesMethod': 'private_get_fills', - 'fetchBalance': { - 'type': 'trade', // or 'main' - }, + 'fetchBalance': 'trade', // endpoint versions 'versions': { 'public': { @@ -87356,6 +85278,25 @@ module.exports = class kucoin extends Exchange { 'accounts/sub-transfer': 'v2', }, }, + 'futuresPrivate': { + 'GET': { + 'account-overview': 'v1', + 'positions': 'v1', + }, + 'POST': { + 'transfer-out': 'v2', + }, + }, + }, + 'accountsByType': { + 'trade': 'trade', + 'trading': 'trade', + 'margin': 'margin', + 'main': 'main', + 'futures': 'contract', + 'contract': 'contract', + 'pool': 'pool', + 'pool-x': 'pool', }, }, }); @@ -87436,11 +85377,11 @@ module.exports = class kucoin extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const active = this.safeValue (market, 'enableTrading'); - const baseMaxSize = this.safeFloat (market, 'baseMaxSize'); - const baseMinSize = this.safeFloat (market, 'baseMinSize'); - const quoteMaxSize = this.safeFloat (market, 'quoteMaxSize'); - const quoteMinSize = this.safeFloat (market, 'quoteMinSize'); - // const quoteIncrement = this.safeFloat (market, 'quoteIncrement'); + const baseMaxSize = this.safeNumber (market, 'baseMaxSize'); + const baseMinSize = this.safeNumber (market, 'baseMinSize'); + const quoteMaxSize = this.safeNumber (market, 'quoteMaxSize'); + const quoteMinSize = this.safeNumber (market, 'quoteMinSize'); + // const quoteIncrement = this.safeNumber (market, 'quoteIncrement'); const precision = { 'amount': this.precisionFromString (this.safeString (market, 'baseIncrement')), 'price': this.precisionFromString (this.safeString (market, 'priceIncrement')), @@ -87451,7 +85392,7 @@ module.exports = class kucoin extends Exchange { 'max': baseMaxSize, }, 'price': { - 'min': this.safeFloat (market, 'priceIncrement'), + 'min': this.safeNumber (market, 'priceIncrement'), 'max': quoteMaxSize / baseMinSize, }, 'cost': { @@ -87502,7 +85443,7 @@ module.exports = class kucoin extends Exchange { const precision = this.safeInteger (entry, 'precision'); const isWithdrawEnabled = this.safeValue (entry, 'isWithdrawEnabled', false); const isDepositEnabled = this.safeValue (entry, 'isDepositEnabled', false); - const fee = this.safeFloat (entry, 'withdrawalMinFee'); + const fee = this.safeNumber (entry, 'withdrawalMinFee'); const active = (isWithdrawEnabled && isDepositEnabled); result[code] = { 'id': id, @@ -87569,7 +85510,7 @@ module.exports = class kucoin extends Exchange { const response = await this.privateGetWithdrawalsQuotas (this.extend (request, params)); const data = response['data']; const withdrawFees = {}; - withdrawFees[code] = this.safeFloat (data, 'withdrawMinFee'); + withdrawFees[code] = this.safeNumber (data, 'withdrawMinFee'); return { 'info': response, 'withdraw': withdrawFees, @@ -87616,35 +85557,35 @@ module.exports = class kucoin extends Exchange { // "mark": 0 // } // - let percentage = this.safeFloat (ticker, 'changeRate'); + let percentage = this.safeNumber (ticker, 'changeRate'); if (percentage !== undefined) { percentage = percentage * 100; } - const last = this.safeFloat2 (ticker, 'last', 'lastTradedPrice'); + const last = this.safeNumber2 (ticker, 'last', 'lastTradedPrice'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'vol'); - const quoteVolume = this.safeFloat (ticker, 'volValue'); + const baseVolume = this.safeNumber (ticker, 'vol'); + const quoteVolume = this.safeNumber (ticker, 'volValue'); const vwap = this.vwap (baseVolume, quoteVolume); const timestamp = this.safeInteger2 (ticker, 'time', 'datetime'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'changePrice'), + 'change': this.safeNumber (ticker, 'changePrice'), 'percentage': percentage, - 'average': this.safeFloat (ticker, 'averagePrice'), + 'average': this.safeNumber (ticker, 'averagePrice'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -87728,11 +85669,11 @@ module.exports = class kucoin extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -87930,16 +85871,18 @@ module.exports = class kucoin extends Exchange { // 'marginMode': 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned // 'autoBorrow': false, // The system will first borrow you funds at the optimal interest rate and then place an order for you }; - if (type !== 'market') { - request['price'] = this.priceToPrecision (symbol, price); - request['size'] = this.amountToPrecision (symbol, amount); - } else { - if (this.safeValue (params, 'quoteAmount')) { - // used to create market order by quote amount - https://github.com/ccxt/ccxt/issues/4876 - request['funds'] = this.amountToPrecision (symbol, amount); + const quoteAmount = this.safeNumber2 (params, 'cost', 'funds'); + if (type === 'market') { + if (quoteAmount !== undefined) { + params = this.omit (params, [ 'cost', 'funds' ]); + // kucoin uses base precision even for quote values + request['funds'] = this.amountToPrecision (symbol, quoteAmount); } else { request['size'] = this.amountToPrecision (symbol, amount); } + } else { + request['price'] = this.priceToPrecision (symbol, price); + request['size'] = this.amountToPrecision (symbol, amount); } const response = await this.privatePostOrders (this.extend (request, params)); // @@ -87973,8 +85916,10 @@ module.exports = class kucoin extends Exchange { 'fee': undefined, 'trades': undefined, }; - if (!this.safeValue (params, 'quoteAmount')) { + if (quoteAmount === undefined) { order['amount'] = amount; + } else { + order['cost'] = quoteAmount; } return order; } @@ -88150,15 +86095,18 @@ module.exports = class kucoin extends Exchange { const type = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'createdAt'); const datetime = this.iso8601 (timestamp); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); + if (price === 0.0) { + // market orders + price = undefined; + } const side = this.safeString (order, 'side'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (order, 'fee'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'dealSize'); - const cost = this.safeFloat (order, 'dealFunds'); - const remaining = amount - filled; + const feeCost = this.safeNumber (order, 'fee'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'dealSize'); + const cost = this.safeNumber (order, 'dealFunds'); // bool const isActive = this.safeValue (order, 'isActive', false); const cancelExist = this.safeValue (order, 'cancelExist', false); @@ -88168,20 +86116,11 @@ module.exports = class kucoin extends Exchange { 'currency': feeCurrency, 'cost': feeCost, }; - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const clientOrderId = this.safeString (order, 'clientOid'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': orderId, 'clientOrderId': clientOrderId, 'symbol': symbol, @@ -88194,7 +86133,7 @@ module.exports = class kucoin extends Exchange { 'stopPrice': stopPrice, 'cost': cost, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'timestamp': timestamp, 'datetime': datetime, 'fee': fee, @@ -88203,7 +86142,7 @@ module.exports = class kucoin extends Exchange { 'lastTradeTimestamp': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -88404,7 +86343,6 @@ module.exports = class kucoin extends Exchange { const id = this.safeString2 (trade, 'tradeId', 'id'); const orderId = this.safeString (trade, 'orderId'); const takerOrMaker = this.safeString (trade, 'liquidity'); - const amount = this.safeFloat2 (trade, 'size', 'amount'); let timestamp = this.safeInteger (trade, 'time'); if (timestamp !== undefined) { timestamp = parseInt (timestamp / 1000000); @@ -88415,10 +86353,13 @@ module.exports = class kucoin extends Exchange { timestamp = timestamp * 1000; } } - const price = this.safeFloat2 (trade, 'price', 'dealPrice'); + const priceString = this.safeString2 (trade, 'price', 'dealPrice'); + const amountString = this.safeString2 (trade, 'size', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const side = this.safeString (trade, 'side'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); let feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -88430,20 +86371,16 @@ module.exports = class kucoin extends Exchange { fee = { 'cost': feeCost, 'currency': feeCurrency, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } let type = this.safeString (trade, 'type'); if (type === 'match') { type = undefined; } - let cost = this.safeFloat2 (trade, 'funds', 'dealValue'); + let cost = this.safeNumber2 (trade, 'funds', 'dealValue'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'info': trade, @@ -88539,7 +86476,7 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); let address = this.safeString (transaction, 'address'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let txid = this.safeString (transaction, 'walletTxId'); if (txid !== undefined) { const txidParts = txid.split ('@'); @@ -88557,7 +86494,7 @@ module.exports = class kucoin extends Exchange { const rawStatus = this.safeString (transaction, 'status'); const status = this.parseTransactionStatus (rawStatus); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { let rate = undefined; if (amount !== undefined) { @@ -88738,45 +86675,180 @@ module.exports = class kucoin extends Exchange { async fetchBalance (params = {}) { await this.loadMarkets (); - let type = undefined; - const request = {}; - if ('type' in params) { - type = params['type']; - if (type !== undefined) { - request['type'] = type; - } - params = this.omit (params, 'type'); + const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'trade'); + const requestedType = this.safeString (params, 'type', defaultType); + const accountsByType = this.safeValue (this.options, 'accountsByType'); + const type = this.safeString (accountsByType, requestedType); + if (type === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' type must be one of ' + keys.join (', ')); + } + params = this.omit (params, 'type'); + if (type === 'contract') { + // futures api requires a futures apiKey + // only fetches one balance at a time + // by default it will only fetch the BTC balance of the futures account + // you can send 'currency' in params to fetch other currencies + // fetchBalance ({ 'type': 'futures', 'currency': 'USDT' }) + const response = await this.futuresPrivateGetAccountOverview (params); + // + // { + // code: '200000', + // data: { + // accountEquity: 0.00005, + // unrealisedPNL: 0, + // marginBalance: 0.00005, + // positionMargin: 0, + // orderMargin: 0, + // frozenFunds: 0, + // availableBalance: 0.00005, + // currency: 'XBT' + // } + // } + // + const data = this.safeValue (response, 'data'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (data, 'availableBalance'); + account['total'] = this.safeString (data, 'accountEquity'); + const result = { 'info': response }; + result[code] = account; + return this.parseBalance (result, false); } else { - const options = this.safeValue (this.options, 'fetchBalance', {}); - type = this.safeString (options, 'type', 'trade'); - } - const response = await this.privateGetAccounts (this.extend (request, params)); - // - // { - // "code":"200000", - // "data":[ - // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, - // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, - // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - const result = { 'info': response }; - for (let i = 0; i < data.length; i++) { - const balance = data[i]; - const balanceType = this.safeString (balance, 'type'); - if (balanceType === type) { - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'holds'); - result[code] = account; + const request = { + 'type': type, + }; + const response = await this.privateGetAccounts (this.extend (request, params)); + // + // { + // "code":"200000", + // "data":[ + // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, + // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, + // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + const result = { 'info': response }; + for (let i = 0; i < data.length; i++) { + const balance = data[i]; + const balanceType = this.safeString (balance, 'type'); + if (balanceType === type) { + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'holds'); + result[code] = account; + } } + return this.parseBalance (result, false); + } + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const requestedAmount = this.currencyToPrecision (code, amount); + const accountsById = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsById, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsById, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + if (fromId === 'contract') { + if (toId !== 'main') { + throw new ExchangeError (this.id + ' only supports transferring from futures account to main account'); + } + const request = { + 'currency': currency['id'], + 'amount': requestedAmount, + }; + if (!('bizNo' in params)) { + // it doesn't like more than 24 characters + request['bizNo'] = this.uuid22 (); + } + const response = await this.futuresPrivatePostTransferOut (this.extend (request, params)); + // + // { + // code: '200000', + // data: { + // applyId: '605a87217dff1500063d485d', + // bizNo: 'bcd6e5e1291f4905af84dc', + // payAccountType: 'CONTRACT', + // payTag: 'DEFAULT', + // remark: '', + // recAccountType: 'MAIN', + // recTag: 'DEFAULT', + // recRemark: '', + // recSystem: 'KUCOIN', + // status: 'PROCESSING', + // currency: 'XBT', + // amount: '0.00001', + // fee: '0', + // sn: '573688685663948', + // reason: '', + // createdAt: 1616545569000, + // updatedAt: 1616545569000 + // } + // } + // + const data = this.safeValue (response, 'data'); + const timestamp = this.safeInteger (data, 'createdAt'); + const id = this.safeString (data, 'applyId'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const amount = this.safeNumber (data, 'amount'); + const rawStatus = this.safeString (data, 'status'); + let status = undefined; + if (rawStatus === 'PROCESSING') { + status = 'pending'; + } + return { + 'info': response, + 'currency': code, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'amount': amount, + 'fromAccount': fromId, + 'toAccount': toId, + 'id': id, + 'status': status, + }; + } else { + const request = { + 'currency': currency['id'], + 'from': fromId, + 'to': toId, + 'amount': requestedAmount, + }; + if (!('clientOid' in params)) { + request['clientOid'] = this.uuid (); + } + const response = await this.privatePostAccountsInnerTransfer (this.extend (request, params)); + // { code: '200000', data: { orderId: '605a6211e657f00006ad0ad6' } } + const data = this.safeValue (response, 'data'); + const id = this.safeString (data, 'orderId'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'currency': code, + 'amount': requestedAmount, + 'fromAccount': fromId, + 'toAccount': toId, + 'status': undefined, + }; } - return this.parseBalance (result); } async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -88864,11 +86936,11 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'code': code, }; - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'balance'); const direction = this.safeString (item, 'direction'); let before = undefined; if (after !== undefined && amount !== undefined) { @@ -88918,6 +86990,94 @@ module.exports = class kucoin extends Exchange { return this.safeString (types, type, type); } + async fetchPositions (symbols = undefined, params = {}) { + const response = await this.futuresPrivateGetPositions (params); + // + // { + // code: '200000', + // data: [ + // { + // id: '605a9772a229ab0006408258', + // symbol: 'XBTUSDTM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746099, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54371.92, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'USDT', + // isInverse: false + // }, + // { + // id: '605a9772026ac900066550df', + // symbol: 'XBTUSDM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746110, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54354.76, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'XBT', + // isInverse: true + // } + // ] + // } + // + return this.safeValue (response, 'data', response); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { // // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint @@ -88934,16 +87094,16 @@ module.exports = class kucoin extends Exchange { let endpart = ''; headers = (headers !== undefined) ? headers : {}; if (Object.keys (query).length) { - if (method !== 'GET') { + if ((method === 'GET') || (method === 'DELETE')) { + endpoint += '?' + this.urlencode (query); + } else { body = this.json (query); endpart = body; headers['Content-Type'] = 'application/json'; - } else { - endpoint += '?' + this.urlencode (query); } } const url = this.urls['api'][api] + endpoint; - if (api === 'private') { + if ((api === 'private') || (api === 'futuresPrivate')) { this.checkRequiredCredentials (); const timestamp = this.nonce ().toString (); headers = this.extend ({ @@ -88986,23 +87146,24 @@ module.exports = class kucoin extends Exchange { // { code: '200000', data: { ... }} // const errorCode = this.safeString (response, 'code'); - const message = this.safeString (response, 'msg'); - this.throwExactlyMatchedException (this.exceptions['exact'], message, message); - this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, message); + const message = this.safeString (response, 'msg', ''); + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, this.id + ' ' + message); } }; -},{"./base/Exchange":6,"./base/errors":8}],104:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],101:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- -const acx = require ('./acx.js'); -const { ArgumentsRequired } = require ('./base/errors'); +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, InsufficientFunds, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class kuna extends acx { +module.exports = class kuna extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'kuna', @@ -89012,14 +87173,24 @@ module.exports = class kuna extends acx { 'version': 'v2', 'has': { 'CORS': false, - 'fetchTickers': true, + 'cancelOrder': true, + 'createOrder': true, + 'fetchBalance': true, + 'fetchMarkets': true, + 'fetchMyTrades': true, 'fetchOHLCV': 'emulated', 'fetchOpenOrders': true, - 'fetchMyTrades': true, + 'fetchOrder': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchTime': true, + 'fetchTrades': true, 'withdraw': false, }, 'timeframes': undefined, 'urls': { + 'extension': '.json', 'referral': 'https://kuna.io?r=kunaid-gvfihe8az7o4', 'logo': 'https://user-images.githubusercontent.com/51840849/87153927-f0578b80-c2c0-11ea-84b6-74612568e9e1.jpg', 'api': 'https://kuna.io', @@ -89027,8 +87198,47 @@ module.exports = class kuna extends acx { 'doc': 'https://kuna.io/documents/api', 'fees': 'https://kuna.io/documents/api', }, + 'api': { + 'public': { + 'get': [ + 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. + 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator + 'k', // Get OHLC(k line) of specific market + 'markets', // Get all available markets + 'order_book', // Get the order book of specified market + 'order_book/{market}', + 'tickers', // Get ticker of all markets + 'tickers/{market}', // Get ticker of specific market + 'timestamp', // Get server current time, in seconds since Unix epoch + 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. + 'trades/{market}', + ], + }, + 'private': { + 'get': [ + 'members/me', // Get your profile and accounts info + 'deposits', // Get your deposits history + 'deposit', // Get details of specific deposit + 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. + 'orders', // Get your orders, results is paginated + 'order', // Get information of specified order + 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. + 'withdraws', // Get your cryptocurrency withdraws + 'withdraw', // Get your cryptocurrency withdraw + ], + 'post': [ + 'orders', // Create a Sell/Buy order + 'orders/multi', // Create multiple sell/buy orders + 'orders/clear', // Cancel all my orders + 'order/delete', // Cancel an order + 'withdraw', // Create a withdraw + ], + }, + }, 'fees': { 'trading': { + 'tierBased': false, + 'percentage': true, 'taker': 0.25 / 100, 'maker': 0.25 / 100, }, @@ -89051,9 +87261,24 @@ module.exports = class kuna extends acx { }, }, }, + 'commonCurrencies': { + 'PLA': 'Plair', + }, + 'exceptions': { + '2002': InsufficientFunds, + '2003': OrderNotFound, + }, }); } + async fetchTime (params = {}) { + const response = await this.publicGetTimestamp (params); + // + // 1594911427 + // + return response * 1000; + } + async fetchMarkets (params = {}) { const quotes = [ 'btc', 'eth', 'eurs', 'rub', 'uah', 'usd', 'usdt', 'gol' ]; const pricePrecisions = { @@ -89109,24 +87334,100 @@ module.exports = class kuna extends acx { return markets; } - async fetchL3OrderBook (symbol, limit = undefined, params = {}) { - return await this.fetchOrderBook (symbol, limit, params); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); - } + async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; - const response = await this.privateGetOrders (this.extend (request, params)); - // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder - // with order cache + fetchOpenOrders - // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX - return this.parseOrders (response, market, since, limit); + if (limit !== undefined) { + request['limit'] = limit; // default = 300 + } + const orderbook = await this.publicGetDepth (this.extend (request, params)); + const timestamp = this.safeTimestamp (orderbook, 'timestamp'); + return this.parseOrderBook (orderbook, timestamp); + } + + parseTicker (ticker, market = undefined) { + const timestamp = this.safeTimestamp (ticker, 'at'); + ticker = ticker['ticker']; + let symbol = undefined; + if (market) { + symbol = market['symbol']; + } + const last = this.safeNumber (ticker, 'last'); + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'bidVolume': undefined, + 'ask': this.safeNumber (ticker, 'sell'), + 'askVolume': undefined, + 'vwap': undefined, + 'open': this.safeNumber (ticker, 'open'), + 'close': last, + 'last': last, + 'previousClose': undefined, + 'change': undefined, + 'percentage': undefined, + 'average': undefined, + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const response = await this.publicGetTickers (params); + const ids = Object.keys (response); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + let market = undefined; + let symbol = id; + if (id in this.markets_by_id) { + market = this.markets_by_id[id]; + symbol = market['symbol']; + } else { + let base = id.slice (0, 3); + let quote = id.slice (3, 6); + base = base.toUpperCase (); + quote = quote.toUpperCase (); + base = this.safeCurrencyCode (base); + quote = this.safeCurrencyCode (quote); + symbol = base + '/' + quote; + } + result[symbol] = this.parseTicker (response[id], market); + } + return this.filterByArray (result, 'symbol', symbols); + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTickersMarket (this.extend (request, params)); + return this.parseTicker (response, market); + } + + async fetchL3OrderBook (symbol, limit = undefined, params = {}) { + return await this.fetchOrderBook (symbol, limit, params); + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTrades (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); } parseTrade (trade, market = undefined) { @@ -89143,9 +87444,14 @@ module.exports = class kuna extends acx { }; side = this.safeString (sideMap, side, side); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_id'); const id = this.safeString (trade, 'id'); return { @@ -89165,29 +87471,6 @@ module.exports = class kuna extends acx { }; } - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); - } - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.privateGetTradesMy (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const trades = await this.fetchTrades (symbol, since, limit, params); @@ -89206,15 +87489,210 @@ module.exports = class kuna extends acx { } return result; } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + const response = await this.privateGetMembersMe (params); + const balances = this.safeValue (response, 'accounts'); + const result = { 'info': balances }; + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'market': this.marketId (symbol), + 'side': side, + 'volume': amount.toString (), + 'ord_type': type, + }; + if (type === 'limit') { + request['price'] = price.toString (); + } + const response = await this.privatePostOrders (this.extend (request, params)); + const marketId = this.safeValue (response, 'market'); + const market = this.safeValue (this.markets_by_id, marketId); + return this.parseOrder (response, market); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': id, + }; + const response = await this.privatePostOrderDelete (this.extend (request, params)); + const order = this.parseOrder (response); + const status = order['status']; + if (status === 'closed' || status === 'canceled') { + throw new OrderNotFound (this.id + ' ' + this.json (order)); + } + return order; + } + + parseOrderStatus (status) { + const statuses = { + 'done': 'closed', + 'wait': 'open', + 'cancel': 'canceled', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + const marketId = this.safeString (order, 'market'); + const symbol = this.safeSymbol (marketId, market); + const timestamp = this.parse8601 (this.safeString (order, 'created_at')); + const status = this.parseOrderStatus (this.safeString (order, 'state')); + const type = this.safeString (order, 'type'); + const side = this.safeString (order, 'side'); + const id = this.safeString (order, 'id'); + return this.safeOrder ({ + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': undefined, + 'status': status, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': this.safeNumber (order, 'price'), + 'stopPrice': undefined, + 'amount': this.safeNumber (order, 'volume'), + 'filled': this.safeNumber (order, 'executed_volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'trades': undefined, + 'fee': undefined, + 'info': order, + 'cost': undefined, + 'average': undefined, + }); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': parseInt (id), + }; + const response = await this.privateGetOrder (this.extend (request, params)); + return this.parseOrder (response); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetOrders (this.extend (request, params)); + // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder + // with order cache + fetchOpenOrders + // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX + return this.parseOrders (response, market, since, limit); + } + + async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetTradesMy (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); + } + + nonce () { + return this.milliseconds (); + } + + encodeParams (params) { + if ('orders' in params) { + const orders = params['orders']; + let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); + for (let i = 0; i < orders.length; i++) { + const order = orders[i]; + const keys = Object.keys (order); + for (let k = 0; k < keys.length; k++) { + const key = keys[k]; + const value = order[key]; + query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); + } + } + return query; + } + return this.urlencode (this.keysort (params)); + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let request = '/api/' + this.version + '/' + this.implodeParams (path, params); + if ('extension' in this.urls) { + request += this.urls['extension']; + } + const query = this.omit (params, this.extractParams (path)); + let url = this.urls['api'] + request; + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const nonce = this.nonce ().toString (); + const query = this.encodeParams (this.extend ({ + 'access_key': this.apiKey, + 'tonce': nonce, + }, params)); + const auth = method + '|' + request + '|' + query; + const signed = this.hmac (this.encode (auth), this.encode (this.secret)); + const suffix = query + '&signature=' + signed; + if (method === 'GET') { + url += '?' + suffix; + } else { + body = suffix; + headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; + } + } + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; + } + if (code === 400) { + const error = this.safeValue (response, 'error'); + const errorCode = this.safeString (error, 'code'); + const feedback = this.id + ' ' + this.json (response); + this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); + // fallback to default error handler + } + } }; -},{"./acx.js":4,"./base/errors":8}],105:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],102:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, BadSymbol, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89323,10 +87801,10 @@ module.exports = class lakebtc extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -89344,16 +87822,16 @@ module.exports = class lakebtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -89363,7 +87841,7 @@ module.exports = class lakebtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -89394,14 +87872,11 @@ module.exports = class lakebtc extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -89538,14 +88013,14 @@ module.exports = class lakebtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],106:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],103:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, DDoSProtection, BadRequest, AuthenticationError } = require ('./base/errors'); -const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89626,6 +88101,7 @@ module.exports = class latoken extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.1 / 100, @@ -89710,7 +88186,7 @@ module.exports = class latoken extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minQty'), + 'min': this.safeNumber (market, 'minQty'), 'max': undefined, }, 'price': { @@ -89760,7 +88236,7 @@ module.exports = class latoken extends Exchange { const numericId = this.safeInteger (currency, 'currencyId'); const code = this.safeCurrencyCode (id); const precision = this.safeInteger (currency, 'precission'); - const fee = this.safeFloat (currency, 'fee'); + const fee = this.safeNumber (currency, 'fee'); const active = undefined; result[code] = { 'id': id, @@ -89794,27 +88270,6 @@ module.exports = class latoken extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privateGetAccountBalances (params); @@ -89838,17 +88293,15 @@ module.exports = class latoken extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const frozen = this.safeFloat (balance, 'frozen'); - const pending = this.safeFloat (balance, 'pending'); - const used = this.sum (frozen, pending); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': used, - 'total': this.safeFloat (balance, 'amount'), - }; + const frozen = this.safeString (balance, 'frozen'); + const pending = this.safeString (balance, 'pending'); + const account = this.account (); + account['used'] = Precise.stringAdd (frozen, pending); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -89893,20 +88346,20 @@ module.exports = class latoken extends Exchange { // const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; if (open !== undefined && close !== undefined) { change = close - open; } - const percentage = this.safeFloat (ticker, 'priceChange'); + const percentage = this.safeNumber (ticker, 'priceChange'); const timestamp = this.nonce (); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'low': this.safeFloat (ticker, 'low'), - 'high': this.safeFloat (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -89920,7 +88373,7 @@ module.exports = class latoken extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -90004,22 +88457,19 @@ module.exports = class latoken extends Exchange { timestamp *= 1000; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'orderId'); - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -90154,29 +88604,17 @@ module.exports = class latoken extends Exchange { const symbol = this.safeSymbol (marketId, market); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executedAmount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executedAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderStatus')); - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const timeFilled = this.safeTimestamp (order, 'timeFilled'); let lastTradeTimestamp = undefined; if ((timeFilled !== undefined) && (timeFilled > 0)) { lastTradeTimestamp = timeFilled; } const clientOrderId = this.safeString (order, 'cliOrdId'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -90191,14 +88629,14 @@ module.exports = class latoken extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'average': undefined, - 'remaining': remaining, + 'remaining': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -90428,13 +88866,14 @@ module.exports = class latoken extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],107:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],104:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, DDoSProtection, AuthenticationError, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -90632,8 +89071,8 @@ module.exports = class lbank extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const info = ticker; ticker = info['ticker']; - const last = this.safeFloat (ticker, 'latest'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'latest'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; if (percentage !== undefined) { const relativeChange = this.sum (1, percentage / 100); @@ -90654,8 +89093,8 @@ module.exports = class lbank extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -90668,8 +89107,8 @@ module.exports = class lbank extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'turnover'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'turnover'), 'info': info, }; } @@ -90719,17 +89158,15 @@ module.exports = class lbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (trade, 'date_ms'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'tid'); const type = undefined; - const side = this.safeString (trade, 'type'); + let side = this.safeString (trade, 'type'); + side = side.replace ('_market', ''); return { 'id': id, 'info': this.safeValue (trade, 'info', trade), @@ -90777,11 +89214,11 @@ module.exports = class lbank extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -90846,12 +89283,12 @@ module.exports = class lbank extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (freeze, currencyId); - account['total'] = this.safeFloat (asset, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (freeze, currencyId); + account['total'] = this.safeString (asset, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -90879,35 +89316,20 @@ module.exports = class lbank extends Exchange { // "status":2 // } // - let symbol = undefined; - const responseMarket = this.safeValue (this.marketsById, order['symbol']); - if (responseMarket !== undefined) { - symbol = responseMarket['symbol']; - } else if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeInteger (order, 'create_time'); // Limit Order Request Returns: Order Price // Market Order Returns: cny amount of market order - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount', 0.0); - const filled = this.safeFloat (order, 'deal_amount', 0.0); - const av_price = this.safeFloat (order, 'avg_price'); - let cost = undefined; - if (av_price !== undefined) { - cost = filled * av_price; - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount', 0.0); + const filled = this.safeNumber (order, 'deal_amount', 0.0); + const average = this.safeNumber (order, 'avg_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'order_id'); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -90921,15 +89343,15 @@ module.exports = class lbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': this.safeValue (order, 'info', order), - 'average': undefined, - }; + 'average': average, + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -91129,14 +89551,15 @@ module.exports = class lbank extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],108:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],105:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported } = require ('./base/errors'); +const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -91240,7 +89663,7 @@ module.exports = class liquid extends Exchange { 'trading': { 'tierBased': true, 'percentage': true, - 'taker': 0.0015, + 'taker': 0.0030, 'maker': 0.0000, 'tiers': { 'perpetual': { @@ -91259,48 +89682,52 @@ module.exports = class liquid extends Exchange { [ 300000000, -0.00025 ], ], 'taker': [ - [ 0, 0.000600 ], - [ 25000, 0.000575 ], - [ 50000, 0.000550 ], - [ 100000, 0.000525 ], - [ 1000000, 0.000500 ], - [ 10000000, 0.000475 ], - [ 25000000, 0.000450 ], - [ 50000000, 0.000425 ], - [ 75000000, 0.000400 ], - [ 100000000, 0.000375 ], - [ 200000000, 0.000350 ], - [ 300000000, 0.000325 ], + [ 0, 0.00120 ], + [ 25000, 0.00115 ], + [ 50000, 0.00110 ], + [ 100000, 0.00105 ], + [ 1000000, 0.00100 ], + [ 10000000, 0.00095 ], + [ 25000000, 0.00090 ], + [ 50000000, 0.00085 ], + [ 75000000, 0.00080 ], + [ 100000000, 0.00075 ], + [ 200000000, 0.00070 ], + [ 300000000, 0.00065 ], ], }, 'spot': { 'taker': [ - [ 0, 0.0015 ], - [ 10000, 0.0015 ], - [ 20000, 0.0014 ], - [ 50000, 0.0013 ], - [ 100000, 0.0010 ], - [ 1000000, 0.0008 ], - [ 5000000, 0.0006 ], - [ 10000000, 0.0005 ], - [ 25000000, 0.0005 ], - [ 50000000, 0.00045 ], - [ 100000000, 0.0004 ], - [ 200000000, 0.0003 ], + [ 0, 0.003 ], + [ 10000, 0.0029 ], + [ 20000, 0.0028 ], + [ 50000, 0.0026 ], + [ 100000, 0.0020 ], + [ 1000000, 0.0016 ], + [ 5000000, 0.0012 ], + [ 10000000, 0.0010 ], + [ 25000000, 0.0009 ], + [ 50000000, 0.0008 ], + [ 100000000, 0.0007 ], + [ 200000000, 0.0006 ], + [ 500000000, 0.0004 ], + [ 1000000000, 0.0003 ], ], 'maker': [ [ 0, 0.0000 ], - [ 10000, 0.0015 ], - [ 20000, 0.1400 ], - [ 50000, 0.1300 ], - [ 100000, 0.0800 ], - [ 1000000, 0.0004 ], - [ 5000000, 0.00035 ], - [ 10000000, 0.00025 ], + [ 10000, 0.0020 ], + [ 20000, 0.0019 ], + [ 50000, 0.0018 ], + [ 100000, 0.0016 ], + [ 1000000, 0.0008 ], + [ 5000000, 0.0007 ], + [ 10000000, 0.0005 ], [ 25000000, 0.0000 ], [ 50000000, 0.0000 ], [ 100000000, 0.0000 ], [ 200000000, 0.0000 ], + [ 500000000, 0.0000 ], + [ 1000000000, 0.0000 ], ], }, }, @@ -91319,6 +89746,7 @@ module.exports = class liquid extends Exchange { 'less_than_order_size': InvalidOrder, 'price_too_high': InvalidOrder, 'price_too_small': InvalidOrder, // {"errors":{"order":["price_too_small"]}} + 'product_disabled': BadSymbol, // {"errors":{"order":["product_disabled"]}} }, 'commonCurrencies': { 'WIN': 'WCOIN', @@ -91368,7 +89796,7 @@ module.exports = class liquid extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': decimalPrecision, 'limits': { 'amount': { @@ -91384,7 +89812,7 @@ module.exports = class liquid extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal'), + 'min': this.safeNumber (currency, 'minimum_withdrawal'), 'max': undefined, }, }, @@ -91509,19 +89937,19 @@ module.exports = class liquid extends Exchange { let maker = this.fees['trading']['maker']; let taker = this.fees['trading']['taker']; if (type === 'swap') { - maker = this.safeFloat (market, 'maker_fee', this.fees['trading']['maker']); - taker = this.safeFloat (market, 'taker_fee', this.fees['trading']['taker']); + maker = this.safeNumber (market, 'maker_fee', this.fees['trading']['maker']); + taker = this.safeNumber (market, 'taker_fee', this.fees['trading']['taker']); } const disabled = this.safeValue (market, 'disabled', false); const active = !disabled; const baseCurrency = this.safeValue (currenciesByCode, base); const precision = { 'amount': 0.00000001, - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; let minAmount = undefined; if (baseCurrency !== undefined) { - minAmount = this.safeFloat (baseCurrency['info'], 'minimum_order_quantity'); + minAmount = this.safeNumber (baseCurrency['info'], 'minimum_order_quantity'); } const limits = { 'amount': { @@ -91603,8 +90031,8 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } for (let i = 0; i < fiat.length; i++) { @@ -91612,11 +90040,11 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -91635,7 +90063,7 @@ module.exports = class liquid extends Exchange { if (ticker['last_traded_price']) { const length = ticker['last_traded_price'].length; if (length > 0) { - last = this.safeFloat (ticker, 'last_traded_price'); + last = this.safeNumber (ticker, 'last_traded_price'); } } } @@ -91660,7 +90088,7 @@ module.exports = class liquid extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'last_price_24h'); + const open = this.safeNumber (ticker, 'last_price_24h'); if (open !== undefined && last !== undefined) { change = last - open; average = this.sum (last, open) / 2; @@ -91672,11 +90100,11 @@ module.exports = class liquid extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_market_ask'), - 'low': this.safeFloat (ticker, 'low_market_bid'), - 'bid': this.safeFloat (ticker, 'market_bid'), + 'high': this.safeNumber (ticker, 'high_market_ask'), + 'low': this.safeNumber (ticker, 'low_market_bid'), + 'bid': this.safeNumber (ticker, 'market_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'market_ask'), + 'ask': this.safeNumber (ticker, 'market_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -91686,7 +90114,7 @@ module.exports = class liquid extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'volume_24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -91732,14 +90160,11 @@ module.exports = class liquid extends Exchange { if (mySide !== undefined) { takerOrMaker = (takerSide === mySide) ? 'taker' : 'maker'; } - let cost = undefined; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -91942,9 +90367,9 @@ module.exports = class liquid extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeValue (this.markets_by_id, marketId); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'filled_quantity'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + let filled = this.safeNumber (order, 'filled_quantity'); + const price = this.safeNumber (order, 'price'); let symbol = undefined; let feeCurrency = undefined; if (market !== undefined) { @@ -91954,7 +90379,7 @@ module.exports = class liquid extends Exchange { const type = this.safeString (order, 'order_type'); let tradeCost = 0; let tradeFilled = 0; - let average = this.safeFloat (order, 'average_price'); + let average = this.safeNumber (order, 'average_price'); const trades = this.parseTrades (this.safeValue (order, 'executions', []), market, undefined, undefined, { 'order': orderId, 'type': type, @@ -92011,7 +90436,7 @@ module.exports = class liquid extends Exchange { 'trades': trades, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'order_fee'), + 'cost': this.safeNumber (order, 'order_fee'), }, 'info': order, }; @@ -92166,7 +90591,7 @@ module.exports = class liquid extends Exchange { const updated = this.safeTimestamp (transaction, 'updated_at'); const type = 'withdrawal'; const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); return { 'info': transaction, 'id': id, @@ -92267,13 +90692,14 @@ module.exports = class liquid extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],109:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],106:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -92349,6 +90775,10 @@ module.exports = class luno extends Exchange { 'quotes/{id}', 'withdrawals', 'withdrawals/{id}', + 'transfers', + // GET /api/exchange/2/listorders + // GET /api/exchange/2/orders/{id} + // GET /api/exchange/3/order ], 'post': [ 'accounts', @@ -92423,12 +90853,12 @@ module.exports = class luno extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), - 'max': this.safeFloat (market, 'max_volume'), + 'min': this.safeNumber (market, 'min_volume'), + 'max': this.safeNumber (market, 'max_volume'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -92479,20 +90909,22 @@ module.exports = class luno extends Exchange { const wallet = wallets[i]; const currencyId = this.safeString (wallet, 'asset'); const code = this.safeCurrencyCode (currencyId); - const reserved = this.safeFloat (wallet, 'reserved'); - const unconfirmed = this.safeFloat (wallet, 'unconfirmed'); - const balance = this.safeFloat (wallet, 'balance'); + const reserved = this.safeString (wallet, 'reserved'); + const unconfirmed = this.safeString (wallet, 'unconfirmed'); + const balance = this.safeString (wallet, 'balance'); + const reservedUnconfirmed = Precise.stringAdd (reserved, unconfirmed); + const balanceUnconfirmed = Precise.stringAdd (balance, unconfirmed); if (code in result) { - result[code]['used'] = this.sum (result[code]['used'], reserved, unconfirmed); - result[code]['total'] = this.sum (result[code]['total'], balance, unconfirmed); + result[code]['used'] = Precise.stringAdd (result[code]['used'], reservedUnconfirmed); + result[code]['total'] = Precise.stringAdd (result[code]['total'], balanceUnconfirmed); } else { const account = this.account (); - account['used'] = this.sum (reserved, unconfirmed); - account['total'] = this.sum (balance, unconfirmed); + account['used'] = reservedUnconfirmed; + account['total'] = balanceUnconfirmed; result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -92543,18 +90975,12 @@ module.exports = class luno extends Exchange { const side = (order['type'] === 'ASK') ? 'sell' : 'buy'; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'limit_volume'); - const quoteFee = this.safeFloat (order, 'fee_counter'); - const baseFee = this.safeFloat (order, 'fee_base'); - const filled = this.safeFloat (order, 'base'); - const cost = this.safeFloat (order, 'counter'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'limit_volume'); + const quoteFee = this.safeNumber (order, 'fee_counter'); + const baseFee = this.safeNumber (order, 'fee_base'); + const filled = this.safeNumber (order, 'base'); + const cost = this.safeNumber (order, 'counter'); const fee = { 'currency': undefined }; if (quoteFee) { fee['cost'] = quoteFee; @@ -92568,7 +90994,7 @@ module.exports = class luno extends Exchange { } } const id = this.safeString (order, 'order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -92585,12 +91011,12 @@ module.exports = class luno extends Exchange { 'amount': amount, 'filled': filled, 'cost': cost, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -92636,16 +91062,16 @@ module.exports = class luno extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -92655,7 +91081,7 @@ module.exports = class luno extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'rolling_24_hour_volume'), + 'baseVolume': this.safeNumber (ticker, 'rolling_24_hour_volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -92706,8 +91132,8 @@ module.exports = class luno extends Exchange { } else { side = trade['is_buy'] ? 'buy' : 'sell'; } - const feeBase = this.safeFloat (trade, 'fee_base'); - const feeCounter = this.safeFloat (trade, 'fee_counter'); + const feeBase = this.safeNumber (trade, 'fee_base'); + const feeCounter = this.safeNumber (trade, 'fee_counter'); let feeCurrency = undefined; let feeCost = undefined; if (feeBase !== undefined) { @@ -92732,10 +91158,10 @@ module.exports = class luno extends Exchange { 'type': undefined, 'side': side, 'takerOrMaker': takerOrMaker, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), // Does not include potential fee costs - 'cost': this.safeFloat (trade, 'counter'), + 'cost': this.safeNumber (trade, 'counter'), 'fee': { 'cost': feeCost, 'currency': feeCurrency, @@ -92782,8 +91208,8 @@ module.exports = class luno extends Exchange { const response = await this.privateGetFeeInfo (params); return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } @@ -92917,9 +91343,9 @@ module.exports = class luno extends Exchange { const timestamp = this.safeValue (entry, 'timestamp'); const currencyId = this.safeString (entry, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - const available_delta = this.safeFloat (entry, 'available_delta'); - const balance_delta = this.safeFloat (entry, 'balance_delta'); - const after = this.safeFloat (entry, 'balance'); + const available_delta = this.safeNumber (entry, 'available_delta'); + const balance_delta = this.safeNumber (entry, 'balance_delta'); + const after = this.safeNumber (entry, 'balance'); const comment = this.safeString (entry, 'description'); let before = after; let amount = 0.0; @@ -92988,12 +91414,13 @@ module.exports = class luno extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],110:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],107:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -93175,18 +91602,16 @@ module.exports = class lykke extends Exchange { const id = this.safeString2 (trade, 'id', 'Id'); const orderId = this.safeString (trade, 'OrderId'); const timestamp = this.parse8601 (this.safeString2 (trade, 'dateTime', 'DateTime')); - const price = this.safeFloat2 (trade, 'price', 'Price'); - let amount = this.safeFloat2 (trade, 'volume', 'Amount'); + const priceString = this.safeString2 (trade, 'price', 'Price'); + let amountString = this.safeString2 (trade, 'volume', 'Amount'); let side = this.safeStringLower (trade, 'action'); if (side === undefined) { - if (amount < 0) { - side = 'sell'; - } else { - side = 'buy'; - } + side = (amountString[0] === '-') ? 'sell' : 'buy'; } - amount = Math.abs (amount); - const cost = price * amount; + amountString = (amountString[0] === '-') ? amountString.slice (1) : amountString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = { 'cost': 0, // There are no fees for trading. https://www.lykke.com/wallet-fees-and-limits/ 'currency': market['quote'], @@ -93247,11 +91672,11 @@ module.exports = class lykke extends Exchange { const currencyId = this.safeString (balance, 'AssetId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Balance'); - account['used'] = this.safeFloat (balance, 'Reserved'); + account['total'] = this.safeString (balance, 'Balance'); + account['used'] = this.safeString (balance, 'Reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -93298,7 +91723,7 @@ module.exports = class lykke extends Exchange { // } // const id = this.safeString (result, 'Id'); - price = this.safeFloat (result, 'Price'); + price = this.safeNumber (result, 'Price'); return { 'id': id, 'info': result, @@ -93389,16 +91814,16 @@ module.exports = class lykke extends Exchange { if (market) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'lastPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -93409,7 +91834,7 @@ module.exports = class lykke extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume24H'), + 'quoteVolume': this.safeNumber (ticker, 'volume24H'), 'info': ticker, }; } @@ -93467,20 +91892,18 @@ module.exports = class lykke extends Exchange { } else if (('CreatedAt' in order) && (order['CreatedAt'])) { timestamp = this.parse8601 (order['CreatedAt']); } - const price = this.safeFloat (order, 'Price'); + const price = this.safeNumber (order, 'Price'); let side = undefined; - let amount = this.safeFloat (order, 'Volume'); + let amount = this.safeNumber (order, 'Volume'); if (amount < 0) { side = 'sell'; amount = Math.abs (amount); } else { side = 'buy'; } - const remaining = Math.abs (this.safeFloat (order, 'RemainingVolume')); - const filled = amount - remaining; - const cost = filled * price; + const remaining = Math.abs (this.safeNumber (order, 'RemainingVolume')); const id = this.safeString (order, 'Id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -93494,15 +91917,15 @@ module.exports = class lykke extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -93563,8 +91986,8 @@ module.exports = class lykke extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - let amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + let amount = this.safeNumber (bidask, amountKey); if (amount < 0) { amount = -amount; } @@ -93604,13 +92027,14 @@ module.exports = class lykke extends Exchange { } }; -},{"./base/Exchange":6}],111:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7}],108:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -93767,7 +92191,7 @@ module.exports = class mercado extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, baseId), + 'min': this.safeNumber (amountLimits, baseId), 'max': undefined, }, 'price': { @@ -93803,16 +92227,16 @@ module.exports = class mercado extends Exchange { const response = await this.publicGetCoinTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'ticker', {}); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -93822,7 +92246,7 @@ module.exports = class mercado extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -93837,15 +92261,12 @@ module.exports = class mercado extends Exchange { const id = this.safeString2 (trade, 'tid', 'operation_id'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee_rate'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee_rate'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -93902,12 +92323,12 @@ module.exports = class mercado extends Exchange { if (currencyId in balances) { const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -94014,32 +92435,31 @@ module.exports = class mercado extends Exchange { // } // const id = this.safeString (order, 'order_id'); + const order_type = this.safeString (order, 'order_type'); let side = undefined; if ('order_type' in order) { - side = (order['order_type'] === 1) ? 'buy' : 'sell'; + side = (order_type === '1') ? 'buy' : 'sell'; } const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'coin_pair'); market = this.safeMarket (marketId, market); const timestamp = this.safeTimestamp (order, 'created_timestamp'); const fee = { - 'cost': this.safeFloat (order, 'fee'), + 'cost': this.safeNumber (order, 'fee'), 'currency': market['quote'], }; - const price = this.safeFloat (order, 'limit_price'); - // price = this.safeFloat (order, 'executed_price_avg', price); - const average = this.safeFloat (order, 'executed_price_avg'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'executed_quantity'); - const remaining = amount - filled; - const cost = filled * average; + const price = this.safeNumber (order, 'limit_price'); + // price = this.safeNumber (order, 'executed_price_avg', price); + const average = this.safeNumber (order, 'executed_price_avg'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const lastTradeTimestamp = this.safeTimestamp (order, 'updated_timestamp'); const rawTrades = this.safeValue (order, 'operations', []); const trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'side': side, 'order': id, }); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -94053,15 +92473,15 @@ module.exports = class mercado extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -94119,11 +92539,11 @@ module.exports = class mercado extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -94244,13 +92664,14 @@ module.exports = class mercado extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],112:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],109:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -94319,11 +92740,11 @@ module.exports = class mixcoins extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.safeFloat (balance, 'lock'); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = this.safeString (balance, 'lock'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -94343,16 +92764,16 @@ module.exports = class mixcoins extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'result'); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -94362,7 +92783,7 @@ module.exports = class mixcoins extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -94375,14 +92796,11 @@ module.exports = class mixcoins extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -94475,7 +92893,7 @@ module.exports = class mixcoins extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],113:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],110:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -94483,6 +92901,7 @@ module.exports = class mixcoins extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -94722,7 +93141,7 @@ module.exports = class ndax extends Exchange { const name = this.safeString (currency, 'ProductFullName'); const type = this.safeString (currency, 'ProductType'); const code = this.safeCurrencyCode (this.safeString (currency, 'Product')); - const precision = this.safeFloat (currency, 'TickSize'); + const precision = this.safeNumber (currency, 'TickSize'); const isDisabled = this.safeValue (currency, 'IsDisabled'); const active = !isDisabled; result[code] = { @@ -94803,8 +93222,8 @@ module.exports = class ndax extends Exchange { const quote = this.safeCurrencyCode (this.safeString (market, 'Product2Symbol')); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'QuantityIncrement'), - 'price': this.safeFloat (market, 'PriceIncrement'), + 'amount': this.safeNumber (market, 'QuantityIncrement'), + 'price': this.safeNumber (market, 'PriceIncrement'), }; const sessionStatus = this.safeString (market, 'SessionStatus'); const isDisable = this.safeValue (market, 'IsDisable'); @@ -94822,11 +93241,11 @@ module.exports = class ndax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinimumQuantity'), + 'min': this.safeNumber (market, 'MinimumQuantity'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'MinimumPrice'), + 'min': this.safeNumber (market, 'MinimumPrice'), 'max': undefined, }, 'cost': { @@ -94947,27 +93366,27 @@ module.exports = class ndax extends Exchange { const timestamp = this.safeInteger (ticker, 'TimeStamp'); const marketId = this.safeString (ticker, 'InstrumentId'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'LastTradedPx'); - const percentage = this.safeFloat (ticker, 'Rolling24HrPxChangePercent'); - const change = this.safeFloat (ticker, 'Rolling24HrPxChange'); - const open = this.safeFloat (ticker, 'SessionOpen'); + const last = this.safeNumber (ticker, 'LastTradedPx'); + const percentage = this.safeNumber (ticker, 'Rolling24HrPxChangePercent'); + const change = this.safeNumber (ticker, 'Rolling24HrPxChange'); + const open = this.safeNumber (ticker, 'SessionOpen'); let average = undefined; if ((last !== undefined) && (change !== undefined)) { average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'Rolling24HrVolume'); - const quoteVolume = this.safeFloat (ticker, 'Rolling24HrNotional'); + const baseVolume = this.safeNumber (ticker, 'Rolling24HrVolume'); + const quoteVolume = this.safeNumber (ticker, 'Rolling24HrNotional'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'SessionHigh'), - 'low': this.safeFloat (ticker, 'SessionLow'), - 'bid': this.safeFloat (ticker, 'BestBid'), - 'bidVolume': undefined, // this.safeFloat (ticker, 'BidQty'), always shows 0 - 'ask': this.safeFloat (ticker, 'BestOffer'), - 'askVolume': undefined, // this.safeFloat (ticker, 'AskQty'), always shows 0 + 'high': this.safeNumber (ticker, 'SessionHigh'), + 'low': this.safeNumber (ticker, 'SessionLow'), + 'bid': this.safeNumber (ticker, 'BestBid'), + 'bidVolume': undefined, // this.safeNumber (ticker, 'BidQty'), always shows 0 + 'ask': this.safeNumber (ticker, 'BestOffer'), + 'askVolume': undefined, // this.safeNumber (ticker, 'AskQty'), always shows 0 'vwap': vwap, 'open': open, 'close': last, @@ -95040,11 +93459,11 @@ module.exports = class ndax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -95192,8 +93611,8 @@ module.exports = class ndax extends Exchange { // "OMSId":1 // } // - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let cost = undefined; let timestamp = undefined; let id = undefined; @@ -95204,11 +93623,8 @@ module.exports = class ndax extends Exchange { let fee = undefined; let type = undefined; if (Array.isArray (trade)) { - price = this.safeFloat (trade, 3); - amount = this.safeFloat (trade, 2); - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + priceString = this.safeString (trade, 3); + amountString = this.safeString (trade, 2); timestamp = this.safeInteger (trade, 6); id = this.safeString (trade, 0); marketId = this.safeInteger (trade, 1); @@ -95220,13 +93636,13 @@ module.exports = class ndax extends Exchange { id = this.safeString (trade, 'TradeId'); orderId = this.safeString2 (trade, 'OrderId', 'OrigOrderId'); marketId = this.safeString2 (trade, 'InstrumentId', 'Instrument'); - price = this.safeFloat (trade, 'Price'); - amount = this.safeFloat (trade, 'Quantity'); - cost = this.safeFloat2 (trade, 'Value', 'GrossValueExecuted'); + priceString = this.safeString (trade, 'Price'); + amountString = this.safeString (trade, 'Quantity'); + cost = this.safeNumber2 (trade, 'Value', 'GrossValueExecuted'); takerOrMaker = this.safeStringLower (trade, 'MakerTaker'); side = this.safeStringLower (trade, 'Side'); type = this.safeStringLower (trade, 'OrderType'); - const feeCost = this.safeFloat (trade, 'Fee'); + const feeCost = this.safeNumber (trade, 'Fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'FeeProductId'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -95236,6 +93652,11 @@ module.exports = class ndax extends Exchange { }; } } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const symbol = this.safeSymbol (marketId, market); return { 'info': trade, @@ -95350,11 +93771,11 @@ module.exports = class ndax extends Exchange { const currencyId = this.safeString (balance, 'ProductId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Amount'); - account['used'] = this.safeFloat (balance, 'Hold'); + account['total'] = this.safeString (balance, 'Amount'); + account['used'] = this.safeString (balance, 'Hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseLedgerEntryType (type) { @@ -95400,8 +93821,8 @@ module.exports = class ndax extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'ReferenceType')); const currencyId = this.safeString (item, 'ProductId'); const code = this.safeCurrencyCode (currencyId, currency); - const credit = this.safeFloat (item, 'CR'); - const debit = this.safeFloat (item, 'DR'); + const credit = this.safeNumber (item, 'CR'); + const debit = this.safeNumber (item, 'DR'); let amount = undefined; let direction = undefined; if (credit > 0) { @@ -95413,7 +93834,7 @@ module.exports = class ndax extends Exchange { } const timestamp = this.safeInteger (item, 'TimeStamp'); let before = undefined; - const after = this.safeFloat (item, 'Balance'); + const after = this.safeNumber (item, 'Balance'); if (direction === 'out') { before = this.sum (after, amount); } else if (direction === 'in') { @@ -95561,36 +93982,26 @@ module.exports = class ndax extends Exchange { // const id = this.safeString2 (order, 'ReplacementOrderId', 'OrderId'); const timestamp = this.safeInteger (order, 'ReceiveTime'); - let lastTradeTimestamp = undefined; + const lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); const marketId = this.safeString (order, 'Instrument'); const symbol = this.safeSymbol (marketId, market); const side = this.safeStringLower (order, 'Side'); const type = this.safeStringLower (order, 'OrderType'); const clientOrderId = this.safeString2 (order, 'ReplacementClOrdId', 'ClientOrderId'); - let price = this.safeFloat (order, 'Price', 0.0); + let price = this.safeNumber (order, 'Price', 0.0); price = (price > 0.0) ? price : undefined; - const amount = this.safeFloat (order, 'OrigQuantity'); - const filled = this.safeFloat (order, 'QuantityExecuted'); - const cost = this.safeFloat (order, 'GrossValueExecuted'); - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (filled > 0) { - lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); - average = this.safeFloat (order, 'AvgPrice', 0.0); - average = (average > 0) ? average : undefined; - } - } - let stopPrice = this.safeFloat (order, 'StopPrice', 0.0); + const amount = this.safeNumber (order, 'OrigQuantity'); + const filled = this.safeNumber (order, 'QuantityExecuted'); + const cost = this.safeNumber (order, 'GrossValueExecuted'); + let average = this.safeNumber (order, 'AvgPrice', 0.0); + average = (average > 0) ? average : undefined; + let stopPrice = this.safeNumber (order, 'StopPrice', 0.0); stopPrice = (stopPrice > 0.0) ? stopPrice : undefined; const timeInForce = undefined; const status = this.parseOrderStatus (this.safeString (order, 'OrderState')); const fee = undefined; const trades = undefined; - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -95609,10 +94020,10 @@ module.exports = class ndax extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -96410,8 +94821,8 @@ module.exports = class ndax extends Exchange { } const addressTo = address; const status = this.parseTransactionStatusByType (this.safeString (transaction, 'TicketStatus'), type); - const amount = this.safeFloat (transaction, 'Amount'); - const feeCost = this.safeFloat (transaction, 'FeeAmount'); + const amount = this.safeNumber (transaction, 'Amount'); + const feeCost = this.safeNumber (transaction, 'FeeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -96492,7 +94903,7 @@ module.exports = class ndax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],114:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],111:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -96500,6 +94911,7 @@ module.exports = class ndax extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, BadRequest, CancelPending, OrderNotFound, InsufficientFunds, RateLimitExceeded, InvalidOrder, AccountSuspended, BadSymbol, OnMaintenance } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -96692,7 +95104,7 @@ module.exports = class novadax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -96700,7 +95112,7 @@ module.exports = class novadax extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderValue'), + 'min': this.safeNumber (market, 'minOrderValue'), 'max': undefined, }, }; @@ -96742,8 +95154,8 @@ module.exports = class novadax extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const open = this.safeFloat (ticker, 'open24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'open24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let percentage = undefined; let change = undefined; let average = undefined; @@ -96752,18 +95164,18 @@ module.exports = class novadax extends Exchange { percentage = change / open * 100; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'baseVolume24h'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume24h'); + const baseVolume = this.safeNumber (ticker, 'baseVolume24h'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -96919,11 +95331,13 @@ module.exports = class novadax extends Exchange { const orderId = this.safeString (trade, 'orderId'); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeStringLower (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - cost = amount * price; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'volume'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); @@ -96935,7 +95349,7 @@ module.exports = class novadax extends Exchange { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { - 'cost': this.safeFloat (parts, 0), + 'cost': this.safeNumber (parts, 0), 'currency': feeCurrencyCode, }; } @@ -97043,11 +95457,11 @@ module.exports = class novadax extends Exchange { const volumeField = this.safeString (options, 'volume', 'amount'); // or vol return [ this.safeTimestamp (ohlcv, 'score'), - this.safeFloat (ohlcv, 'openPrice'), - this.safeFloat (ohlcv, 'highPrice'), - this.safeFloat (ohlcv, 'lowPrice'), - this.safeFloat (ohlcv, 'closePrice'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'openPrice'), + this.safeNumber (ohlcv, 'highPrice'), + this.safeNumber (ohlcv, 'lowPrice'), + this.safeNumber (ohlcv, 'closePrice'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -97075,12 +95489,12 @@ module.exports = class novadax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'available'); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); + account['total'] = this.safeString (balance, 'available'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -97103,7 +95517,7 @@ module.exports = class novadax extends Exchange { if (uppercaseSide === 'SELL') { request['amount'] = this.amountToPrecision (symbol, amount); } else if (uppercaseSide === 'BUY') { - let value = this.safeFloat (params, 'value'); + let value = this.safeNumber (params, 'value'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -97333,21 +95747,17 @@ module.exports = class novadax extends Exchange { // } // const id = this.safeString (order, 'id'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'filledValue'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'filledValue'); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeInteger (order, 'timestamp'); - const average = this.safeFloat (order, 'averagePrice'); - const filled = this.safeFloat (order, 'filledAmount'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } + const average = this.safeNumber (order, 'averagePrice'); + const filled = this.safeNumber (order, 'filledAmount'); let fee = undefined; - const feeCost = this.safeFloat (order, 'filledFee'); + const feeCost = this.safeNumber (order, 'filledFee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -97356,7 +95766,7 @@ module.exports = class novadax extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -97374,11 +95784,11 @@ module.exports = class novadax extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async withdraw (code, amount, address, tag = undefined, params = {}) { @@ -97541,7 +95951,7 @@ module.exports = class novadax extends Exchange { } else if (type === 'COIN_OUT') { type = 'withdraw'; } - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'addressTag'); const txid = this.safeString (transaction, 'txHash'); @@ -97683,7 +96093,7 @@ module.exports = class novadax extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],115:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],112:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -97833,10 +96243,10 @@ module.exports = class oceanex extends Exchange { 'active': true, 'info': market, 'precision': { - 'amount': this.safeValue (market, 'amount_precision'), - 'price': this.safeValue (market, 'price_precision'), - 'base': this.safeValue (market, 'ask_precision'), - 'quote': this.safeValue (market, 'bid_precision'), + 'amount': this.safeInteger (market, 'amount_precision'), + 'price': this.safeInteger (market, 'price_precision'), + 'base': this.safeInteger (market, 'ask_precision'), + 'quote': this.safeInteger (market, 'bid_precision'), }, 'limits': { 'amount': { @@ -97848,7 +96258,7 @@ module.exports = class oceanex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeValue (market, 'minimum_trading_amount'), + 'min': this.safeNumber (market, 'minimum_trading_amount'), 'max': undefined, }, }, @@ -97942,21 +96352,21 @@ module.exports = class oceanex extends Exchange { 'symbol': market['symbol'], 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (ticker, 'last'), - 'last': this.safeFloat (ticker, 'last'), + 'close': this.safeNumber (ticker, 'last'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -98081,8 +96491,8 @@ module.exports = class oceanex extends Exchange { 'type': 'limit', 'takerOrMaker': undefined, 'side': side, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), 'cost': undefined, 'fee': undefined, }; @@ -98109,8 +96519,8 @@ module.exports = class oceanex extends Exchange { result[symbol] = { 'info': group, 'symbol': symbol, - 'maker': this.safeFloat (maker, 'value'), - 'taker': this.safeFloat (taker, 'value'), + 'maker': this.safeNumber (maker, 'value'), + 'taker': this.safeNumber (taker, 'value'), }; } return result; @@ -98132,11 +96542,11 @@ module.exports = class oceanex extends Exchange { const currencyId = this.safeValue (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -98244,12 +96654,12 @@ module.exports = class oceanex extends Exchange { // const status = this.parseOrderStatus (this.safeValue (order, 'state')); const marketId = this.safeString2 (order, 'market', 'market_id'); - const symbol = this.safeSymbol (marketId); + const symbol = this.safeSymbol (marketId, market); let timestamp = this.safeTimestamp (order, 'created_on'); if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'created_at')); } - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, @@ -98261,17 +96671,17 @@ module.exports = class oceanex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeValue (order, 'side'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_price'), - 'amount': this.safeFloat (order, 'volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'filled': this.safeFloat (order, 'executed_volume'), + 'average': this.safeNumber (order, 'avg_price'), + 'amount': this.safeNumber (order, 'volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'filled': this.safeNumber (order, 'executed_volume'), 'status': status, 'cost': undefined, 'trades': undefined, 'fee': undefined, - }; + }); } parseOrderStatus (status) { @@ -98364,12 +96774,12 @@ module.exports = class oceanex extends Exchange { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['codes'], errorCode, feedback); this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - throw new ExchangeError (response); + throw new ExchangeError (feedback); } } }; -},{"./base/Exchange":6,"./base/errors":8}],116:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],113:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -98406,7 +96816,7 @@ module.exports = class okcoin extends okex { } }; -},{"./okex.js":117}],117:[function(require,module,exports){ +},{"./okex.js":114}],114:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -98414,6 +96824,7 @@ module.exports = class okcoin extends okex { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -99207,7 +97618,7 @@ module.exports = class okex extends Exchange { let option = false; let baseId = this.safeString (market, 'base_currency'); let quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { if ('option_type' in market) { marketType = 'option'; @@ -99233,12 +97644,12 @@ module.exports = class okex extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = spot ? (base + '/' + quote) : id; - const lotSize = this.safeFloat2 (market, 'lot_size', 'trade_increment'); + const lotSize = this.safeNumber2 (market, 'lot_size', 'trade_increment'); const precision = { - 'amount': this.safeFloat (market, 'size_increment', lotSize), - 'price': this.safeFloat (market, 'tick_size'), + 'amount': this.safeNumber (market, 'size_increment', lotSize), + 'price': this.safeNumber (market, 'tick_size'), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const active = true; const fees = this.safeValue2 (this.fees, marketType, 'trading', {}); return this.extend (fees, { @@ -99413,7 +97824,7 @@ module.exports = class okex extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal'), + 'min': this.safeNumber (currency, 'min_withdrawal'), 'max': undefined, }, }, @@ -99488,18 +97899,18 @@ module.exports = class okex extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open_24h'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open_24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_24h'), - 'low': this.safeFloat (ticker, 'low_24h'), - 'bid': this.safeFloat (ticker, 'best_bid'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (ticker, 'best_ask'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber (ticker, 'high_24h'), + 'low': this.safeNumber (ticker, 'low_24h'), + 'bid': this.safeNumber (ticker, 'best_bid'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (ticker, 'best_ask'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': undefined, 'open': open, 'close': last, @@ -99508,8 +97919,8 @@ module.exports = class okex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'base_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'quote_volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'base_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'quote_volume_24h'), 'info': ticker, }; } @@ -99646,9 +98057,12 @@ module.exports = class okex extends Exchange { quote = market['quote']; } const timestamp = this.parse8601 (this.safeString2 (trade, 'timestamp', 'created_at')); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'size', 'qty'); - amount = this.safeFloat (trade, 'order_qty', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'size', 'qty'); + amountString = this.safeString (trade, 'order_qty', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -99656,13 +98070,7 @@ module.exports = class okex extends Exchange { takerOrMaker = 'taker'; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -99771,22 +98179,22 @@ module.exports = class okex extends Exchange { } return [ timestamp, // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets ]; } else { return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, 'volume'), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, 'volume'), // Base Volume ]; } } @@ -99932,9 +98340,9 @@ module.exports = class okex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeNumber (balance, 'balance'); + account['used'] = this.safeNumber (balance, 'hold'); + account['free'] = this.safeNumber (balance, 'available'); result[code] = account; } return this.parseBalance (result); @@ -100004,9 +98412,9 @@ module.exports = class okex extends Exchange { const currencyId = parts[1]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (marketBalance, 'balance'); - account['used'] = this.safeFloat (marketBalance, 'hold'); - account['free'] = this.safeFloat (marketBalance, 'available'); + account['total'] = this.safeNumber (marketBalance, 'balance'); + account['used'] = this.safeNumber (marketBalance, 'hold'); + account['free'] = this.safeNumber (marketBalance, 'available'); accounts[code] = account; } else { throw new NotSupported (this.id + ' margin balance response format has changed!'); @@ -100059,29 +98467,29 @@ module.exports = class okex extends Exchange { const code = this.safeCurrencyCode (id); const balance = this.safeValue (info, id, {}); const account = this.account (); - const totalAvailBalance = this.safeFloat (balance, 'total_avail_balance'); + const totalAvailBalance = this.safeNumber (balance, 'total_avail_balance'); if (this.safeString (balance, 'margin_mode') === 'fixed') { const contracts = this.safeValue (balance, 'contracts', []); let free = totalAvailBalance; for (let i = 0; i < contracts.length; i++) { const contract = contracts[i]; - const fixedBalance = this.safeFloat (contract, 'fixed_balance'); - const realizedPnl = this.safeFloat (contract, 'realized_pnl'); - const marginFrozen = this.safeFloat (contract, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (contract, 'margin_for_unfilled'); + const fixedBalance = this.safeNumber (contract, 'fixed_balance'); + const realizedPnl = this.safeNumber (contract, 'realized_pnl'); + const marginFrozen = this.safeNumber (contract, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (contract, 'margin_for_unfilled'); const margin = this.sum (fixedBalance, realizedPnl) - marginFrozen - marginForUnfilled; free = this.sum (free, margin); } account['free'] = free; } else { - const realizedPnl = this.safeFloat (balance, 'realized_pnl'); - const unrealizedPnl = this.safeFloat (balance, 'unrealized_pnl'); - const marginFrozen = this.safeFloat (balance, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (balance, 'margin_for_unfilled'); + const realizedPnl = this.safeNumber (balance, 'realized_pnl'); + const unrealizedPnl = this.safeNumber (balance, 'unrealized_pnl'); + const marginFrozen = this.safeNumber (balance, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (balance, 'margin_for_unfilled'); account['free'] = this.sum (totalAvailBalance, realizedPnl, unrealizedPnl) - marginFrozen - marginForUnfilled; } // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); + account['total'] = this.safeNumber (balance, 'equity'); result[code] = account; } return this.parseBalance (result); @@ -100119,8 +98527,8 @@ module.exports = class okex extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeNumber (balance, 'equity'); + account['free'] = this.safeNumber (balance, 'total_avail_balance'); result[symbol] = account; } return this.parseBalance (result); @@ -100324,7 +98732,7 @@ module.exports = class okex extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -100534,8 +98942,8 @@ module.exports = class okex extends Exchange { symbol = market['symbol']; } } - let amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat2 (order, 'filled_size', 'filled_qty'); + let amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber2 (order, 'filled_size', 'filled_qty'); let remaining = undefined; if (amount !== undefined) { if (filled !== undefined) { @@ -100546,9 +98954,9 @@ module.exports = class okex extends Exchange { if (type === 'market') { remaining = 0; } - let cost = this.safeFloat2 (order, 'filled_notional', 'funds'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); + let cost = this.safeNumber2 (order, 'filled_notional', 'funds'); + const price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'price_avg'); if (cost === undefined) { if (filled !== undefined && average !== undefined) { cost = average * filled; @@ -100559,7 +98967,7 @@ module.exports = class okex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'state')); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -100572,7 +98980,7 @@ module.exports = class okex extends Exchange { if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) { clientOrderId = undefined; // fix empty clientOrderId string } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); return { 'info': order, 'id': id, @@ -100816,16 +99224,6 @@ module.exports = class okex extends Exchange { return await this.fetchOrdersByState ('7', symbol, since, limit, params); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -100853,7 +99251,8 @@ module.exports = class okex extends Exchange { async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); - const currency = this.currency (code); + const parts = code.split ('-'); + const currency = this.currency (parts[0]); const request = { 'currency': currency['id'], }; @@ -100866,8 +99265,8 @@ module.exports = class okex extends Exchange { // } // ] // - const addresses = this.parseDepositAddresses (response); - const address = this.safeValue (addresses, code); + const addressesByCode = this.parseDepositAddresses (response); + const address = this.safeValue (addressesByCode, code); if (address === undefined) { throw new InvalidAddress (this.id + ' fetchDepositAddress cannot return nonexistent addresses, you should create withdrawal addresses with the exchange website first'); } @@ -101042,7 +99441,7 @@ module.exports = class okex extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const txid = this.safeString (transaction, 'txid'); const timestamp = this.parse8601 (this.safeString (transaction, 'timestamp')); @@ -101105,19 +99504,19 @@ module.exports = class okex extends Exchange { let feeCurrencyId = undefined; if (receivedCurrencyId === quoteId) { side = this.safeString (otherTrade, 'side'); - amount = this.safeFloat (otherTrade, 'size'); - cost = this.safeFloat (userTrade, 'size'); + amount = this.safeNumber (otherTrade, 'size'); + cost = this.safeNumber (userTrade, 'size'); feeCurrencyId = this.safeString (otherTrade, 'currency'); } else { side = this.safeString (userTrade, 'side'); - amount = this.safeFloat (userTrade, 'size'); - cost = this.safeFloat (otherTrade, 'size'); + amount = this.safeNumber (userTrade, 'size'); + cost = this.safeNumber (otherTrade, 'size'); feeCurrencyId = this.safeString (userTrade, 'currency'); } const id = this.safeString (userTrade, 'trade_id'); - const price = this.safeFloat (userTrade, 'price'); - const feeCostFirst = this.safeFloat (otherTrade, 'fee'); - const feeCostSecond = this.safeFloat (userTrade, 'fee'); + const price = this.safeNumber (userTrade, 'price'); + const feeCostFirst = this.safeNumber (otherTrade, 'fee'); + const feeCostSecond = this.safeNumber (userTrade, 'fee'); const feeCurrencyCodeFirst = this.safeCurrencyCode (this.safeString (otherTrade, 'currency')); const feeCurrencyCodeSecond = this.safeCurrencyCode (this.safeString (userTrade, 'currency')); let fee = undefined; @@ -101549,7 +99948,7 @@ module.exports = class okex extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); let method = undefined; const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType'); @@ -101931,14 +100330,14 @@ module.exports = class okex extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'timestamp')); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; const marketId = this.safeString (item, 'instrument_id'); let symbol = undefined; @@ -102048,13 +100447,14 @@ module.exports = class okex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],118:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],115:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -102147,12 +100547,12 @@ module.exports = class paymium extends Exchange { if (free in response) { const account = this.account (); const used = 'locked_' + currencyId; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -102171,30 +100571,30 @@ module.exports = class paymium extends Exchange { }; const ticker = await this.publicGetDataCurrencyTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'at'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'price'); + const last = this.safeNumber (ticker, 'price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'variation'), + 'percentage': this.safeNumber (ticker, 'variation'), 'average': undefined, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, @@ -102210,15 +100610,12 @@ module.exports = class paymium extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); + const priceString = this.safeString (trade, 'price'); const amountField = 'traded_' + market['base'].toLowerCase (); - const amount = this.safeFloat (trade, amountField); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const amountString = this.safeString (trade, amountField); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -102313,7 +100710,7 @@ module.exports = class paymium extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],119:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],116:[function(require,module,exports){ 'use strict'; // ---------------------------------------------------------------------------- @@ -102621,13 +101018,13 @@ module.exports = class phemex extends Exchange { }); } - parseSafeFloat (value = undefined) { + parseSafeNumber (value = undefined) { if (value === undefined) { return value; } value = value.replace (',', ''); const parts = value.split (' '); - return this.safeFloat (parts, 0); + return this.safeNumber (parts, 0); } parseSwapMarket (market) { @@ -102651,7 +101048,9 @@ module.exports = class phemex extends Exchange { // "minPriceEp":5000, // "maxPriceEp":10000000000, // "maxOrderQty":1000000, - // "type":"Perpetual" + // "type":"Perpetual", + // "status":"Listed", + // "tipOrderQty":1000000, // "steps":"50", // "riskLimits":[ // {"limit":100,"initialMargin":"1.0%","initialMarginEr":1000000,"maintenanceMargin":"0.5%","maintenanceMarginEr":500000}, @@ -102676,7 +101075,7 @@ module.exports = class phemex extends Exchange { // } // const id = this.safeString (market, 'symbol'); - const baseId = this.safeString (market, 'baseCurrency', 'contractUnderlyingAssets'); + const baseId = this.safeString2 (market, 'baseCurrency', 'contractUnderlyingAssets'); const quoteId = this.safeString (market, 'quoteCurrency'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); @@ -102693,16 +101092,16 @@ module.exports = class phemex extends Exchange { } const linear = !inverse; const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const priceScale = this.safeInteger (market, 'priceScale'); const ratioScale = this.safeInteger (market, 'ratioScale'); const valueScale = this.safeInteger (market, 'valueScale'); - const minPriceEp = this.safeFloat (market, 'minPriceEp'); - const maxPriceEp = this.safeFloat (market, 'maxPriceEp'); - const makerFeeRateEr = this.safeFloat (market, 'makerFeeRateEr'); - const takerFeeRateEr = this.safeFloat (market, 'takerFeeRateEr'); + const minPriceEp = this.safeNumber (market, 'minPriceEp'); + const maxPriceEp = this.safeNumber (market, 'maxPriceEp'); + const makerFeeRateEr = this.safeNumber (market, 'makerFeeRateEr'); + const takerFeeRateEr = this.safeNumber (market, 'takerFeeRateEr'); if (makerFeeRateEr !== undefined) { maker = this.fromEn (makerFeeRateEr, ratioScale, 0.00000001); } @@ -102720,10 +101119,11 @@ module.exports = class phemex extends Exchange { }, 'cost': { 'min': undefined, - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderQty')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderQty')), }, }; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -102772,7 +101172,9 @@ module.exports = class phemex extends Exchange { // "defaultMakerFee":"0.001", // "defaultMakerFeeEr":100000, // "baseQtyPrecision":6, - // "quoteQtyPrecision":2 + // "quoteQtyPrecision":2, + // "status":"Listed", + // "tipOrderQty":20 // } // const type = this.safeStringLower (market, 'type'); @@ -102783,30 +101185,31 @@ module.exports = class phemex extends Exchange { const inverse = undefined; const spot = true; const swap = false; - const taker = this.safeFloat (market, 'defaultTakerFee'); - const maker = this.safeFloat (market, 'defaultMakerFee'); + const taker = this.safeNumber (market, 'defaultTakerFee'); + const maker = this.safeNumber (market, 'defaultMakerFee'); const precision = { - 'amount': this.parseSafeFloat (this.safeString (market, 'baseTickSize')), - 'price': this.parseSafeFloat (this.safeString (market, 'quoteTickSize')), + 'amount': this.parseSafeNumber (this.safeString (market, 'baseTickSize')), + 'price': this.parseSafeNumber (this.safeString (market, 'quoteTickSize')), }; const limits = { 'amount': { 'min': precision['amount'], - 'max': this.parseSafeFloat (this.safeString (market, 'maxBaseOrderSize')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxBaseOrderSize')), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.parseSafeFloat (this.safeString (market, 'minOrderValue')), - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderValue')), + 'min': this.parseSafeNumber (this.safeString (market, 'minOrderValue')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderValue')), }, }; const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -102996,8 +101399,8 @@ module.exports = class phemex extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const valueScale = this.safeInteger (currency, 'valueScale'); - const minValueEv = this.safeFloat (currency, 'minValueEv'); - const maxValueEv = this.safeFloat (currency, 'maxValueEv'); + const minValueEv = this.safeNumber (currency, 'minValueEv'); + const maxValueEv = this.safeNumber (currency, 'maxValueEv'); let minAmount = undefined; let maxAmount = undefined; let precision = undefined; @@ -103047,12 +101450,12 @@ module.exports = class phemex extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - let amount = this.safeFloat (bidask, amountKey); + let amount = this.safeNumber (bidask, amountKey); if (market['spot']) { amount = this.fromEv (amount, market); } return [ - this.fromEp (this.safeFloat (bidask, priceKey), market), + this.fromEp (this.safeNumber (bidask, priceKey), market), amount, ]; } @@ -103186,16 +101589,16 @@ module.exports = class phemex extends Exchange { // let baseVolume = undefined; if ((market !== undefined) && market['spot']) { - baseVolume = this.fromEv (this.safeFloat (ohlcv, 7), market); + baseVolume = this.fromEv (this.safeNumber (ohlcv, 7), market); } else { baseVolume = this.safeInteger (ohlcv, 7); } return [ this.safeTimestamp (ohlcv, 0), - this.fromEp (this.safeFloat (ohlcv, 3), market), - this.fromEp (this.safeFloat (ohlcv, 4), market), - this.fromEp (this.safeFloat (ohlcv, 5), market), - this.fromEp (this.safeFloat (ohlcv, 6), market), + this.fromEp (this.safeNumber (ohlcv, 3), market), + this.fromEp (this.safeNumber (ohlcv, 4), market), + this.fromEp (this.safeNumber (ohlcv, 5), market), + this.fromEp (this.safeNumber (ohlcv, 6), market), baseVolume, ]; } @@ -103288,11 +101691,11 @@ module.exports = class phemex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.000001); - const last = this.fromEp (this.safeFloat (ticker, 'lastEp'), market); - const quoteVolume = this.fromEp (this.safeFloat (ticker, 'turnoverEv'), market); - let baseVolume = this.safeFloat (ticker, 'volume'); + const last = this.fromEp (this.safeNumber (ticker, 'lastEp'), market); + const quoteVolume = this.fromEp (this.safeNumber (ticker, 'turnoverEv'), market); + let baseVolume = this.safeNumber (ticker, 'volume'); if (baseVolume === undefined) { - baseVolume = this.fromEv (this.safeFloat (ticker, 'volumeEv')); + baseVolume = this.fromEv (this.safeNumber (ticker, 'volumeEv')); } let vwap = undefined; if ((market !== undefined) && (market['spot'])) { @@ -103301,7 +101704,7 @@ module.exports = class phemex extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.fromEp (this.safeFloat (ticker, 'openEp'), market); + const open = this.fromEp (this.safeNumber (ticker, 'openEp'), market); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -103313,11 +101716,11 @@ module.exports = class phemex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.fromEp (this.safeFloat (ticker, 'highEp'), market), - 'low': this.fromEp (this.safeFloat (ticker, 'lowEp'), market), - 'bid': this.fromEp (this.safeFloat (ticker, 'bidEp'), market), + 'high': this.fromEp (this.safeNumber (ticker, 'highEp'), market), + 'low': this.fromEp (this.safeNumber (ticker, 'lowEp'), market), + 'bid': this.fromEp (this.safeNumber (ticker, 'bidEp'), market), 'bidVolume': undefined, - 'ask': this.fromEp (this.safeFloat (ticker, 'askEp'), market), + 'ask': this.fromEp (this.safeNumber (ticker, 'askEp'), market), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -103508,8 +101911,8 @@ module.exports = class phemex extends Exchange { id = this.safeString (trade, tradeLength - 4); } side = this.safeStringLower (trade, tradeLength - 3); - price = this.fromEp (this.safeFloat (trade, tradeLength - 2), market); - amount = this.fromEv (this.safeFloat (trade, tradeLength - 1), market); + price = this.fromEp (this.safeNumber (trade, tradeLength - 2), market); + amount = this.fromEv (this.safeNumber (trade, tradeLength - 1), market); if (market['spot']) { if ((price !== undefined) && (amount !== undefined)) { cost = price * amount; @@ -103525,14 +101928,14 @@ module.exports = class phemex extends Exchange { if (execStatus === 'MakerFill') { takerOrMaker = 'maker'; } - price = this.fromEp (this.safeFloat (trade, 'execPriceEp'), market); - amount = this.fromEv (this.safeFloat (trade, 'execBaseQtyEv'), market); - amount = this.safeFloat (trade, 'execQty', amount); - cost = this.fromEv (this.safeFloat2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); - const feeCost = this.fromEv (this.safeFloat (trade, 'execFeeEv'), market); + price = this.fromEp (this.safeNumber (trade, 'execPriceEp'), market); + amount = this.fromEv (this.safeNumber (trade, 'execBaseQtyEv'), market); + amount = this.safeNumber (trade, 'execQty', amount); + cost = this.fromEv (this.safeNumber2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); + const feeCost = this.fromEv (this.safeNumber (trade, 'execFeeEv'), market); if (feeCost !== undefined) { let feeRate = undefined; - let feeRateEr = this.safeFloat (trade, 'feeRateEr'); + let feeRateEr = this.safeNumber (trade, 'feeRateEr'); if (feeRateEr < 0) { feeRateEr = Math.abs (feeRateEr); feeRate = this.fromEr (feeRateEr, market); @@ -103608,9 +102011,9 @@ module.exports = class phemex extends Exchange { const currency = this.safeValue (this.currencies, code, {}); const scale = this.safeInteger (currency, 'valueScale', 8); const account = this.account (); - const balanceEv = this.safeFloat (balance, 'balanceEv'); - const lockedTradingBalanceEv = this.safeFloat (balance, 'lockedTradingBalanceEv'); - const lockedWithdrawEv = this.safeFloat (balance, 'lockedWithdrawEv'); + const balanceEv = this.safeNumber (balance, 'balanceEv'); + const lockedTradingBalanceEv = this.safeNumber (balance, 'lockedTradingBalanceEv'); + const lockedWithdrawEv = this.safeNumber (balance, 'lockedWithdrawEv'); const total = this.fromEn (balanceEv, scale, scale, DECIMAL_PLACES); const lockedTradingBalance = this.fromEn (lockedTradingBalanceEv, scale, scale, DECIMAL_PLACES); const lockedWithdraw = this.fromEn (lockedWithdrawEv, scale, scale, DECIMAL_PLACES); @@ -103704,8 +102107,8 @@ module.exports = class phemex extends Exchange { const code = this.safeCurrencyCode (currencyId); const currency = this.currency (code); const account = this.account (); - const accountBalanceEv = this.safeFloat (balance, 'accountBalanceEv'); - const totalUsedBalanceEv = this.safeFloat (balance, 'totalUsedBalanceEv'); + const accountBalanceEv = this.safeNumber (balance, 'accountBalanceEv'); + const totalUsedBalanceEv = this.safeNumber (balance, 'totalUsedBalanceEv'); const valueScale = this.safeInteger (currency, 'valueScale', 8); account['total'] = this.fromEn (accountBalanceEv, valueScale, valueScale, DECIMAL_PLACES); account['used'] = this.fromEn (totalUsedBalanceEv, valueScale, valueScale, DECIMAL_PLACES); @@ -103937,21 +102340,21 @@ module.exports = class phemex extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let price = this.fromEp (this.safeFloat (order, 'priceEp'), market); + let price = this.fromEp (this.safeNumber (order, 'priceEp'), market); if (price === 0) { price = undefined; } - const amount = this.fromEv (this.safeFloat (order, 'baseQtyEv'), market); - const remaining = this.fromEv (this.safeFloat (order, 'leavesBaseQtyEv'), market); - let filled = this.fromEv (this.safeFloat (order, 'cumBaseQtyEv'), market); - const cost = this.fromEv (this.safeFloat (order, 'quoteQtyEv'), market); - const average = this.fromEp (this.safeFloat (order, 'avgPriceEp'), market); + const amount = this.fromEv (this.safeNumber (order, 'baseQtyEv'), market); + const remaining = this.fromEv (this.safeNumber (order, 'leavesBaseQtyEv'), market); + let filled = this.fromEv (this.safeNumber (order, 'cumBaseQtyEv'), market); + const cost = this.fromEv (this.safeNumber (order, 'quoteQtyEv'), market); + const average = this.fromEp (this.safeNumber (order, 'avgPriceEp'), market); const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'ordType')); const timestamp = this.safeIntegerProduct2 (order, 'actionTimeNs', 'createTimeNs', 0.000001); let fee = undefined; - const feeCost = this.fromEv (this.safeFloat (order, 'cumFeeEv'), market); + const feeCost = this.fromEv (this.safeNumber (order, 'cumFeeEv'), market); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -103964,7 +102367,7 @@ module.exports = class phemex extends Exchange { } } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.fromEp (this.safeFloat (order, 'stopPxEp', market)); + const stopPrice = this.fromEp (this.safeNumber (order, 'stopPxEp', market)); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -104037,18 +102440,18 @@ module.exports = class phemex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'orderType')); - const price = this.fromEp (this.safeFloat (order, 'priceEp'), market); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); + const price = this.fromEp (this.safeNumber (order, 'priceEp'), market); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); const timestamp = this.safeIntegerProduct (order, 'actionTimeNs', 0.000001); - const cost = this.safeFloat (order, 'cumValue'); + const cost = this.safeNumber (order, 'cumValue'); let lastTradeTimestamp = this.safeIntegerProduct (order, 'transactTimeNs', 0.000001); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -104123,7 +102526,7 @@ module.exports = class phemex extends Exchange { } request['qtyType'] = qtyType; if (qtyType === 'ByQuote') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); params = this.omit (params, 'cost'); if (this.options['createOrderByQuoteRequiresPrice']) { if (price !== undefined) { @@ -104143,7 +102546,7 @@ module.exports = class phemex extends Exchange { if (type === 'Limit') { request['priceEp'] = this.toEp (price, market); } - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice !== undefined) { request['stopPxEp'] = this.toEp (stopPrice, market); } @@ -104651,7 +103054,7 @@ module.exports = class phemex extends Exchange { const code = currency['code']; const timestamp = this.safeInteger2 (transaction, 'createdAt', 'submitedAt'); let type = this.safeStringLower (transaction, 'type'); - const feeCost = this.fromEn (this.safeFloat (transaction, 'feeEv'), currency['valueScale'], currency['precision']); + const feeCost = this.fromEn (this.safeNumber (transaction, 'feeEv'), currency['valueScale'], currency['precision']); let fee = undefined; if (feeCost !== undefined) { type = 'withdrawal'; @@ -104661,7 +103064,7 @@ module.exports = class phemex extends Exchange { }; } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.fromEn (this.safeFloat (transaction, 'amountEv'), currency['valueScale'], currency['precision']); + const amount = this.fromEn (this.safeNumber (transaction, 'amountEv'), currency['valueScale'], currency['precision']); return { 'info': transaction, 'id': id, @@ -104683,7 +103086,7 @@ module.exports = class phemex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.safeString (params, 'code'); const request = {}; @@ -104836,13 +103239,14 @@ module.exports = class phemex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],120:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],117:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, RequestTimeout, AuthenticationError, PermissionDenied, DDoSProtection, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, CancelPending, InvalidNonce, OnMaintenance, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -104952,6 +103356,7 @@ module.exports = class poloniex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', // starting from Jan 8 2020 'maker': 0.0009, 'taker': 0.0009, @@ -105046,24 +103451,6 @@ module.exports = class poloniex extends Exchange { }); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - parseOHLCV (ohlcv, market = undefined) { // // { @@ -105079,11 +103466,11 @@ module.exports = class poloniex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'date'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'quoteVolume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'quoteVolume'), ]; } @@ -105176,11 +103563,11 @@ module.exports = class poloniex extends Exchange { const balance = this.safeValue (response, currencyId, {}); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onOrders'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFees (params = {}) { @@ -105198,8 +103585,8 @@ module.exports = class poloniex extends Exchange { // return { 'info': fees, - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), 'withdraw': {}, 'deposit': {}, }; @@ -105257,8 +103644,8 @@ module.exports = class poloniex extends Exchange { let open = undefined; let change = undefined; let average = undefined; - const last = this.safeFloat (ticker, 'last'); - const relativeChange = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const relativeChange = this.safeNumber (ticker, 'percentChange'); if (relativeChange !== -1) { open = last / this.sum (1, relativeChange); change = last - open; @@ -105268,11 +103655,11 @@ module.exports = class poloniex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24hr'), - 'low': this.safeFloat (ticker, 'low24hr'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high24hr'), + 'low': this.safeNumber (ticker, 'low24hr'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -105282,8 +103669,8 @@ module.exports = class poloniex extends Exchange { 'change': change, 'percentage': relativeChange * 100, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -105324,7 +103711,7 @@ module.exports = class poloniex extends Exchange { const code = this.safeCurrencyCode (id); const active = (currency['delisted'] === 0) && !currency['disabled']; const numericId = this.safeInteger (currency, 'id'); - const fee = this.safeFloat (currency, 'txFee'); + const fee = this.safeNumber (currency, 'txFee'); result[code] = { 'id': id, 'numericId': numericId, @@ -105415,13 +103802,18 @@ module.exports = class poloniex extends Exchange { } const side = this.safeString (trade, 'type'); let fee = undefined; - const price = this.safeFloat (trade, 'rate'); - const cost = this.safeFloat (trade, 'total'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const feeDisplay = this.safeString (trade, 'feeDisplay'); if (feeDisplay !== undefined) { const parts = feeDisplay.split (' '); - const feeCost = this.safeFloat (parts, 0); + const feeCost = this.safeNumber (parts, 0); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -105440,7 +103832,7 @@ module.exports = class poloniex extends Exchange { } } let takerOrMaker = undefined; - const takerAdjustment = this.safeFloat (trade, 'takerAdjustment'); + const takerAdjustment = this.safeNumber (trade, 'takerAdjustment'); if (takerAdjustment !== undefined) { takerOrMaker = 'taker'; } @@ -105686,9 +104078,9 @@ module.exports = class poloniex extends Exchange { if (resultingTrades !== undefined) { trades = this.parseTrades (resultingTrades, market); } - const price = this.safeFloat2 (order, 'price', 'rate'); - let remaining = this.safeFloat (order, 'amount'); - let amount = this.safeFloat (order, 'startingAmount'); + const price = this.safeNumber2 (order, 'price', 'rate'); + let remaining = this.safeNumber (order, 'amount'); + let amount = this.safeNumber (order, 'startingAmount'); let filled = undefined; let cost = 0; if (amount !== undefined) { @@ -105738,7 +104130,7 @@ module.exports = class poloniex extends Exchange { } const id = this.safeString (order, 'orderNumber'); let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -106235,11 +104627,11 @@ module.exports = class poloniex extends Exchange { const defaultType = ('withdrawalNumber' in transaction) ? 'withdrawal' : 'deposit'; const type = this.safeString (transaction, 'type', defaultType); const id = this.safeString2 (transaction, 'withdrawalNumber', 'depositNumber'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'paymentID'); // according to https://poloniex.com/fees/ - const feeCost = this.safeFloat (transaction, 'fee', 0); + const feeCost = this.safeNumber (transaction, 'fee', 0); if (type === 'withdrawal') { // poloniex withdrawal amount includes the fee amount = amount - feeCost; @@ -106323,7 +104715,7 @@ module.exports = class poloniex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],121:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],118:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -106331,6 +104723,7 @@ module.exports = class poloniex extends Exchange { const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, BadResponse, BadRequest, InvalidOrder, InsufficientFunds, AuthenticationError, ArgumentsRequired, InvalidAddress, RateLimitExceeded, DDoSProtection, BadSymbol } = require ('./base/errors'); const { TRUNCATE, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -106466,9 +104859,11 @@ module.exports = class probit extends Exchange { }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', 'CBC': 'CryptoBharatCoin', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'HBC': 'Hybrid Bank Cash', 'UNI': 'UNICORN Token', }, @@ -106517,11 +104912,11 @@ module.exports = class probit extends Exchange { const costPrecision = this.safeInteger (market, 'cost_precision'); const precision = { 'amount': 1 / Math.pow (10, amountPrecision), - 'price': this.safeFloat (market, 'price_increment'), + 'price': this.safeNumber (market, 'price_increment'), 'cost': 1 / Math.pow (10, costPrecision), }; - const takerFeeRate = this.safeFloat (market, 'taker_fee_rate'); - const makerFeeRate = this.safeFloat (market, 'maker_fee_rate'); + const takerFeeRate = this.safeNumber (market, 'taker_fee_rate'); + const makerFeeRate = this.safeNumber (market, 'maker_fee_rate'); result.push ({ 'id': id, 'info': market, @@ -106536,16 +104931,16 @@ module.exports = class probit extends Exchange { 'maker': makerFeeRate / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_cost'), - 'max': this.safeFloat (market, 'max_cost'), + 'min': this.safeNumber (market, 'min_cost'), + 'max': this.safeNumber (market, 'max_cost'), }, }, }); @@ -106632,7 +105027,7 @@ module.exports = class probit extends Exchange { // [ { 'amount': '0.015', 'priority': 1, 'currency_id': 'ETH' }, {} ] for (let j = 0; j < withdrawalFees.length; j++) { const withdrawalFee = withdrawalFees[j]; - const amount = this.safeFloat (withdrawalFee, 'amount'); + const amount = this.safeNumber (withdrawalFee, 'amount'); const priority = this.safeInteger (withdrawalFee, 'priority'); if ((amount !== undefined) && (priority !== undefined)) { fees.push (withdrawalFee); @@ -106640,7 +105035,7 @@ module.exports = class probit extends Exchange { } const withdrawalFeesByPriority = this.sortBy (fees, 'priority'); const withdrawalFee = this.safeValue (withdrawalFeesByPriority, 0, {}); - const fee = this.safeFloat (withdrawalFee, 'amount'); + const fee = this.safeNumber (withdrawalFee, 'amount'); result[code] = { 'id': id, 'code': code, @@ -106663,11 +105058,11 @@ module.exports = class probit extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (platform, 'min_deposit_amount'), + 'min': this.safeNumber (platform, 'min_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (platform, 'min_withdrawal_amount'), + 'min': this.safeNumber (platform, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -106697,11 +105092,11 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (balance, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'total'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -106753,14 +105148,6 @@ module.exports = class probit extends Exchange { return this.parseTickers (data, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -106808,8 +105195,8 @@ module.exports = class probit extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); - const close = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); + const close = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); let percentage = undefined; let open = undefined; if (change !== undefined) { @@ -106818,15 +105205,15 @@ module.exports = class probit extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -106968,16 +105355,13 @@ module.exports = class probit extends Exchange { marketId = this.safeString (trade, 'market_id', marketId); const symbol = this.safeSymbol (marketId, market, '-'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'order_id'); - const feeCost = this.safeFloat (trade, 'fee_amount'); + const feeCost = this.safeNumber (trade, 'fee_amount'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency_id'); @@ -107121,11 +105505,11 @@ module.exports = class probit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'start_time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_volume'), ]; } @@ -107224,37 +105608,24 @@ module.exports = class probit extends Exchange { const marketId = this.safeString (order, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'time')); - let price = this.safeFloat (order, 'limit_price'); - const filled = this.safeFloat (order, 'filled_quantity'); - let remaining = this.safeFloat (order, 'open_quantity'); - const canceledAmount = this.safeFloat (order, 'cancelled_quantity'); + let price = this.safeNumber (order, 'limit_price'); + const filled = this.safeNumber (order, 'filled_quantity'); + let remaining = this.safeNumber (order, 'open_quantity'); + const canceledAmount = this.safeNumber (order, 'cancelled_quantity'); if (canceledAmount !== undefined) { remaining = this.sum (remaining, canceledAmount); } - const amount = this.safeFloat (order, 'quantity', this.sum (filled, remaining)); - let cost = this.safeFloat2 (order, 'filled_cost', 'cost'); + const amount = this.safeNumber (order, 'quantity', this.sum (filled, remaining)); + const cost = this.safeNumber2 (order, 'filled_cost', 'cost'); if (type === 'market') { price = undefined; } - let average = undefined; - if (filled !== undefined) { - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if (cost !== undefined) { - if (filled > 0) { - average = cost / filled; - } - } - } let clientOrderId = this.safeString (order, 'client_order_id'); if (clientOrderId === '') { clientOrderId = undefined; } const timeInForce = this.safeStringUpper (order, 'time_in_force'); - return { + return this.safeOrder ({ 'id': id, 'info': order, 'clientOrderId': clientOrderId, @@ -107271,11 +105642,11 @@ module.exports = class probit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'average': average, + 'average': undefined, 'cost': cost, 'fee': undefined, 'trades': undefined, - }; + }); } costToPrecision (symbol, cost) { @@ -107305,7 +105676,7 @@ module.exports = class probit extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -107430,16 +105801,6 @@ module.exports = class probit extends Exchange { return this.parseDepositAddresses (data); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { // In order to use this method // you need to allow API withdrawal from the API Settings Page, and @@ -107470,7 +105831,7 @@ module.exports = class probit extends Exchange { parseTransaction (transaction, currency = undefined) { const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'destination_tag'); const txid = this.safeString (transaction, 'hash'); @@ -107479,7 +105840,7 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (transaction, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined && feeCost !== 0) { fee = { @@ -107609,13 +105970,14 @@ module.exports = class probit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],122:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],119:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, InsufficientFunds, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -107791,11 +106153,11 @@ module.exports = class qtrade extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_buy_value'), + 'min': this.safeNumber (market, 'minimum_buy_value'), 'max': undefined, }, 'price': { @@ -107876,12 +106238,12 @@ module.exports = class qtrade extends Exchange { 'info': currency, 'type': type, 'name': name, - 'fee': this.safeFloat (config, 'withdraw_fee'), + 'fee': this.safeNumber (config, 'withdraw_fee'), 'precision': this.safeInteger (currency, 'precision'), 'active': active, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimum_order'), + 'min': this.safeNumber (currency, 'minimum_order'), 'max': undefined, }, 'price': { @@ -107916,11 +106278,11 @@ module.exports = class qtrade extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'market_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'market_volume'), ]; } @@ -107982,8 +106344,8 @@ module.exports = class qtrade extends Exchange { const result = []; for (let j = 0; j < prices.length; j++) { const priceAsString = prices[j]; - const price = this.safeFloat (prices, j); - const amount = this.safeFloat (bidasks, priceAsString); + const price = this.safeNumber (prices, j); + const amount = this.safeNumber (bidasks, priceAsString); result.push ([ price, amount ]); } orderbook[side] = result; @@ -108015,12 +106377,12 @@ module.exports = class qtrade extends Exchange { const marketId = this.safeString (ticker, 'id_hr'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeIntegerProduct (ticker, 'last_change', 0.001); - const previous = this.safeFloat (ticker, 'day_open'); - const last = this.safeFloat (ticker, 'last'); - const day_change = this.safeFloat (ticker, 'day_change'); + const previous = this.safeNumber (ticker, 'day_open'); + const last = this.safeNumber (ticker, 'last'); + const day_change = this.safeNumber (ticker, 'day_change'); let percentage = undefined; let change = undefined; - let average = this.safeFloat (ticker, 'day_avg_price'); + let average = this.safeNumber (ticker, 'day_avg_price'); if (day_change !== undefined) { percentage = day_change * 100; if (previous !== undefined) { @@ -108030,18 +106392,18 @@ module.exports = class qtrade extends Exchange { if ((average === undefined) && (last !== undefined) && (previous !== undefined)) { average = this.sum (last, previous) / 2; } - const baseVolume = this.safeFloat (ticker, 'day_volume_market'); - const quoteVolume = this.safeFloat (ticker, 'day_volume_base'); + const baseVolume = this.safeNumber (ticker, 'day_volume_market'); + const quoteVolume = this.safeNumber (ticker, 'day_volume_base'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'day_high'), - 'low': this.safeFloat (ticker, 'day_low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'day_high'), + 'low': this.safeNumber (ticker, 'day_low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': previous, @@ -108249,16 +106611,16 @@ module.exports = class qtrade extends Exchange { const side = this.safeString (trade, 'side'); const marketId = this.safeString (trade, 'market_string'); const symbol = this.safeSymbol (marketId, market, '_'); - let cost = this.safeFloat2 (trade, 'base_volume', 'base_amount'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'market_amount', 'amount'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - if (price !== undefined) { - cost = price * amount; - } + let cost = this.safeNumber2 (trade, 'base_volume', 'base_amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'market_amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'base_fee'); + const feeCost = this.safeNumber (trade, 'base_fee'); if (feeCost !== undefined) { const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; fee = { @@ -108315,7 +106677,7 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); account['used'] = 0; result[code] = account; } @@ -108325,10 +106687,10 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -108457,10 +106819,9 @@ module.exports = class qtrade extends Exchange { side = this.safeString (parts, 0); orderType = this.safeString (parts, 1); } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'market_amount'); - let remaining = this.safeFloat (order, 'market_amount_remaining'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'market_amount'); + const remaining = this.safeNumber (order, 'market_amount_remaining'); const open = this.safeValue (order, 'open', false); const closeReason = this.safeString (order, 'close_reason'); let status = undefined; @@ -108472,58 +106833,21 @@ module.exports = class qtrade extends Exchange { status = 'closed'; } const marketId = this.safeString (order, 'market_string'); - const symbol = this.safeSymbol (marketId, market, '_'); + market = this.safeMarket (marketId, market, '_'); + const symbol = market['symbol']; const rawTrades = this.safeValue (order, 'trades', []); const parsedTrades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id, 'side': side, 'type': orderType, }); - const numTrades = parsedTrades.length; - let lastTradeTimestamp = undefined; - let feeCost = undefined; - let cost = undefined; - if (numTrades > 0) { - feeCost = 0; - cost = 0; - filled = 0; - remaining = amount; - for (let i = 0; i < parsedTrades.length; i++) { - const trade = parsedTrades[i]; - feeCost = this.sum (trade['fee']['cost'], feeCost); - lastTradeTimestamp = this.safeInteger (trade, 'timestamp'); - cost = this.sum (trade['cost'], cost); - filled = this.sum (trade['amount'], filled); - remaining = Math.max (0, remaining - trade['amount']); - } - } - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; - fee = { - 'currency': feeCurrencyCode, - 'cost': feeCost, - }; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let average = undefined; - if (filled !== undefined) { - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': orderType, 'timeInForce': undefined, @@ -108531,15 +106855,16 @@ module.exports = class qtrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, - 'fee': fee, - 'cost': cost, + 'fee': undefined, + 'fees': undefined, + 'cost': undefined, 'trades': parsedTrades, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -109008,7 +107333,7 @@ module.exports = class qtrade extends Exchange { const tagTo = tag; const cancelRequested = this.safeValue (transaction, 'cancel_requested'); const type = (cancelRequested === undefined) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); let status = this.parseTransactionStatus (this.safeString (transaction, 'status')); @@ -109152,7 +107477,7 @@ module.exports = class qtrade extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],123:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],120:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); @@ -109340,8 +107665,8 @@ module.exports = class rightbtc extends Exchange { return result; } - divideSafeFloat (x, key, divisor) { - const value = this.safeFloat (x, key); + divideSafeNumber (x, key, divisor) { + const value = this.safeNumber (x, key); if (value !== undefined) { return value / divisor; } @@ -109351,12 +107676,12 @@ module.exports = class rightbtc extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); - const last = this.divideSafeFloat (ticker, 'last', 1e8); - const high = this.divideSafeFloat (ticker, 'high', 1e8); - const low = this.divideSafeFloat (ticker, 'low', 1e8); - const bid = this.divideSafeFloat (ticker, 'buy', 1e8); - const ask = this.divideSafeFloat (ticker, 'sell', 1e8); - const baseVolume = this.divideSafeFloat (ticker, 'vol24h', 1e8); + const last = this.divideSafeNumber (ticker, 'last', 1e8); + const high = this.divideSafeNumber (ticker, 'high', 1e8); + const low = this.divideSafeNumber (ticker, 'low', 1e8); + const bid = this.divideSafeNumber (ticker, 'buy', 1e8); + const ask = this.divideSafeNumber (ticker, 'sell', 1e8); + const baseVolume = this.divideSafeNumber (ticker, 'vol24h', 1e8); return { 'symbol': symbol, 'timestamp': timestamp, @@ -109460,9 +107785,9 @@ module.exports = class rightbtc extends Exchange { let id = this.safeString (trade, 'tid'); id = this.safeString (trade, 'trade_id', id); const orderId = this.safeString (trade, 'order_id'); - const price = this.divideSafeFloat (trade, 'price', 1e8); - let amount = this.safeFloat (trade, 'amount'); - amount = this.safeFloat (trade, 'quantity', amount); + const price = this.divideSafeNumber (trade, 'price', 1e8); + let amount = this.safeNumber (trade, 'amount'); + amount = this.safeNumber (trade, 'quantity', amount); if (amount !== undefined) { amount = amount / 1e8; } @@ -109559,8 +107884,8 @@ module.exports = class rightbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); // https://github.com/ccxt/ccxt/issues/3873 - account['free'] = this.divideSafeFloat (balance, 'balance', 1e8); - account['used'] = this.divideSafeFloat (balance, 'frozen', 1e8); + account['free'] = this.divideSafeNumber (balance, 'balance', 1e8); + account['used'] = this.divideSafeNumber (balance, 'frozen', 1e8); result[code] = account; } return this.parseBalance (result); @@ -109649,30 +107974,18 @@ module.exports = class rightbtc extends Exchange { } else if ('transactTime' in order) { timestamp = order['transactTime']; } - let price = this.safeFloat2 (order, 'limit', 'price'); + let price = this.safeNumber2 (order, 'limit', 'price'); if (price !== undefined) { price = price / 1e8; } - const amount = this.divideSafeFloat (order, 'quantity', 1e8); - let filled = this.divideSafeFloat (order, 'filled_quantity', 1e8); - let remaining = this.divideSafeFloat (order, 'rest', 1e8); - const cost = this.divideSafeFloat (order, 'cost', 1e8); + const amount = this.divideSafeNumber (order, 'quantity', 1e8); + const filled = this.divideSafeNumber (order, 'filled_quantity', 1e8); + const remaining = this.divideSafeNumber (order, 'rest', 1e8); + const cost = this.divideSafeNumber (order, 'cost', 1e8); // lines 483-494 should be generalized into a base class method - if (amount !== undefined) { - if (remaining === undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - if (filled === undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } - } const type = 'limit'; const side = this.safeStringLower (order, 'side'); - const feeCost = this.divideSafeFloat (order, 'min_fee', 1e8); + const feeCost = this.divideSafeNumber (order, 'min_fee', 1e8); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -109680,13 +107993,13 @@ module.exports = class rightbtc extends Exchange { feeCurrency = market['quote']; } fee = { - 'rate': this.safeFloat (order, 'fee'), + 'rate': this.safeNumber (order, 'fee'), 'cost': feeCost, 'currency': feeCurrency, }; } const trades = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -109708,7 +108021,7 @@ module.exports = class rightbtc extends Exchange { 'fee': fee, 'trades': trades, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -109912,7 +108225,7 @@ module.exports = class rightbtc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],124:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9,"./base/functions/number":15}],121:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -109920,6 +108233,7 @@ module.exports = class rightbtc extends Exchange { const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, BadSymbol, BadRequest, InvalidOrder, ArgumentsRequired, OrderNotFound, InsufficientFunds, DDoSProtection } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110064,12 +108378,12 @@ module.exports = class ripio extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'min_amount'), - 'price': this.safeFloat (market, 'price_tick'), + 'amount': this.safeNumber (market, 'min_amount'), + 'price': this.safeNumber (market, 'price_tick'), }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -110077,15 +108391,15 @@ module.exports = class ripio extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_value'), + 'min': this.safeNumber (market, 'min_value'), 'max': undefined, }, }; const active = this.safeValue (market, 'enabled', true); const fees = this.safeValue (market, 'fees', []); const firstFee = this.safeValue (fees, 0, {}); - const maker = this.safeFloat (firstFee, 'maker_fee', 0.0); - const taker = this.safeFloat (firstFee, 'taker_fee', 0.0); + const maker = this.safeNumber (firstFee, 'maker_fee', 0.0); + const taker = this.safeNumber (firstFee, 'taker_fee', 0.0); result.push ({ 'id': id, 'symbol': symbol, @@ -110192,18 +108506,18 @@ module.exports = class ripio extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); const marketId = this.safeString (ticker, 'pair'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const average = this.safeFloat (ticker, 'avg'); + const last = this.safeNumber (ticker, 'last_price'); + const average = this.safeNumber (ticker, 'avg'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bid_volume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'ask_volume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bid_volume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'ask_volume'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -110345,15 +108659,14 @@ module.exports = class ripio extends Exchange { if (side !== undefined) { side = side.toLowerCase (); } - const price = this.safeFloat2 (trade, 'price', 'match_price'); - const amount = this.safeFloat2 (trade, 'amount', 'exchanged'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString2 (trade, 'price', 'match_price'); + const amountString = this.safeString2 (trade, 'amount', 'exchanged'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'pair'); market = this.safeMarket (marketId, market); - const feeCost = this.safeFloat (trade, takerOrMaker + '_fee'); + const feeCost = this.safeNumber (trade, takerOrMaker + '_fee'); const orderId = this.safeString (trade, takerOrMaker); let fee = undefined; if (feeCost !== undefined) { @@ -110427,11 +108740,11 @@ module.exports = class ripio extends Exchange { const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -110690,16 +109003,16 @@ module.exports = class ripio extends Exchange { // } // const id = this.safeString (order, 'order_id'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat (order, 'notional'); + const amount = this.safeNumber (order, 'amount'); + let cost = this.safeNumber (order, 'notional'); const type = this.safeStringLower (order, 'order_type'); const priceField = (type === 'market') ? 'fill_price' : 'limit_price'; - const price = this.safeFloat (order, priceField); + const price = this.safeNumber (order, priceField); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeTimestamp (order, 'created_at'); let average = this.safeValue (order, 'fill_price'); - let filled = this.safeFloat (order, 'filled'); + let filled = this.safeNumber (order, 'filled'); let remaining = undefined; const fills = this.safeValue (order, 'fills'); let trades = undefined; @@ -110734,7 +109047,7 @@ module.exports = class ripio extends Exchange { } const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); return { 'id': id, 'clientOrderId': undefined, @@ -110860,13 +109173,14 @@ module.exports = class ripio extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],125:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],122:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110977,14 +109291,14 @@ module.exports = class southxchange extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const deposited = this.safeFloat (balance, 'Deposited'); - const unconfirmed = this.safeFloat (balance, 'Unconfirmed'); + const deposited = this.safeString (balance, 'Deposited'); + const unconfirmed = this.safeString (balance, 'Unconfirmed'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'Available'); - account['total'] = this.sum (deposited, unconfirmed); + account['free'] = this.safeString (balance, 'Available'); + account['total'] = Precise.stringAdd (deposited, unconfirmed); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -111002,16 +109316,16 @@ module.exports = class southxchange extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'Last'); + const last = this.safeNumber (ticker, 'Last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'Bid'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -111019,9 +109333,9 @@ module.exports = class southxchange extends Exchange { 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'Variation24Hr'), + 'percentage': this.safeNumber (ticker, 'Variation24Hr'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume24Hr'), + 'baseVolume': this.safeNumber (ticker, 'Volume24Hr'), 'quoteVolume': undefined, 'info': ticker, }; @@ -111055,14 +109369,11 @@ module.exports = class southxchange extends Exchange { parseTrade (trade, market) { const timestamp = this.safeTimestamp (trade, 'At'); - const price = this.safeFloat (trade, 'Price'); - const amount = this.safeFloat (trade, 'Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'Price'); + const amountString = this.safeString (trade, 'Amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'Type'); let symbol = undefined; if (market !== undefined) { @@ -111103,21 +109414,13 @@ module.exports = class southxchange extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const timestamp = undefined; - const price = this.safeFloat (order, 'LimitPrice'); - const amount = this.safeFloat (order, 'OriginalAmount'); - const remaining = this.safeFloat (order, 'Amount'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - cost = price * amount; - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'LimitPrice'); + const amount = this.safeNumber (order, 'OriginalAmount'); + const remaining = this.safeNumber (order, 'Amount'); const type = 'limit'; const side = this.safeStringLower (order, 'Type'); const id = this.safeString (order, 'Code'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -111132,15 +109435,14 @@ module.exports = class southxchange extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'filled': filled, + 'cost': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -111273,8 +109575,8 @@ module.exports = class southxchange extends Exchange { const type = this.safeString (item, 'Type'); const ledgerEntryType = this.parseLedgerEntryType (type); const code = this.safeCurrencyCode (this.safeString (item, 'CurrencyCode'), currency); - let amount = this.safeFloat (item, 'Amount'); - const after = this.safeFloat (item, 'TotalBalance'); + let amount = this.safeNumber (item, 'Amount'); + const after = this.safeNumber (item, 'TotalBalance'); let before = undefined; if (amount !== undefined) { if (after !== undefined) { @@ -111445,7 +109747,7 @@ module.exports = class southxchange extends Exchange { // } // const id = this.safeString (transaction, 'MovementId'); - const amount = this.safeFloat (transaction, 'Amount'); + const amount = this.safeNumber (transaction, 'Amount'); const address = this.safeString (transaction, 'Address'); const addressTo = address; const addressFrom = undefined; @@ -111560,7 +109862,7 @@ module.exports = class southxchange extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],126:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],123:[function(require,module,exports){ (function (module, exports) { 'use strict'; @@ -115088,7 +113390,7 @@ module.exports = class southxchange extends Exchange { }; })(typeof module === 'undefined' || module, this); -},{"buffer":188}],127:[function(require,module,exports){ +},{"buffer":184}],124:[function(require,module,exports){ ;(function (root, factory) { if (typeof exports === "object") { // CommonJS @@ -121077,7 +119379,7 @@ module.exports = class southxchange extends Exchange { return CryptoJS; })); -},{}],128:[function(require,module,exports){ +},{}],125:[function(require,module,exports){ 'use strict'; var elliptic = exports; @@ -121101,7 +119403,7 @@ elliptic.curves = require('./elliptic/curves'); elliptic.ec = require('./elliptic/ec'); elliptic.eddsa = require('./elliptic/eddsa'); -},{"./elliptic/curve":131,"./elliptic/curves":134,"./elliptic/ec":135,"./elliptic/eddsa":138,"./elliptic/utils":142}],129:[function(require,module,exports){ +},{"./elliptic/curve":128,"./elliptic/curves":131,"./elliptic/ec":132,"./elliptic/eddsa":135,"./elliptic/utils":139}],126:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -121478,7 +119780,7 @@ BasePoint.prototype.dblp = function dblp(k) { return r; }; -},{"../../../../BN/bn":126,"../../elliptic":128}],130:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],127:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -121913,7 +120215,7 @@ Point.prototype.eqXToP = function eqXToP(x) { Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],131:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],128:[function(require,module,exports){ 'use strict'; var curve = exports; @@ -121923,7 +120225,7 @@ curve.short = require('./short'); curve.mont = require('./mont'); curve.edwards = require('./edwards'); -},{"./base":129,"./edwards":130,"./mont":132,"./short":133}],132:[function(require,module,exports){ +},{"./base":126,"./edwards":127,"./mont":129,"./short":130}],129:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -122105,7 +120407,7 @@ Point.prototype.getX = function getX() { return this.x.fromRed(); }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],133:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],130:[function(require,module,exports){ 'use strict'; var curve = require('../curve'); @@ -123045,7 +121347,7 @@ JPoint.prototype.isInfinity = function isInfinity() { return this.z.cmpn(0) === 0; }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../curve":131}],134:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../curve":128}],131:[function(require,module,exports){ 'use strict'; var curves = exports; @@ -123251,7 +121553,7 @@ defineCurve('secp256k1', { ] }); -},{"../elliptic":128,"./precomputed/secp256k1":141}],135:[function(require,module,exports){ +},{"../elliptic":125,"./precomputed/secp256k1":138}],132:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123493,7 +121795,7 @@ EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { throw new Error('Unable to find valid recovery factor'); }; -},{"../../../../BN/bn":126,"../../elliptic":128,"../../hmac-drbg/hmac-drbg":143,"./key":136,"./signature":137}],136:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125,"../../hmac-drbg/hmac-drbg":140,"./key":133,"./signature":134}],133:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123614,7 +121916,7 @@ KeyPair.prototype.inspect = function inspect() { ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; }; -},{"../../../../BN/bn":126,"../../elliptic":128}],137:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],134:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123640,7 +121942,7 @@ function Signature(options, enc) { } module.exports = Signature; -},{"../../../../BN/bn":126,"../../elliptic":128}],138:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../../elliptic":125}],135:[function(require,module,exports){ 'use strict'; var curves = require('../curves'); @@ -123787,7 +122089,7 @@ EDDSA.prototype.isPoint = function isPoint(val) { return val instanceof this.pointClass; }; -},{"../../../../../base/functions/encode":11,"../../../../BN/bn.js":126,"../../../../crypto-js/crypto-js":127,"../curves":134,"../utils":142,"./key":139,"./signature":140}],139:[function(require,module,exports){ +},{"../../../../../base/functions/encode":12,"../../../../BN/bn.js":123,"../../../../crypto-js/crypto-js":124,"../curves":131,"../utils":139,"./key":136,"./signature":137}],136:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -123889,7 +122191,7 @@ KeyPair.prototype.getPublic = function getPublic(enc) { module.exports = KeyPair; -},{"../utils":142}],140:[function(require,module,exports){ +},{"../utils":139}],137:[function(require,module,exports){ 'use strict'; var BN = require('../../../../BN/bn'); @@ -123956,7 +122258,7 @@ Signature.prototype.toHex = function toHex() { module.exports = Signature; -},{"../../../../BN/bn":126,"../utils":142}],141:[function(require,module,exports){ +},{"../../../../BN/bn":123,"../utils":139}],138:[function(require,module,exports){ module.exports = { doubles: { step: 4, @@ -124738,7 +123040,7 @@ module.exports = { } }; -},{}],142:[function(require,module,exports){ +},{}],139:[function(require,module,exports){ 'use strict'; var utils = exports; @@ -124954,7 +123256,7 @@ utils.encode = function encode(arr, enc) { return arr; }; -},{"../../../BN/bn":126}],143:[function(require,module,exports){ +},{"../../../BN/bn":123}],140:[function(require,module,exports){ 'use strict'; var CryptoJS = require('../../../crypto-js/crypto-js'); @@ -125070,7 +123372,7 @@ HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { return utils.wordArrayToBuffer(res); }; -},{"../../../../base/functions/encode":11,"../../../crypto-js/crypto-js":127,"../elliptic/utils":142}],144:[function(require,module,exports){ +},{"../../../../base/functions/encode":12,"../../../crypto-js/crypto-js":124,"../elliptic/utils":139}],141:[function(require,module,exports){ 'use strict'; var fetch = require('../node-fetch/index'); @@ -125111,7 +123413,7 @@ module.exports = function (context) { }; }; -},{"../node-fetch/index":145}],145:[function(require,module,exports){ +},{"../node-fetch/index":142}],142:[function(require,module,exports){ (function (global,Buffer){ 'use strict'; @@ -126679,7 +124981,7 @@ exports.Response = Response; exports.FetchError = FetchError; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"buffer":188,"http":230,"https":193,"stream":229,"url":236,"zlib":187}],146:[function(require,module,exports){ +},{"buffer":184,"http":226,"https":189,"stream":225,"url":232,"zlib":183}],143:[function(require,module,exports){ (function (Buffer){ /*! * RSA library for Node.js @@ -126906,7 +125208,7 @@ module.exports = (function () { })(); }).call(this,require("buffer").Buffer) -},{"./formats/formats.js":153,"./libs/rsa.js":157,"./schemes/schemes.js":159,"./utils":160,"buffer":188}],147:[function(require,module,exports){ +},{"./formats/formats.js":150,"./libs/rsa.js":154,"./schemes/schemes.js":156,"./utils":157,"buffer":184}],144:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. @@ -126921,7 +125223,7 @@ module.exports = { }; -},{}],148:[function(require,module,exports){ +},{}],145:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. var errors = require('./errors'); @@ -126944,7 +125246,7 @@ for (var e in errors) { module.exports[e] = errors[e]; } -},{"./errors":147,"./reader":149,"./types":150}],149:[function(require,module,exports){ +},{"./errors":144,"./reader":146,"./types":147}],146:[function(require,module,exports){ (function (Buffer){ // Copyright 2011 Mark Cavage All rights reserved. @@ -127210,7 +125512,7 @@ Reader.prototype._readTag = function (tag) { module.exports = Reader; }).call(this,require("buffer").Buffer) -},{"./errors":147,"./types":150,"assert":183,"buffer":188}],150:[function(require,module,exports){ +},{"./errors":144,"./types":147,"assert":179,"buffer":184}],147:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. @@ -127248,7 +125550,7 @@ module.exports = { Context: 128 }; -},{}],151:[function(require,module,exports){ +},{}],148:[function(require,module,exports){ // Copyright 2011 Mark Cavage All rights reserved. // If you have no idea what ASN.1 or BER is, see this: @@ -127267,7 +125569,7 @@ module.exports = { BerReader: Ber.Reader, }; -},{"./ber/index":148}],152:[function(require,module,exports){ +},{"./ber/index":145}],149:[function(require,module,exports){ var _ = require('../utils')._; var utils = require('../utils'); @@ -127340,7 +125642,7 @@ module.exports = { } }; -},{"../utils":160}],153:[function(require,module,exports){ +},{"../utils":157}],150:[function(require,module,exports){ var _ = require('../utils')._; module.exports = { @@ -127373,7 +125675,7 @@ module.exports = { }, }; -},{"../utils":160,"./components":152,"./pkcs1":154,"./pkcs8":155}],154:[function(require,module,exports){ +},{"../utils":157,"./components":149,"./pkcs1":151,"./pkcs8":152}],151:[function(require,module,exports){ (function (Buffer){ var ber = require('../asn1/index').Ber; var _ = require('../utils')._; @@ -127525,7 +125827,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"../asn1/index":151,"../utils":160,"buffer":188}],155:[function(require,module,exports){ +},{"../asn1/index":148,"../utils":157,"buffer":184}],152:[function(require,module,exports){ (function (Buffer){ var ber = require('../asn1/index').Ber; var _ = require('../utils')._; @@ -127716,7 +126018,7 @@ module.exports = { }; }).call(this,require("buffer").Buffer) -},{"../asn1/index":151,"../utils":160,"buffer":188}],156:[function(require,module,exports){ +},{"../asn1/index":148,"../utils":157,"buffer":184}],153:[function(require,module,exports){ (function (Buffer){ /* * Basic JavaScript BN library - subset useful for RSA encryption. @@ -128972,7 +127274,7 @@ BigInteger.prototype.square = bnSquare; module.exports = BigInteger; }).call(this,require("buffer").Buffer) -},{"../utils":160,"buffer":188}],157:[function(require,module,exports){ +},{"../utils":157,"buffer":184}],154:[function(require,module,exports){ /* * RSA Encryption / Decryption with PKCS1 v2 Padding. * @@ -129121,7 +127423,7 @@ module.exports.Key = (function () { })(); -},{"../schemes/schemes.js":159,"../utils":160,"../utils.js":160,"./jsbn.js":156}],158:[function(require,module,exports){ +},{"../schemes/schemes.js":156,"../utils":157,"../utils.js":157,"./jsbn.js":153}],155:[function(require,module,exports){ (function (Buffer){ /** * PKCS1 padding and signature scheme @@ -129301,7 +127603,7 @@ function wordArrayToBuffer(wordArray) { } }).call(this,require("buffer").Buffer) -},{"../../crypto-js/crypto-js":127,"../libs/jsbn":156,"buffer":188,"constants":190}],159:[function(require,module,exports){ +},{"../../crypto-js/crypto-js":124,"../libs/jsbn":153,"buffer":184,"constants":186}],156:[function(require,module,exports){ module.exports = { pkcs1: require('./pkcs1'), @@ -129324,7 +127626,7 @@ module.exports = { } }; -},{"./pkcs1":158}],160:[function(require,module,exports){ +},{"./pkcs1":155}],157:[function(require,module,exports){ /* * Utils functions * @@ -129424,7 +127726,7 @@ module.exports.trimSurroundingText = function (data, opening, closing) { return data.substring(trimStartIndex, trimEndIndex); } -},{}],161:[function(require,module,exports){ +},{}],158:[function(require,module,exports){ 'use strict'; var replace = String.prototype.replace; @@ -129444,7 +127746,7 @@ module.exports = { RFC3986: 'RFC3986' }; -},{}],162:[function(require,module,exports){ +},{}],159:[function(require,module,exports){ 'use strict'; var stringify = require('./stringify'); @@ -129457,7 +127759,7 @@ module.exports = { stringify: stringify }; -},{"./formats":161,"./parse":163,"./stringify":164}],163:[function(require,module,exports){ +},{"./formats":158,"./parse":160,"./stringify":161}],160:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); @@ -129701,7 +128003,7 @@ module.exports = function (str, opts) { return utils.compact(obj); }; -},{"./utils":165}],164:[function(require,module,exports){ +},{"./utils":162}],161:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); @@ -129972,7 +128274,7 @@ module.exports = function (object, opts) { return joined.length > 0 ? prefix + joined : ''; }; -},{"./formats":161,"./utils":165}],165:[function(require,module,exports){ +},{"./formats":158,"./utils":162}],162:[function(require,module,exports){ 'use strict'; var has = Object.prototype.hasOwnProperty; @@ -130204,13 +128506,14 @@ module.exports = { merge: merge }; -},{}],166:[function(require,module,exports){ +},{}],163:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, OrderNotFound, PermissionDenied, BadRequest, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -130393,6 +128696,7 @@ module.exports = class stex extends Exchange { 'BITSW': 'BITS', 'BHD': 'Bithold', 'BTH': 'Bithereum', + 'MPH': 'Chasyr Token', 'SBTC': 'SBTCT', // SiamBitcoin }, 'options': { @@ -130456,7 +128760,7 @@ module.exports = class stex extends Exchange { // differentiated fees for each particular method const code = this.safeCurrencyCode (this.safeString (currency, 'code')); const precision = this.safeInteger (currency, 'precision'); - const fee = this.safeFloat (currency, 'withdrawal_fee_const'); // todo: redesign + const fee = this.safeNumber (currency, 'withdrawal_fee_const'); // todo: redesign const active = this.safeValue (currency, 'active', true); result[code] = { 'id': id, @@ -130473,11 +128777,11 @@ module.exports = class stex extends Exchange { 'price': { 'min': Math.pow (10, -precision), 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (currency, 'minimum_deposit_amount'), + 'min': this.safeNumber (currency, 'minimum_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal_amount'), + 'min': this.safeNumber (currency, 'minimum_withdrawal_amount'), 'max': undefined, }, }, @@ -130538,11 +128842,11 @@ module.exports = class stex extends Exchange { 'price': this.safeInteger (market, 'market_precision'), }; const active = this.safeValue (market, 'active'); - const minBuyPrice = this.safeFloat (market, 'min_buy_price'); - const minSellPrice = this.safeFloat (market, 'min_sell_price'); + const minBuyPrice = this.safeNumber (market, 'min_buy_price'); + const minSellPrice = this.safeNumber (market, 'min_sell_price'); const minPrice = Math.max (minBuyPrice, minSellPrice); - const buyFee = this.safeFloat (market, 'buy_fee_percent') / 100; - const sellFee = this.safeFloat (market, 'sell_fee_percent') / 100; + const buyFee = this.safeNumber (market, 'buy_fee_percent') / 100; + const sellFee = this.safeNumber (market, 'sell_fee_percent') / 100; const fee = Math.max (buyFee, sellFee); result.push ({ 'id': id, @@ -130561,7 +128865,7 @@ module.exports = class stex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_order_amount'), + 'min': this.safeNumber (market, 'min_order_amount'), 'max': undefined, }, 'price': { 'min': minPrice, 'max': undefined }, @@ -130725,8 +129029,8 @@ module.exports = class stex extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString2 (ticker, 'id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -130739,11 +129043,11 @@ module.exports = class stex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -130753,20 +129057,12 @@ module.exports = class stex extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volumeQuote'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volumeQuote'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker (params); @@ -130832,11 +129128,11 @@ module.exports = class stex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -130911,12 +129207,11 @@ module.exports = class stex extends Exchange { // const id = this.safeString (trade, 'id'); const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; @@ -131029,11 +129324,11 @@ module.exports = class stex extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'currency_id')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen_balance'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -131092,9 +129387,9 @@ module.exports = class stex extends Exchange { const marketId = this.safeString2 (order, 'currency_pair_id', 'currency_pair_name'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (order, 'timestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'initial_amount'); - const filled = this.safeFloat (order, 'processed_amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'initial_amount'); + const filled = this.safeNumber (order, 'processed_amount'); let remaining = undefined; let cost = undefined; if (filled !== undefined) { @@ -131124,7 +129419,7 @@ module.exports = class stex extends Exchange { 'order': id, }); } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); const result = { 'info': order, 'id': id, @@ -131155,7 +129450,7 @@ module.exports = class stex extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'amount'); + const feeCost = this.safeNumber (fees[i], 'amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -131739,13 +130034,13 @@ module.exports = class stex extends Exchange { code = currency['code']; } const type = ('deposit_status_id' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeStringLower (transaction, 'status')); const timestamp = this.safeTimestamp2 (transaction, 'timestamp', 'created_ts'); const updated = this.safeTimestamp (transaction, 'updated_ts'); const txid = this.safeString (transaction, 'txid'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'fee_currency_id', 'deposit_fee_currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -131981,8 +130276,8 @@ module.exports = class stex extends Exchange { for (let i = 0; i < data.length; i++) { const id = this.safeString (data[i], 'id'); const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (data[i], 'withdrawal_fee_const'); - depositFees[code] = this.safeFloat (data[i], 'deposit_fee_const'); + withdrawFees[code] = this.safeNumber (data[i], 'withdrawal_fee_const'); + depositFees[code] = this.safeNumber (data[i], 'deposit_fee_const'); } return { 'withdraw': withdrawFees, @@ -132011,7 +130306,7 @@ module.exports = class stex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],167:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],164:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -132045,13 +130340,14 @@ module.exports = class surbitcoin extends foxbit { } }; -},{"./foxbit.js":87}],168:[function(require,module,exports){ +},{"./foxbit.js":85}],165:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -132219,8 +130515,8 @@ module.exports = class therock extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const buy_fee = this.safeFloat (market, 'buy_fee'); - const sell_fee = this.safeFloat (market, 'sell_fee'); + const buy_fee = this.safeNumber (market, 'buy_fee'); + const sell_fee = this.safeNumber (market, 'sell_fee'); let taker = Math.max (buy_fee, sell_fee); taker = taker / 100; const maker = taker; @@ -132241,11 +130537,11 @@ module.exports = class therock extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_quantity_offer'), + 'min': this.safeNumber (market, 'minimum_quantity_offer'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'minimum_price_offer'), + 'min': this.safeNumber (market, 'minimum_price_offer'), 'max': undefined, }, 'cost': { @@ -132269,11 +130565,11 @@ module.exports = class therock extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'trading_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'trading_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -132292,27 +130588,27 @@ module.exports = class therock extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'close'), // previous day close, if any + 'previousClose': this.safeNumber (ticker, 'close'), // previous day close, if any 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_traded'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume_traded'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -132387,14 +130683,11 @@ module.exports = class therock extends Exchange { const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; let feeCost = undefined; const transactions = this.safeValue (trade, 'transactions', []); @@ -132404,7 +130697,7 @@ module.exports = class therock extends Exchange { if (feeCost === undefined) { feeCost = 0; } - feeCost = this.sum (feeCost, this.safeFloat (feeTransactions[i], 'price')); + feeCost = this.sum (feeCost, this.safeNumber (feeTransactions[i], 'price')); } if (feeCost !== undefined) { fee = { @@ -132559,7 +130852,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (item, 'price'); + const amount = this.safeNumber (item, 'price'); const timestamp = this.parse8601 (this.safeString (item, 'date')); const status = 'ok'; return { @@ -132791,7 +131084,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'price'); + const amount = this.safeNumber (transaction, 'price'); const timestamp = this.parse8601 (this.safeString (transaction, 'date')); const status = 'ok'; // todo parse tags @@ -132966,15 +131259,15 @@ module.exports = class therock extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'date')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'amount_unfilled'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amount_unfilled'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let trades = this.safeValue (order, 'trades'); let cost = undefined; let average = undefined; @@ -133001,7 +131294,7 @@ module.exports = class therock extends Exchange { cost = 0; } } - const stopPrice = this.safeFloat (order, 'conditional_price'); + const stopPrice = this.safeNumber (order, 'conditional_price'); return { 'id': id, 'clientOrderId': undefined, @@ -133279,13 +131572,14 @@ module.exports = class therock extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],169:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],166:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, OrderNotFound, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -133464,11 +131758,11 @@ module.exports = class tidebit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -133493,15 +131787,15 @@ module.exports = class tidebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'ask': this.safeFloat (ticker, 'sell'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'ask': this.safeNumber (ticker, 'sell'), 'bidVolume': undefined, 'askVolume': undefined, 'vwap': undefined, @@ -133512,7 +131806,7 @@ module.exports = class tidebit extends Exchange { 'percentage': undefined, 'previousClose': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -133546,9 +131840,14 @@ module.exports = class tidebit extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -133593,11 +131892,11 @@ module.exports = class tidebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -133683,18 +131982,12 @@ module.exports = class tidebit extends Exchange { const id = this.safeString (order, 'id'); const type = this.safeString (order, 'ord_type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const filled = this.safeFloat (order, 'executed_volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - let cost = undefined; - if (price !== undefined) { - if (filled !== undefined) { - cost = price * filled; - } - } - const average = this.safeFloat (order, 'avg_price'); - return { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const filled = this.safeNumber (order, 'executed_volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -133711,12 +132004,12 @@ module.exports = class tidebit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': average, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -133824,11 +132117,12 @@ module.exports = class tidebit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],170:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],167:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class tidex extends Exchange { describe () { @@ -133910,6 +132204,7 @@ module.exports = class tidex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.1 / 100, @@ -133954,19 +132249,48 @@ module.exports = class tidex extends Exchange { async fetchCurrencies (params = {}) { const response = await this.webGetCurrency (params); + // + // [ + // { + // "id":2, + // "symbol":"BTC", + // "type":2, + // "name":"Bitcoin", + // "amountPoint":8, + // "depositEnable":true, + // "depositMinAmount":0.0005, + // "withdrawEnable":true, + // "withdrawFee":0.0004, + // "withdrawMinAmount":0.0005, + // "settings":{ + // "Blockchain":"https://blockchair.com/bitcoin/", + // "TxUrl":"https://blockchair.com/bitcoin/transaction/{0}", + // "AddrUrl":"https://blockchair.com/bitcoin/address/{0}", + // "ConfirmationCount":3, + // "NeedMemo":false + // }, + // "visible":true, + // "isDelisted":false + // } + // ] + // const result = {}; for (let i = 0; i < response.length; i++) { const currency = response[i]; const id = this.safeString (currency, 'symbol'); - const precision = currency['amountPoint']; + const precision = this.safeInteger (currency, 'amountPoint'); const code = this.safeCurrencyCode (id); - let active = currency['visible'] === true; - const canWithdraw = currency['withdrawEnable'] === true; - const canDeposit = currency['depositEnable'] === true; + const visible = this.safeValue (currency, 'visible'); + let active = visible === true; + const withdrawEnable = this.safeValue (currency, 'withdrawEnable'); + const depositEnable = this.safeValue (currency, 'depositEnable'); + const canWithdraw = withdrawEnable === true; + const canDeposit = depositEnable === true; if (!canWithdraw || !canDeposit) { active = false; } const name = this.safeString (currency, 'name'); + const fee = this.safeNumber (currency, 'withdrawFee'); result[code] = { 'id': id, 'code': code, @@ -133976,7 +132300,7 @@ module.exports = class tidex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': currency['withdrawFee'], + 'fee': fee, }, 'deposit': { 'active': canDeposit, @@ -133997,11 +132321,11 @@ module.exports = class tidex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawMinAmount'), + 'min': this.safeNumber (currency, 'withdrawMinAmount'), 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'depositMinAmount'), + 'min': this.safeNumber (currency, 'depositMinAmount'), 'max': undefined, }, }, @@ -134011,26 +132335,25 @@ module.exports = class tidex extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615861869, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":3.0, + // "min_amount":0.001, + // "max_amount":1000000.0, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.1, + // }, + // }, + // } + // const markets = response['pairs']; const keys = Object.keys (markets); const result = []; @@ -134047,19 +132370,20 @@ module.exports = class tidex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }, }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -134068,7 +132392,7 @@ module.exports = class tidex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -134089,11 +132413,11 @@ module.exports = class tidex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (funds, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'value'); - account['used'] = this.safeFloat (balance, 'inOrders'); + account['free'] = this.safeString (balance, 'value'); + account['used'] = this.safeString (balance, 'inOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -134165,16 +132489,16 @@ module.exports = class tidex extends Exchange { timestamp = undefined; } } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -134183,9 +132507,9 @@ module.exports = class tidex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -134233,16 +132557,19 @@ module.exports = class tidex extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const orderId = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = 'limit'; // all trades are still limit trades let takerOrMaker = undefined; let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -134261,12 +132588,6 @@ module.exports = class tidex extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': orderId, @@ -134322,17 +132643,18 @@ module.exports = class tidex extends Exchange { let status = 'open'; let filled = 0.0; let remaining = amount; - if ('return' in response) { - id = this.safeString (response['return'], 'order_id'); + const returnResult = this.safeValue (response, 'return'); + if (returnResult !== undefined) { + id = this.safeString (returnResult, 'order_id'); if (id === '0') { - id = this.safeString (response['return'], 'init_order_id'); + id = this.safeString (returnResult, 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (returnResult, 'received', filled); + remaining = this.safeNumber (returnResult, 'remains', amount); } const timestamp = this.milliseconds (); - return { + return this.safeOrder ({ 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -134342,7 +132664,7 @@ module.exports = class tidex extends Exchange { 'type': type, 'side': side, 'price': price, - 'cost': price * filled, + 'cost': undefined, 'amount': amount, 'remaining': remaining, 'filled': filled, @@ -134352,7 +132674,7 @@ module.exports = class tidex extends Exchange { 'clientOrderId': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -134381,23 +132703,15 @@ module.exports = class tidex extends Exchange { const symbol = this.safeSymbol (marketId, market); let remaining = undefined; let amount = undefined; - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; + const price = this.safeNumber (order, 'rate'); if ('start_amount' in order) { - amount = this.safeFloat (order, 'start_amount'); - remaining = this.safeFloat (order, 'amount'); + amount = this.safeNumber (order, 'start_amount'); + remaining = this.safeNumber (order, 'amount'); } else { - remaining = this.safeFloat (order, 'amount'); - } - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } + remaining = this.safeNumber (order, 'amount'); } const fee = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -134411,15 +132725,15 @@ module.exports = class tidex extends Exchange { 'side': this.safeString (order, 'type'), 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -134609,11 +132923,12 @@ module.exports = class tidex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],171:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],168:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, PermissionDenied, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, RateLimitExceeded, NotSupported, BadRequest, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class timex extends Exchange { describe () { @@ -135062,11 +133377,11 @@ module.exports = class timex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'totalBalance'); - account['used'] = this.safeFloat (balance, 'lockedBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + account['used'] = this.safeString (balance, 'lockedBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -135427,7 +133742,7 @@ module.exports = class timex extends Exchange { const result = this.safeValue (response, 0, {}); return { 'info': response, - 'maker': this.safeFloat (result, 'fee'), + 'maker': this.safeNumber (result, 'fee'), 'taker': undefined, }; } @@ -135464,18 +133779,18 @@ module.exports = class timex extends Exchange { 'amount': this.precisionFromString (this.safeString (market, 'quantityIncrement')), 'price': this.precisionFromString (this.safeString (market, 'tickSize')), }; - const amountIncrement = this.safeFloat (market, 'quantityIncrement'); - const minBase = this.safeFloat (market, 'baseMinSize'); + const amountIncrement = this.safeNumber (market, 'quantityIncrement'); + const minBase = this.safeNumber (market, 'baseMinSize'); const minAmount = Math.max (amountIncrement, minBase); - const priceIncrement = this.safeFloat (market, 'tickSize'); - const minCost = this.safeFloat (market, 'quoteMinSize'); + const priceIncrement = this.safeNumber (market, 'tickSize'); + const minCost = this.safeNumber (market, 'quoteMinSize'); const limits = { 'amount': { 'min': minAmount, 'max': undefined }, 'price': { 'min': priceIncrement, 'max': undefined }, 'cost': { 'min': Math.max (minCost, minAmount * priceIncrement), 'max': undefined }, }; - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); return { 'id': id, 'symbol': symbol, @@ -135536,7 +133851,7 @@ module.exports = class timex extends Exchange { const name = this.safeString (currency, 'name'); const precision = this.safeInteger (currency, 'decimals'); const active = this.safeValue (currency, 'active'); - // const fee = this.safeFloat (currency, 'withdrawalFee'); + // const fee = this.safeNumber (currency, 'withdrawalFee'); const feeString = this.safeString (currency, 'withdrawalFee'); const tradeDecimals = this.safeInteger (currency, 'tradeDecimals'); let fee = undefined; @@ -135573,14 +133888,6 @@ module.exports = class timex extends Exchange { }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // // { @@ -135600,8 +133907,8 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '/'); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -135617,11 +133924,11 @@ module.exports = class timex extends Exchange { 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -135631,8 +133938,8 @@ module.exports = class timex extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'volumeQuote'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volumeQuote'), }; } @@ -135651,23 +133958,27 @@ module.exports = class timex extends Exchange { // fetchMyTrades, fetchOrder (private) // // { - // "fee": "0.3", - // "id": 100, - // "makerOrTaker": "MAKER", - // "makerOrderId": "string", - // "price": "0.017", - // "quantity": "0.3", + // "id": "7613414", + // "makerOrderId": "0x8420af060722f560098f786a2894d4358079b6ea5d14b395969ed77bc87a623a", + // "takerOrderId": "0x1235ef158a361815b54c9988b6241c85aedcbc1fe81caf8df8587d5ab0373d1a", + // "symbol": "LTCUSDT", // "side": "BUY", - // "symbol": "TIMEETH", - // "takerOrderId": "string", - // "timestamp": "2019-12-08T04:54:11.171Z" - // } + // "quantity": "0.2", + // "fee": "0.22685", + // "feeToken": "USDT", + // "price": "226.85", + // "makerOrTaker": "TAKER", + // "timestamp": "2021-04-09T15:39:45.608" + // } // const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeStringLower2 (trade, 'direction', 'side'); const takerOrMaker = this.safeStringLower (trade, 'makerOrTaker'); @@ -135676,18 +133987,14 @@ module.exports = class timex extends Exchange { orderId = this.safeString (trade, takerOrMaker + 'OrderId'); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); + const feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'feeToken')); if (feeCost !== undefined) { - const feeCurrency = (market === undefined) ? undefined : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrency, }; } - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = this.costToPrecision (symbol, amount * price); - } return { 'info': trade, 'id': id, @@ -135719,11 +134026,11 @@ module.exports = class timex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -135754,14 +134061,12 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'filledQuantity'); - const canceledQuantity = this.safeFloat (order, 'cancelledQuantity'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'filledQuantity'); + const canceledQuantity = this.safeNumber (order, 'cancelledQuantity'); let status = undefined; if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0.0); if (filled >= amount) { status = 'closed'; } else if ((canceledQuantity !== undefined) && (canceledQuantity > 0)) { @@ -135770,30 +134075,19 @@ module.exports = class timex extends Exchange { status = 'open'; } } - const cost = parseFloat (this.costToPrecision (symbol, price * filled)); - const fee = undefined; - let lastTradeTimestamp = undefined; - let trades = undefined; - const rawTrades = this.safeValue (order, 'trades'); - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'order': id, - }); - } - if (trades !== undefined) { - const numTrades = trades.length; - if (numTrades > 0) { - lastTradeTimestamp = trades[numTrades - 1]['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'order': id, + 'type': type, + }); const clientOrderId = this.safeString (order, 'clientOrderId'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': undefined, @@ -135802,14 +134096,14 @@ module.exports = class timex extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { @@ -135850,13 +134144,14 @@ module.exports = class timex extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],172:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],169:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, PermissionDenied, AddressPending } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -136082,9 +134377,9 @@ module.exports = class upbit extends Exchange { } else if ((locked !== undefined) && locked) { active = false; } - const maxOnetimeWithdrawal = this.safeFloat (withdrawLimits, 'onetime'); - const maxDailyWithdrawal = this.safeFloat (withdrawLimits, 'daily', maxOnetimeWithdrawal); - const remainingDailyWithdrawal = this.safeFloat (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); + const maxOnetimeWithdrawal = this.safeNumber (withdrawLimits, 'onetime'); + const maxDailyWithdrawal = this.safeNumber (withdrawLimits, 'daily', maxOnetimeWithdrawal); + const remainingDailyWithdrawal = this.safeNumber (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); let maxWithdrawLimit = undefined; if (remainingDailyWithdrawal > 0) { maxWithdrawLimit = remainingDailyWithdrawal; @@ -136100,11 +134395,11 @@ module.exports = class upbit extends Exchange { 'code': code, 'name': code, 'active': active, - 'fee': this.safeFloat (currencyInfo, 'withdraw_fee'), + 'fee': this.safeNumber (currencyInfo, 'withdraw_fee'), 'precision': precision, 'limits': { 'withdraw': { - 'min': this.safeFloat (withdrawLimits, 'minimum'), + 'min': this.safeNumber (withdrawLimits, 'minimum'), 'max': maxWithdrawLimit, }, }, @@ -136167,8 +134462,8 @@ module.exports = class upbit extends Exchange { }; const state = this.safeString (marketInfo, 'state'); const active = (state === 'active'); - const bidFee = this.safeFloat (response, 'bid_fee'); - const askFee = this.safeFloat (response, 'ask_fee'); + const bidFee = this.safeNumber (response, 'bid_fee'); + const askFee = this.safeNumber (response, 'ask_fee'); const fee = Math.max (bidFee, askFee); return { 'info': response, @@ -136184,7 +134479,7 @@ module.exports = class upbit extends Exchange { 'taker': fee, 'limits': { 'amount': { - 'min': this.safeFloat (ask, 'min_total'), + 'min': this.safeNumber (ask, 'min_total'), 'max': undefined, }, 'price': { @@ -136192,8 +134487,8 @@ module.exports = class upbit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (bid, 'min_total'), - 'max': this.safeFloat (marketInfo, 'max_total'), + 'min': this.safeNumber (bid, 'min_total'), + 'max': this.safeNumber (marketInfo, 'max_total'), }, }, }; @@ -136232,8 +134527,8 @@ module.exports = class upbit extends Exchange { 'price': 8, }; const active = true; - const makerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); - const takerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); + const makerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); + const takerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); result.push ({ 'id': id, 'symbol': symbol, @@ -136286,11 +134581,11 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { @@ -136393,30 +134688,30 @@ module.exports = class upbit extends Exchange { const timestamp = this.safeInteger (ticker, 'trade_timestamp'); const marketId = this.safeString2 (ticker, 'market', 'code'); const symbol = this.safeSymbol (marketId, market, '-'); - const previous = this.safeFloat (ticker, 'prev_closing_price'); - const last = this.safeFloat (ticker, 'trade_price'); - const change = this.safeFloat (ticker, 'signed_change_price'); - const percentage = this.safeFloat (ticker, 'signed_change_rate'); + const previous = this.safeNumber (ticker, 'prev_closing_price'); + const last = this.safeNumber (ticker, 'trade_price'); + const change = this.safeNumber (ticker, 'signed_change_price'); + const percentage = this.safeNumber (ticker, 'signed_change_rate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price'), - 'low': this.safeFloat (ticker, 'low_price'), + 'high': this.safeNumber (ticker, 'high_price'), + 'low': this.safeNumber (ticker, 'low_price'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'opening_price'), + 'open': this.safeNumber (ticker, 'opening_price'), 'close': last, 'last': last, 'previousClose': previous, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'acc_trade_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'acc_trade_price_24h'), + 'baseVolume': this.safeNumber (ticker, 'acc_trade_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'acc_trade_price_24h'), 'info': ticker, }; } @@ -136523,15 +134818,13 @@ module.exports = class upbit extends Exchange { } else if (askOrBid === 'bid') { side = 'buy'; } - let cost = this.safeFloat (trade, 'funds'); - const price = this.safeFloat2 (trade, 'trade_price', 'price'); - const amount = this.safeFloat2 (trade, 'trade_volume', 'volume'); + let cost = this.safeNumber (trade, 'funds'); + const priceString = this.safeString2 (trade, 'trade_price', 'price'); + const amountString = this.safeString2 (trade, 'trade_volume', 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString2 (trade, 'market', 'code'); market = this.safeMarket (marketId, market); @@ -136626,11 +134919,11 @@ module.exports = class upbit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'candle_date_time_utc')), - this.safeFloat (ohlcv, 'opening_price'), - this.safeFloat (ohlcv, 'high_price'), - this.safeFloat (ohlcv, 'low_price'), - this.safeFloat (ohlcv, 'trade_price'), - this.safeFloat (ohlcv, 'candle_acc_trade_volume'), // base volume + this.safeNumber (ohlcv, 'opening_price'), + this.safeNumber (ohlcv, 'high_price'), + this.safeNumber (ohlcv, 'low_price'), + this.safeNumber (ohlcv, 'trade_price'), + this.safeNumber (ohlcv, 'candle_acc_trade_volume'), // base volume ]; } @@ -136899,7 +135192,7 @@ module.exports = class upbit extends Exchange { // } // const id = this.safeString (transaction, 'uuid'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = undefined; // not present in the data structure received from the exchange const tag = undefined; // not present in the data structure received from the exchange const txid = this.safeString (transaction, 'txid'); @@ -136912,7 +135205,7 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -136997,10 +135290,10 @@ module.exports = class upbit extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const status = this.parseOrderStatus (this.safeString (order, 'state')); let lastTradeTimestamp = undefined; - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - const filled = this.safeFloat (order, 'executed_volume'); + let price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const filled = this.safeNumber (order, 'executed_volume'); let cost = undefined; if (type === 'price') { type = 'market'; @@ -137009,7 +135302,7 @@ module.exports = class upbit extends Exchange { } let average = undefined; let fee = undefined; - let feeCost = this.safeFloat (order, 'paid_fee'); + let feeCost = this.safeNumber (order, 'paid_fee'); const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); let trades = this.safeValue (order, 'trades', []); @@ -137032,7 +135325,7 @@ module.exports = class upbit extends Exchange { cost = this.sum (cost, trade['cost']); if (getFeesFromTrades) { const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); + const tradeFeeCost = this.safeNumber (tradeFee, 'cost'); if (tradeFeeCost !== undefined) { feeCost = this.sum (feeCost, tradeFeeCost); } @@ -137174,16 +135467,6 @@ module.exports = class upbit extends Exchange { return this.parseOrder (response); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetDepositsCoinAddresses (params); @@ -137381,212 +135664,7 @@ module.exports = class upbit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],173:[function(require,module,exports){ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); - -// --------------------------------------------------------------------------- - -module.exports = class vaultoro extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'vaultoro', - 'name': 'Vaultoro', - 'countries': [ 'CH' ], - 'rateLimit': 1000, - 'version': '1', - 'has': { - 'CORS': true, - 'fetchMarkets': true, - 'fetchOrderBook': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'fetchTrades': true, - 'fetchTicker': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg', - 'api': 'https://api.vaultoro.com', - 'www': 'https://www.vaultoro.com', - 'doc': 'https://api.vaultoro.com', - }, - 'commonCurrencies': { - 'GLD': 'Gold', - }, - 'api': { - 'public': { - 'get': [ - 'bidandask', - 'buyorders', - 'latest', - 'latesttrades', - 'markets', - 'orderbook', - 'sellorders', - 'transactions/day', - 'transactions/hour', - 'transactions/month', - ], - }, - 'private': { - 'get': [ - 'balance', - 'mytrades', - 'orders', - ], - 'post': [ - 'buy/{symbol}/{type}', - 'cancel/{id}', - 'sell/{symbol}/{type}', - 'withdraw', - ], - }, - }, - }); - } - - async fetchMarkets (params = {}) { - const result = []; - const response = await this.publicGetMarkets (params); - const market = this.safeValue (response, 'data'); - const baseId = this.safeString (market, 'MarketCurrency'); - const quoteId = this.safeString (market, 'BaseCurrency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const id = this.safeString (market, 'MarketName'); - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'active': undefined, - 'precision': this.precision, - 'limits': this.limits, - }); - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetBalance (params); - const balances = this.safeValue (response, 'data'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency_code'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'cash'); - account['used'] = this.safeFloat (balance, 'reserved'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetOrderbook (params); - const orderbook = { - 'bids': response['data'][0]['b'], - 'asks': response['data'][1]['s'], - }; - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'Gold_Price', 'Gold_Amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'Time')); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const price = this.safeFloat (trade, 'Gold_Price'); - const amount = this.safeFloat (trade, 'Gold_Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } - return { - 'id': undefined, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': undefined, - 'side': undefined, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const response = await this.publicGetTransactionsDay (params); - return this.parseTrades (response, market, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const method = 'privatePost' + this.capitalize (side) + 'SymbolType'; - const request = { - 'symbol': market['quoteId'].toLowerCase (), - 'type': type, - 'gld': amount, - 'price': price || 1, - }; - const response = await this[method] (this.extend (request, params)); - return { - 'info': response, - 'id': response['data']['Order_ID'], - }; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - return await this.privatePostCancelId (this.extend (request, params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/'; - if (api === 'public') { - url += path; - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce (); - url += this.version + '/' + this.implodeParams (path, params); - const query = this.extend ({ - 'nonce': nonce, - 'apikey': this.apiKey, - }, this.omit (params, this.extractParams (path))); - url += '?' + this.urlencode (query); - headers = { - 'Content-Type': 'application/json', - 'X-Signature': this.hmac (this.encode (url), this.encode (this.secret)), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } -}; - -},{"./base/Exchange":6}],174:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],170:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -137620,7 +135698,7 @@ module.exports = class vbtc extends foxbit { } }; -},{"./foxbit.js":87}],175:[function(require,module,exports){ +},{"./foxbit.js":85}],171:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -137628,6 +135706,7 @@ module.exports = class vbtc extends foxbit { const Exchange = require ('./base/Exchange'); const { ExchangeError, OrderNotFound, InvalidOrder, BadRequest, AuthenticationError, RateLimitExceeded, RequestTimeout, BadSymbol, AddressPending, PermissionDenied, InsufficientFunds } = require ('./base/errors'); const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -137819,15 +135898,15 @@ module.exports = class vcc extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, 'min'), + 'min': this.safeNumber (amountLimits, 'min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (priceLimits, 'min'), + 'min': this.safeNumber (priceLimits, 'min'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (costLimits, 'min'), + 'min': this.safeNumber (costLimits, 'min'), 'max': undefined, }, }, @@ -137874,12 +135953,12 @@ module.exports = class vcc extends Exchange { 'code': code, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': this.safeInteger (currency, 'decimal'), 'limits': { 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw'), - 'max': this.safeFloat (currency, 'max_withdraw'), + 'min': this.safeNumber (currency, 'min_withdraw'), + 'max': this.safeNumber (currency, 'max_withdraw'), }, }, }; @@ -137902,8 +135981,8 @@ module.exports = class vcc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } @@ -137929,11 +136008,11 @@ module.exports = class vcc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (data, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -137951,11 +136030,11 @@ module.exports = class vcc extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -138044,10 +136123,10 @@ module.exports = class vcc extends Exchange { // } // const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); - const open = this.safeFloat (ticker, 'open_price'); - const last = this.safeFloat (ticker, 'last_price'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); + const open = this.safeNumber (ticker, 'open_price'); + const last = this.safeNumber (ticker, 'last_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -138064,11 +136143,11 @@ module.exports = class vcc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -138182,17 +136261,17 @@ module.exports = class vcc extends Exchange { } market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'base_volume', 'quantity'); - let cost = this.safeFloat2 (trade, 'quote_volume', 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'base_volume', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber2 (trade, 'quote_volume', 'amount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const side = this.safeString2 (trade, 'type', 'trade_type'); const id = this.safeString2 (trade, 'trade_id', 'id'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -138377,7 +136456,7 @@ module.exports = class vcc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -138385,7 +136464,7 @@ module.exports = class vcc extends Exchange { const txid = this.safeString (transaction, 'transaction_id'); const tag = this.safeString (transaction, 'destination_tag'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -138630,46 +136709,27 @@ module.exports = class vcc extends Exchange { const marketId = baseId + '_' + quoteId; market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'executed_quantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - let cost = this.safeFloat (order, 'ceiling'); + const cost = this.safeNumber (order, 'ceiling'); const id = this.safeString (order, 'id'); - let average = undefined; - let price = this.safeFloat (order, 'price'); - // in case of market order - if (!price) { - price = this.safeFloat (order, 'executed_price'); - average = price; - } - let remaining = this.safeFloat (order, 'remaining'); - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if (filled !== undefined) { - if ((amount !== undefined) && (remaining === undefined)) { - remaining = Math.max (0, amount - filled); - } - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((average === undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'executed_price'); + const remaining = this.safeNumber (order, 'remaining'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'trade_type'); const fee = { 'currency': market['quote'], - 'cost': this.safeFloat (order, 'fee'), - 'rate': this.safeFloat (order, 'fee_rate'), + 'cost': this.safeNumber (order, 'fee'), + 'rate': this.safeNumber (order, 'fee_rate'), }; let lastTradeTimestamp = undefined; if (updated !== created) { lastTradeTimestamp = updated; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': id, 'timestamp': created, @@ -138691,7 +136751,7 @@ module.exports = class vcc extends Exchange { 'fee': fee, 'trades': undefined, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -138961,7 +137021,7 @@ module.exports = class vcc extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8,"./base/functions/number":14}],176:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9,"./base/functions/number":15}],172:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -139529,13 +137589,13 @@ module.exports = class wavesexchange extends Exchange { symbol = market['symbol']; } const data = this.safeValue (ticker, 'data', {}); - const last = this.safeFloat (data, 'lastPrice'); - const low = this.safeFloat (data, 'low'); - const high = this.safeFloat (data, 'high'); - const vwap = this.safeFloat (data, 'weightedAveragePrice'); - const baseVolume = this.safeFloat (data, 'volume'); - const quoteVolume = this.safeFloat (data, 'quoteVolume'); - const open = this.safeValue (data, 'firstPrice'); + const last = this.safeNumber (data, 'lastPrice'); + const low = this.safeNumber (data, 'low'); + const high = this.safeNumber (data, 'high'); + const vwap = this.safeNumber (data, 'weightedAveragePrice'); + const baseVolume = this.safeNumber (data, 'volume'); + const quoteVolume = this.safeNumber (data, 'quoteVolume'); + const open = this.safeNumber (data, 'firstPrice'); let change = undefined; let average = undefined; let percentage = undefined; @@ -139689,11 +137749,11 @@ module.exports = class wavesexchange extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.parse8601 (this.safeString (data, 'time')), - this.safeFloat (data, 'open'), - this.safeFloat (data, 'high'), - this.safeFloat (data, 'low'), - this.safeFloat (data, 'close'), - this.safeFloat (data, 'volume', 0), + this.safeNumber (data, 'open'), + this.safeNumber (data, 'high'), + this.safeNumber (data, 'low'), + this.safeNumber (data, 'close'), + this.safeNumber (data, 'volume', 0), ]; } @@ -139908,7 +137968,7 @@ module.exports = class wavesexchange extends Exchange { } if (matcherFee === undefined) { const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8); - const rate = this.safeFloat (rates, matcherFeeAssetId); + const rate = this.safeNumber (rates, matcherFeeAssetId); const code = this.safeCurrencyCode (matcherFeeAssetId); const currency = this.currency (code); const newPrecison = Math.pow (10, wavesPrecision - currency['precision']); @@ -140318,7 +138378,7 @@ module.exports = class wavesexchange extends Exchange { const issueTransaction = this.safeValue (entry, 'issueTransaction'); const decimals = this.safeInteger (issueTransaction, 'decimals'); const currencyId = this.safeString (entry, 'assetId'); - const balance = this.safeFloat (entry, 'balance'); + const balance = this.safeNumber (entry, 'balance'); let code = undefined; if (currencyId in this.currencies_by_id) { code = this.safeCurrencyCode (currencyId); @@ -140348,7 +138408,7 @@ module.exports = class wavesexchange extends Exchange { if (!(code in result)) { result[code] = this.account (); } - const amount = this.safeFloat (reservedBalance, currencyId); + const amount = this.safeNumber (reservedBalance, currencyId); result[code]['used'] = this.currencyFromPrecision (code, amount); } const wavesRequest = { @@ -140361,7 +138421,7 @@ module.exports = class wavesexchange extends Exchange { // "balance": 909085978 // } result['WAVES'] = this.safeValue (result, 'WAVES', {}); - result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeFloat (wavesTotal, 'balance')); + result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeNumber (wavesTotal, 'balance')); const codes = Object.keys (result); for (let i = 0; i < codes.length; i++) { const code = codes[i]; @@ -140453,8 +138513,8 @@ module.exports = class wavesexchange extends Exchange { const datetime = this.safeString (data, 'timestamp'); const timestamp = this.parse8601 (datetime); const id = this.safeString (data, 'id'); - const price = this.safeFloat (data, 'price'); - const amount = this.safeFloat (data, 'amount'); + const price = this.safeNumber (data, 'price'); + const amount = this.safeNumber (data, 'amount'); const order1 = this.safeValue (data, 'order1'); const order2 = this.safeValue (data, 'order2'); let order = undefined; @@ -140478,7 +138538,7 @@ module.exports = class wavesexchange extends Exchange { cost = price * amount; } const fee = { - 'cost': this.safeFloat (data, 'fee'), + 'cost': this.safeNumber (data, 'fee'), 'currency': this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES')), }; return { @@ -140560,7 +138620,7 @@ module.exports = class wavesexchange extends Exchange { const withdrawAddress = await this.privateGetWithdrawAddressesCurrencyAddress (withdrawAddressRequest); const currency = this.safeValue (withdrawAddress, 'currency'); const allowedAmount = this.safeValue (currency, 'allowed_amount'); - const minimum = this.safeFloat (allowedAmount, 'min'); + const minimum = this.safeNumber (allowedAmount, 'min'); if (amount <= minimum) { throw new BadRequest (this.id + ' ' + code + ' withdraw failed, amount ' + amount.toString () + ' must be greater than the minimum allowed amount of ' + minimum.toString ()); } @@ -140630,13 +138690,14 @@ module.exports = class wavesexchange extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],177:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],173:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeNotAvailable, ExchangeError, DDoSProtection, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -140797,7 +138858,7 @@ module.exports = class whitebit extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -140805,7 +138866,7 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minTotal'), + 'min': this.safeNumber (market, 'minTotal'), 'max': undefined, }, }, @@ -140870,8 +138931,8 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -140883,8 +138944,8 @@ module.exports = class whitebit extends Exchange { const response = await this.publicV2GetFee (params); const fees = this.safeValue (response, 'result'); return { - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), }; } @@ -140954,8 +139015,8 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let change = undefined; if (percentage !== undefined) { change = this.numberToString (percentage * 0.01); @@ -140964,22 +139025,22 @@ module.exports = class whitebit extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'deal'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'deal'), 'info': ticker, }; } @@ -141147,8 +139208,11 @@ module.exports = class whitebit extends Exchange { } else { timestamp = parseInt (timestamp * 1000); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'volume'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'volume'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const id = this.safeString2 (trade, 'id', 'tradeId'); let side = this.safeString (trade, 'type'); if (side === undefined) { @@ -141159,10 +139223,6 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined && price !== undefined) { - cost = amount * price; - } return { 'info': trade, 'timestamp': timestamp, @@ -141232,11 +139292,11 @@ module.exports = class whitebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -141285,7 +139345,7 @@ module.exports = class whitebit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],178:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],174:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- @@ -141440,14 +139500,13 @@ module.exports = class xbtce extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'FreeAmount'), - 'used': this.safeFloat (balance, 'LockedAmount'), - 'total': this.safeFloat (balance, 'Amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'FreeAmount'); + account['used'] = this.safeString (balance, 'LockedAmount'); + account['total'] = this.safeString (balance, 'Amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -141559,11 +139618,11 @@ module.exports = class xbtce extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeInteger (ohlcv, 'Timestamp'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -141657,11 +139716,12 @@ module.exports = class xbtce extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],179:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/errors":9}],175:[function(require,module,exports){ 'use strict'; const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, InsufficientFunds, InvalidAddress, BadSymbol, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class xena extends Exchange { describe () { @@ -141937,8 +139997,8 @@ module.exports = class xena extends Exchange { 'price': pricePrecision, 'amount': 0, }; - const maxCost = this.safeFloat (market, 'maxOrderQty'); - const minCost = this.safeFloat (market, 'minOrderQuantity'); + const maxCost = this.safeNumber (market, 'maxOrderQty'); + const minCost = this.safeNumber (market, 'minOrderQuantity'); const limits = { 'amount': { 'min': undefined, @@ -142023,7 +140083,7 @@ module.exports = class xena extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (withdraw, 'commission'), + 'fee': this.safeNumber (withdraw, 'commission'), 'precision': precision, 'limits': { 'amount': { @@ -142039,7 +140099,7 @@ module.exports = class xena extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'minAmount'), + 'min': this.safeNumber (withdraw, 'minAmount'), 'max': undefined, }, }, @@ -142067,8 +140127,8 @@ module.exports = class xena extends Exchange { const timestamp = this.milliseconds (); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPx'); - const open = this.safeFloat (ticker, 'firstPx'); + const last = this.safeNumber (ticker, 'lastPx'); + const open = this.safeNumber (ticker, 'firstPx'); let percentage = undefined; let change = undefined; let average = undefined; @@ -142079,18 +140139,18 @@ module.exports = class xena extends Exchange { percentage = change / open * 100; } } - const buyVolume = this.safeFloat (ticker, 'buyVolume'); - const sellVolume = this.safeFloat (ticker, 'sellVolume'); + const buyVolume = this.safeNumber (ticker, 'buyVolume'); + const sellVolume = this.safeNumber (ticker, 'sellVolume'); const baseVolume = this.sum (buyVolume, sellVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPx'), - 'low': this.safeFloat (ticker, 'lowPx'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'highPx'), + 'low': this.safeNumber (ticker, 'lowPx'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -142267,11 +140327,11 @@ module.exports = class xena extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onHold'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onHold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTrade (trade, market = undefined) { @@ -142325,20 +140385,17 @@ module.exports = class xena extends Exchange { const orderId = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat2 (trade, 'lastPx', 'mdEntryPx'); - const amount = this.safeFloat2 (trade, 'lastQty', 'mdEntrySize'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'lastPx', 'mdEntryPx'); + const amountString = this.safeString2 (trade, 'lastQty', 'mdEntrySize'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (trade, 'commRate'); + const feeRate = this.safeNumber (trade, 'commRate'); fee = { 'cost': feeCost, 'rate': feeRate, @@ -142453,15 +140510,15 @@ module.exports = class xena extends Exchange { // const transactTime = this.safeInteger (ohlcv, 'transactTime'); const timestamp = parseInt (transactTime / 1000000); - const buyVolume = this.safeFloat (ohlcv, 'buyVolume'); - const sellVolume = this.safeFloat (ohlcv, 'sellVolume'); + const buyVolume = this.safeNumber (ohlcv, 'buyVolume'); + const sellVolume = this.safeNumber (ohlcv, 'sellVolume'); const volume = this.sum (buyVolume, sellVolume); return [ timestamp, - this.safeFloat (ohlcv, 'firstPx'), - this.safeFloat (ohlcv, 'highPx'), - this.safeFloat (ohlcv, 'lowPx'), - this.safeFloat (ohlcv, 'lastPx'), + this.safeNumber (ohlcv, 'firstPx'), + this.safeNumber (ohlcv, 'highPx'), + this.safeNumber (ohlcv, 'lowPx'), + this.safeNumber (ohlcv, 'lastPx'), volume, ]; } @@ -142586,11 +140643,10 @@ module.exports = class xena extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); - let cost = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); let side = this.safeStringLower (order, 'side'); if (side === '1') { side = 'buy'; @@ -142607,12 +140663,7 @@ module.exports = class xena extends Exchange { } else if (type === '4') { type = 'stop-limit'; } - if (cost === undefined) { - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -142627,14 +140678,14 @@ module.exports = class xena extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -142687,7 +140738,7 @@ module.exports = class xena extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if ((type === 'stop') || (type === 'stop-limit')) { - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPx param for order type ' + type); } @@ -142766,12 +140817,12 @@ module.exports = class xena extends Exchange { if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); } - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx !== undefined) { request['stopPx'] = this.priceToPrecision (symbol, stopPx); params = this.omit (params, 'stopPx'); } - const capPrice = this.safeFloat (params, 'capPrice'); + const capPrice = this.safeNumber (params, 'capPrice'); if (capPrice !== undefined) { request['capPrice'] = this.priceToPrecision (symbol, capPrice); params = this.omit (params, 'capPrice'); @@ -143126,7 +141177,7 @@ module.exports = class xena extends Exchange { const address = this.safeString (transaction, 'address'); const addressFrom = undefined; const addressTo = address; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const fee = undefined; return { @@ -143223,7 +141274,7 @@ module.exports = class xena extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'kind')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); @@ -143235,11 +141286,11 @@ module.exports = class xena extends Exchange { timestamp = parseInt (timestamp / 1000000); } const fee = { - 'cost': this.safeFloat (item, 'commission'), + 'cost': this.safeNumber (item, 'commission'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -143379,13 +141430,14 @@ module.exports = class xena extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],180:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],176:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError, RateLimitExceeded } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -143520,6 +141572,7 @@ module.exports = class yobit extends Exchange { 'NAV': 'NavajoCoin', 'NBT': 'NiceBytes', 'OMG': 'OMGame', + 'ONX': 'Onix', 'PAC': '$PAC', 'PLAY': 'PlayCoin', 'PIVX': 'Darknet', @@ -143618,15 +141671,33 @@ module.exports = class yobit extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['total'] = this.safeFloat (total, currencyId); + account['free'] = this.safeString (free, currencyId); + account['total'] = this.safeString (total, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615856752, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":10000, + // "min_amount":0.0001, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.2, + // "fee_buyer":0.2, + // "fee_seller":0.2 + // }, + // }, + // } + // const markets = this.safeValue (response, 'pairs'); const keys = Object.keys (markets); const result = []; @@ -143644,15 +141715,15 @@ module.exports = class yobit extends Exchange { 'price': this.safeInteger (market, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }; const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }; const costLimits = { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }; const limits = { 'amount': amountLimits, @@ -143661,6 +141732,7 @@ module.exports = class yobit extends Exchange { }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -143669,7 +141741,7 @@ module.exports = class yobit extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -143745,16 +141817,16 @@ module.exports = class yobit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -143763,9 +141835,9 @@ module.exports = class yobit extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -143814,15 +141886,18 @@ module.exports = class yobit extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const order = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const type = 'limit'; // all trades are still limit trades let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -143837,12 +141912,6 @@ module.exports = class yobit extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, 'taker'); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': order, @@ -143904,8 +141973,8 @@ module.exports = class yobit extends Exchange { id = this.safeString (response['return'], 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (response['return'], 'received', 0.0); + remaining = this.safeNumber (response['return'], 'remains', amount); } const timestamp = this.milliseconds (); return { @@ -143955,21 +142024,13 @@ module.exports = class yobit extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp_created'); const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const remaining = this.safeFloat (order, 'amount'); - const amount = this.safeFloat (order, 'start_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - cost = price * filled; - } - } + const remaining = this.safeNumber (order, 'amount'); + const amount = this.safeNumber (order, 'start_amount'); + const price = this.safeNumber (order, 'rate'); const fee = undefined; const type = 'limit'; const side = this.safeString (order, 'type'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -143983,16 +142044,15 @@ module.exports = class yobit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -144203,13 +142263,14 @@ module.exports = class yobit extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],181:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],177:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -144333,6 +142394,27 @@ module.exports = class zaif extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetCurrencyPairsAll (params); + // + // [ + // { + // "aux_unit_point": 0, + // "item_japanese": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3", + // "aux_unit_step": 5.0, + // "description": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3\u30fb\u65e5\u672c\u5186\u306e\u53d6\u5f15\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059", + // "item_unit_min": 0.001, + // "event_number": 0, + // "currency_pair": "btc_jpy", + // "is_token": false, + // "aux_unit_min": 5.0, + // "aux_japanese": "\u65e5\u672c\u5186", + // "id": 1, + // "item_unit_step": 0.0001, + // "name": "BTC/JPY", + // "seq": 0, + // "title": "BTC/JPY" + // } + // ] + // const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -144343,8 +142425,8 @@ module.exports = class zaif extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': -Math.log10 (market['item_unit_step']), - 'price': market['aux_unit_point'], + 'amount': -Math.log10 (this.safeNumber (market, 'item_unit_step')), + 'price': this.safeInteger (market, 'aux_unit_point'), }; const fees = this.safeValue (this.options['fees'], symbol, this.fees['trading']); const taker = fees['taker']; @@ -144362,11 +142444,11 @@ module.exports = class zaif extends Exchange { 'maker': maker, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'item_unit_min'), + 'min': this.safeNumber (market, 'item_unit_min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'aux_unit_min'), + 'min': this.safeNumber (market, 'aux_unit_min'), 'max': undefined, }, 'cost': { @@ -144398,7 +142480,7 @@ module.exports = class zaif extends Exchange { }; if ('deposit' in balances) { if (currencyId in balances['deposit']) { - account['total'] = this.safeFloat (balances['deposit'], currencyId); + account['total'] = this.safeNumber (balances['deposit'], currencyId); account['used'] = account['total'] - account['free']; } } @@ -144423,22 +142505,22 @@ module.exports = class zaif extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.milliseconds (); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -144459,14 +142541,11 @@ module.exports = class zaif extends Exchange { side = (side === 'bid') ? 'buy' : 'sell'; const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString2 (trade, 'id', 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); return { @@ -144544,16 +142623,10 @@ module.exports = class zaif extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp'); const marketId = this.safeString (order, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -144567,7 +142640,7 @@ module.exports = class zaif extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': undefined, 'remaining': undefined, @@ -144575,7 +142648,7 @@ module.exports = class zaif extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -144694,13 +142767,14 @@ module.exports = class zaif extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],182:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],178:[function(require,module,exports){ 'use strict'; // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); const { BadRequest, ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, OrderNotFound, ExchangeNotAvailable, DDoSProtection, InvalidOrder, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -144786,8 +142860,8 @@ module.exports = class zb extends Exchange { 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg', 'api': { - 'public': 'http://api.zb.cn/data', // no https for public API - 'private': 'https://trade.zb.cn/api', + 'public': 'https://api.zb.today/data', + 'private': 'https://trade.zb.today/api', }, 'www': 'https://www.zb.com', 'doc': 'https://www.zb.com/i/developer', @@ -144902,6 +142976,16 @@ module.exports = class zb extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetMarkets (params); + // + // { + // "zb_qc":{ + // "amountScale":2, + // "minAmount":0.01, + // "minSize":5, + // "priceScale":4, + // }, + // } + // const keys = Object.keys (markets); const result = []; for (let i = 0; i < keys.length; i++) { @@ -144965,11 +143049,11 @@ module.exports = class zb extends Exchange { const account = this.account (); const currencyId = this.safeString (balance, 'key'); const code = this.safeCurrencyCode (currencyId); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'freez'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'freez'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -145018,18 +143102,6 @@ module.exports = class zb extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetGetPayinAddress (params); @@ -145136,16 +143208,16 @@ module.exports = class zb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -145155,12 +143227,23 @@ module.exports = class zb extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; } + parseOHLCV (ohlcv, market = undefined) { + return [ + this.safeInteger (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + ]; + } + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -145185,14 +143268,12 @@ module.exports = class zb extends Exchange { let side = this.safeString (trade, 'trade_type'); side = (side === 'bid') ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const costString = Precise.stringMul (priceString, amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (costString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -145371,23 +143452,13 @@ module.exports = class zb extends Exchange { const timestamp = this.safeInteger (order, 'trade_date'); const marketId = this.safeString (order, 'currency'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'trade_amount'); - const amount = this.safeFloat (order, 'total_amount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'trade_money'); - let average = undefined; + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'trade_amount'); + const amount = this.safeNumber (order, 'total_amount'); + const cost = this.safeNumber (order, 'trade_money'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((cost !== undefined) && (filled !== undefined) && (filled > 0)) { - average = cost / filled; - } const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fees'); + const feeCost = this.safeNumber (order, 'fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -145402,7 +143473,7 @@ module.exports = class zb extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -145416,15 +143487,15 @@ module.exports = class zb extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -145487,7 +143558,7 @@ module.exports = class zb extends Exchange { // const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'hash'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let timestamp = this.parse8601 (this.safeString (transaction, 'submit_time')); timestamp = this.safeInteger (transaction, 'submitTime', timestamp); let address = this.safeString2 (transaction, 'toAddress', 'address'); @@ -145507,7 +143578,7 @@ module.exports = class zb extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -145540,7 +143611,7 @@ module.exports = class zb extends Exchange { if (password === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires exchange.password or a safePwd parameter'); } - const fees = this.safeFloat (params, 'fees'); + const fees = this.safeNumber (params, 'fees'); if (fees === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires a fees parameter'); } @@ -145731,7 +143802,7 @@ module.exports = class zb extends Exchange { } }; -},{"./base/Exchange":6,"./base/errors":8}],183:[function(require,module,exports){ +},{"./base/Exchange":6,"./base/Precise":7,"./base/errors":9}],179:[function(require,module,exports){ (function (global){ 'use strict'; @@ -146225,7 +144296,7 @@ var objectKeys = Object.keys || function (obj) { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"util/":241}],184:[function(require,module,exports){ +},{"util/":237}],180:[function(require,module,exports){ 'use strict' exports.byteLength = byteLength @@ -146341,9 +144412,9 @@ function fromByteArray (uint8) { return parts.join('') } -},{}],185:[function(require,module,exports){ +},{}],181:[function(require,module,exports){ -},{}],186:[function(require,module,exports){ +},{}],182:[function(require,module,exports){ (function (process,Buffer){ 'use strict'; /* eslint camelcase: "off" */ @@ -146755,7 +144826,7 @@ Zlib.prototype._reset = function () { exports.Zlib = Zlib; }).call(this,require('_process'),require("buffer").Buffer) -},{"_process":210,"assert":183,"buffer":188,"pako/lib/zlib/constants":200,"pako/lib/zlib/deflate.js":202,"pako/lib/zlib/inflate.js":204,"pako/lib/zlib/zstream":208}],187:[function(require,module,exports){ +},{"_process":206,"assert":179,"buffer":184,"pako/lib/zlib/constants":196,"pako/lib/zlib/deflate.js":198,"pako/lib/zlib/inflate.js":200,"pako/lib/zlib/zstream":204}],183:[function(require,module,exports){ (function (process){ 'use strict'; @@ -147367,7 +145438,7 @@ util.inherits(DeflateRaw, Zlib); util.inherits(InflateRaw, Zlib); util.inherits(Unzip, Zlib); }).call(this,require('_process')) -},{"./binding":186,"_process":210,"assert":183,"buffer":188,"stream":229,"util":241}],188:[function(require,module,exports){ +},{"./binding":182,"_process":206,"assert":179,"buffer":184,"stream":225,"util":237}],184:[function(require,module,exports){ /*! * The buffer module from node.js, for the browser. * @@ -149083,7 +147154,7 @@ function numberIsNaN (obj) { return obj !== obj // eslint-disable-line no-self-compare } -},{"base64-js":184,"ieee754":194}],189:[function(require,module,exports){ +},{"base64-js":180,"ieee754":190}],185:[function(require,module,exports){ module.exports = { "100": "Continue", "101": "Switching Protocols", @@ -149149,7 +147220,7 @@ module.exports = { "511": "Network Authentication Required" } -},{}],190:[function(require,module,exports){ +},{}],186:[function(require,module,exports){ module.exports={ "O_RDONLY": 0, "O_WRONLY": 1, @@ -149360,7 +147431,7 @@ module.exports={ "UV_UDP_REUSEADDR": 4 } -},{}],191:[function(require,module,exports){ +},{}],187:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -149471,7 +147542,7 @@ function objectToString(o) { } }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) -},{"../../is-buffer/index.js":196}],192:[function(require,module,exports){ +},{"../../is-buffer/index.js":192}],188:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -149775,7 +147846,7 @@ function isUndefined(arg) { return arg === void 0; } -},{}],193:[function(require,module,exports){ +},{}],189:[function(require,module,exports){ var http = require('http') var url = require('url') @@ -149808,7 +147879,7 @@ function validateParams (params) { return params } -},{"http":230,"url":236}],194:[function(require,module,exports){ +},{"http":226,"url":232}],190:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = nBytes * 8 - mLen - 1 @@ -149894,7 +147965,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],195:[function(require,module,exports){ +},{}],191:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -149919,7 +147990,7 @@ if (typeof Object.create === 'function') { } } -},{}],196:[function(require,module,exports){ +},{}],192:[function(require,module,exports){ /*! * Determine if an object is a Buffer * @@ -149942,14 +148013,14 @@ function isSlowBuffer (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) } -},{}],197:[function(require,module,exports){ +},{}],193:[function(require,module,exports){ var toString = {}.toString; module.exports = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; -},{}],198:[function(require,module,exports){ +},{}],194:[function(require,module,exports){ 'use strict'; @@ -150056,7 +148127,7 @@ exports.setTyped = function (on) { exports.setTyped(TYPED_OK); -},{}],199:[function(require,module,exports){ +},{}],195:[function(require,module,exports){ 'use strict'; // Note: adler32 takes 12% for level 0 and 2% for level 6. @@ -150109,7 +148180,7 @@ function adler32(adler, buf, len, pos) { module.exports = adler32; -},{}],200:[function(require,module,exports){ +},{}],196:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -150179,7 +148250,7 @@ module.exports = { //Z_NULL: null // Use -1 or null inline, depending on var type }; -},{}],201:[function(require,module,exports){ +},{}],197:[function(require,module,exports){ 'use strict'; // Note: we can't get significant speed boost here. @@ -150240,7 +148311,7 @@ function crc32(crc, buf, len, pos) { module.exports = crc32; -},{}],202:[function(require,module,exports){ +},{}],198:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -152116,7 +150187,7 @@ exports.deflatePrime = deflatePrime; exports.deflateTune = deflateTune; */ -},{"../utils/common":198,"./adler32":199,"./crc32":201,"./messages":206,"./trees":207}],203:[function(require,module,exports){ +},{"../utils/common":194,"./adler32":195,"./crc32":197,"./messages":202,"./trees":203}],199:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -152463,7 +150534,7 @@ module.exports = function inflate_fast(strm, start) { return; }; -},{}],204:[function(require,module,exports){ +},{}],200:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154021,7 +152092,7 @@ exports.inflateSyncPoint = inflateSyncPoint; exports.inflateUndermine = inflateUndermine; */ -},{"../utils/common":198,"./adler32":199,"./crc32":201,"./inffast":203,"./inftrees":205}],205:[function(require,module,exports){ +},{"../utils/common":194,"./adler32":195,"./crc32":197,"./inffast":199,"./inftrees":201}],201:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154366,7 +152437,7 @@ module.exports = function inflate_table(type, lens, lens_index, codes, table, ta return 0; }; -},{"../utils/common":198}],206:[function(require,module,exports){ +},{"../utils/common":194}],202:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -154400,7 +152471,7 @@ module.exports = { '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ }; -},{}],207:[function(require,module,exports){ +},{}],203:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -155622,7 +153693,7 @@ exports._tr_flush_block = _tr_flush_block; exports._tr_tally = _tr_tally; exports._tr_align = _tr_align; -},{"../utils/common":198}],208:[function(require,module,exports){ +},{"../utils/common":194}],204:[function(require,module,exports){ 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler @@ -155671,7 +153742,7 @@ function ZStream() { module.exports = ZStream; -},{}],209:[function(require,module,exports){ +},{}],205:[function(require,module,exports){ (function (process){ 'use strict'; @@ -155718,7 +153789,7 @@ function nextTick(fn, arg1, arg2, arg3) { } }).call(this,require('_process')) -},{"_process":210}],210:[function(require,module,exports){ +},{"_process":206}],206:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -155904,7 +153975,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],211:[function(require,module,exports){ +},{}],207:[function(require,module,exports){ (function (global){ /*! https://mths.be/punycode v1.4.1 by @mathias */ ;(function(root) { @@ -156441,7 +154512,7 @@ process.umask = function() { return 0; }; }(this)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],212:[function(require,module,exports){ +},{}],208:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156527,7 +154598,7 @@ var isArray = Array.isArray || function (xs) { return Object.prototype.toString.call(xs) === '[object Array]'; }; -},{}],213:[function(require,module,exports){ +},{}],209:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156614,16 +154685,16 @@ var objectKeys = Object.keys || function (obj) { return res; }; -},{}],214:[function(require,module,exports){ +},{}],210:[function(require,module,exports){ 'use strict'; exports.decode = exports.parse = require('./decode'); exports.encode = exports.stringify = require('./encode'); -},{"./decode":212,"./encode":213}],215:[function(require,module,exports){ +},{"./decode":208,"./encode":209}],211:[function(require,module,exports){ module.exports = require('./lib/_stream_duplex.js'); -},{"./lib/_stream_duplex.js":216}],216:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":212}],212:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156748,7 +154819,7 @@ function forEach(xs, f) { f(xs[i], i); } } -},{"./_stream_readable":218,"./_stream_writable":220,"core-util-is":191,"inherits":195,"process-nextick-args":209}],217:[function(require,module,exports){ +},{"./_stream_readable":214,"./_stream_writable":216,"core-util-is":187,"inherits":191,"process-nextick-args":205}],213:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -156796,7 +154867,7 @@ function PassThrough(options) { PassThrough.prototype._transform = function (chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":219,"core-util-is":191,"inherits":195}],218:[function(require,module,exports){ +},{"./_stream_transform":215,"core-util-is":187,"inherits":191}],214:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -157806,7 +155877,7 @@ function indexOf(xs, x) { return -1; } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":216,"./internal/streams/BufferList":221,"./internal/streams/destroy":222,"./internal/streams/stream":223,"_process":210,"core-util-is":191,"events":192,"inherits":195,"isarray":197,"process-nextick-args":209,"safe-buffer":228,"string_decoder/":234,"util":185}],219:[function(require,module,exports){ +},{"./_stream_duplex":212,"./internal/streams/BufferList":217,"./internal/streams/destroy":218,"./internal/streams/stream":219,"_process":206,"core-util-is":187,"events":188,"inherits":191,"isarray":193,"process-nextick-args":205,"safe-buffer":224,"string_decoder/":230,"util":181}],215:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -158021,7 +156092,7 @@ function done(stream, er, data) { return stream.push(null); } -},{"./_stream_duplex":216,"core-util-is":191,"inherits":195}],220:[function(require,module,exports){ +},{"./_stream_duplex":212,"core-util-is":187,"inherits":191}],216:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -158688,7 +156759,7 @@ Writable.prototype._destroy = function (err, cb) { cb(err); }; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":216,"./internal/streams/destroy":222,"./internal/streams/stream":223,"_process":210,"core-util-is":191,"inherits":195,"process-nextick-args":209,"safe-buffer":228,"util-deprecate":238}],221:[function(require,module,exports){ +},{"./_stream_duplex":212,"./internal/streams/destroy":218,"./internal/streams/stream":219,"_process":206,"core-util-is":187,"inherits":191,"process-nextick-args":205,"safe-buffer":224,"util-deprecate":234}],217:[function(require,module,exports){ 'use strict'; /**/ @@ -158763,7 +156834,7 @@ module.exports = function () { return BufferList; }(); -},{"safe-buffer":228}],222:[function(require,module,exports){ +},{"safe-buffer":224}],218:[function(require,module,exports){ 'use strict'; /**/ @@ -158836,13 +156907,13 @@ module.exports = { destroy: destroy, undestroy: undestroy }; -},{"process-nextick-args":209}],223:[function(require,module,exports){ +},{"process-nextick-args":205}],219:[function(require,module,exports){ module.exports = require('events').EventEmitter; -},{"events":192}],224:[function(require,module,exports){ +},{"events":188}],220:[function(require,module,exports){ module.exports = require('./readable').PassThrough -},{"./readable":225}],225:[function(require,module,exports){ +},{"./readable":221}],221:[function(require,module,exports){ exports = module.exports = require('./lib/_stream_readable.js'); exports.Stream = exports; exports.Readable = exports; @@ -158851,13 +156922,13 @@ exports.Duplex = require('./lib/_stream_duplex.js'); exports.Transform = require('./lib/_stream_transform.js'); exports.PassThrough = require('./lib/_stream_passthrough.js'); -},{"./lib/_stream_duplex.js":216,"./lib/_stream_passthrough.js":217,"./lib/_stream_readable.js":218,"./lib/_stream_transform.js":219,"./lib/_stream_writable.js":220}],226:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":212,"./lib/_stream_passthrough.js":213,"./lib/_stream_readable.js":214,"./lib/_stream_transform.js":215,"./lib/_stream_writable.js":216}],222:[function(require,module,exports){ module.exports = require('./readable').Transform -},{"./readable":225}],227:[function(require,module,exports){ +},{"./readable":221}],223:[function(require,module,exports){ module.exports = require('./lib/_stream_writable.js'); -},{"./lib/_stream_writable.js":220}],228:[function(require,module,exports){ +},{"./lib/_stream_writable.js":216}],224:[function(require,module,exports){ /* eslint-disable node/no-deprecated-api */ var buffer = require('buffer') var Buffer = buffer.Buffer @@ -158921,7 +156992,7 @@ SafeBuffer.allocUnsafeSlow = function (size) { return buffer.SlowBuffer(size) } -},{"buffer":188}],229:[function(require,module,exports){ +},{"buffer":184}],225:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -159050,7 +157121,7 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"events":192,"inherits":195,"readable-stream/duplex.js":215,"readable-stream/passthrough.js":224,"readable-stream/readable.js":225,"readable-stream/transform.js":226,"readable-stream/writable.js":227}],230:[function(require,module,exports){ +},{"events":188,"inherits":191,"readable-stream/duplex.js":211,"readable-stream/passthrough.js":220,"readable-stream/readable.js":221,"readable-stream/transform.js":222,"readable-stream/writable.js":223}],226:[function(require,module,exports){ (function (global){ var ClientRequest = require('./lib/request') var extend = require('xtend') @@ -159132,7 +157203,7 @@ http.METHODS = [ 'UNSUBSCRIBE' ] }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./lib/request":232,"builtin-status-codes":189,"url":236,"xtend":242}],231:[function(require,module,exports){ +},{"./lib/request":228,"builtin-status-codes":185,"url":232,"xtend":238}],227:[function(require,module,exports){ (function (global){ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) @@ -159205,7 +157276,7 @@ function isFunction (value) { xhr = null // Help gc }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],232:[function(require,module,exports){ +},{}],228:[function(require,module,exports){ (function (process,global,Buffer){ var capability = require('./capability') var inherits = require('inherits') @@ -159515,7 +157586,7 @@ var unsafeHeaders = [ ] }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"./capability":231,"./response":233,"_process":210,"buffer":188,"inherits":195,"readable-stream":225,"to-arraybuffer":235}],233:[function(require,module,exports){ +},{"./capability":227,"./response":229,"_process":206,"buffer":184,"inherits":191,"readable-stream":221,"to-arraybuffer":231}],229:[function(require,module,exports){ (function (process,global,Buffer){ var capability = require('./capability') var inherits = require('inherits') @@ -159701,7 +157772,7 @@ IncomingMessage.prototype._onXHRProgress = function () { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) -},{"./capability":231,"_process":210,"buffer":188,"inherits":195,"readable-stream":225}],234:[function(require,module,exports){ +},{"./capability":227,"_process":206,"buffer":184,"inherits":191,"readable-stream":221}],230:[function(require,module,exports){ 'use strict'; var Buffer = require('safe-buffer').Buffer; @@ -159974,7 +158045,7 @@ function simpleWrite(buf) { function simpleEnd(buf) { return buf && buf.length ? this.write(buf) : ''; } -},{"safe-buffer":228}],235:[function(require,module,exports){ +},{"safe-buffer":224}],231:[function(require,module,exports){ var Buffer = require('buffer').Buffer module.exports = function (buf) { @@ -160003,7 +158074,7 @@ module.exports = function (buf) { } } -},{"buffer":188}],236:[function(require,module,exports){ +},{"buffer":184}],232:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -160737,7 +158808,7 @@ Url.prototype.parseHost = function() { if (host) this.hostname = host; }; -},{"./util":237,"punycode":211,"querystring":214}],237:[function(require,module,exports){ +},{"./util":233,"punycode":207,"querystring":210}],233:[function(require,module,exports){ 'use strict'; module.exports = { @@ -160755,7 +158826,7 @@ module.exports = { } }; -},{}],238:[function(require,module,exports){ +},{}],234:[function(require,module,exports){ (function (global){ /** @@ -160826,16 +158897,16 @@ function config (name) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],239:[function(require,module,exports){ -arguments[4][195][0].apply(exports,arguments) -},{"dup":195}],240:[function(require,module,exports){ +},{}],235:[function(require,module,exports){ +arguments[4][191][0].apply(exports,arguments) +},{"dup":191}],236:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],241:[function(require,module,exports){ +},{}],237:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -161425,7 +159496,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":240,"_process":210,"inherits":239}],242:[function(require,module,exports){ +},{"./support/isBuffer":236,"_process":206,"inherits":235}],238:[function(require,module,exports){ module.exports = extend var hasOwnProperty = Object.prototype.hasOwnProperty; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aax.js index 9c71e445f..3b8be7dc2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, ExchangeNotAvailable, OrderNotFound, InvalidOrder, CancelPending, RateLimitExceeded, InsufficientFunds, BadRequest, BadSymbol, PermissionDenied } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -35,6 +36,7 @@ module.exports = class aax extends Exchange { 'fetchOrder': true, 'fetchOrderBook': true, 'fetchOrders': true, + 'fetchStatus': true, 'fetchTicker': 'emulated', 'fetchTickers': true, 'fetchTrades': true, @@ -233,6 +235,37 @@ module.exports = class aax extends Exchange { }); } + async fetchStatus (params = {}) { + const response = await this.publicGetAnnouncementMaintenance (params); + // + // { + // "code": 1, + // "data": { + // "startTime":"2020-06-25T02:15:00.000Z", + // "endTime":"2020-06-25T02:45:00.000Z", + // "description":"Spot Trading :UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45),Futures Trading: UTC Jun 25, 2020 02:15 to 02:45 (HKT Jun 25 10:15 to 10:45).We apologize for any inconvenience caused. Thank you for your patience and understanding.Should you have any enquiries, please do not hesitate our live chat support or via email at cs@aax.com." + // }, + // "message":"success", + // "ts":1593043237000 + // } + // + const data = this.safeValue (response, 'data', {}); + const timestamp = this.milliseconds (); + const startTime = this.parse8601 (this.safeString (data, 'startTime')); + const endTime = this.parse8601 (this.safeString (data, 'endTime')); + const update = { + 'updated': this.safeInteger (response, 'ts', timestamp), + }; + if (endTime !== undefined) { + const startTimeIsOk = (startTime === undefined) ? true : (timestamp < startTime); + const isOk = (timestamp > endTime) || startTimeIsOk; + update['eta'] = endTime; + update['status'] = isOk ? 'ok' : 'maintenance'; + } + this.status = this.extend (this.status, update); + return this.status; + } + async fetchMarkets (params = {}) { const response = await this.publicGetInstruments (params); // @@ -318,8 +351,8 @@ module.exports = class aax extends Exchange { const quote = this.safeCurrencyCode (quoteId); const status = this.safeString (market, 'status'); const active = (status === 'enable'); - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); const type = this.safeString (market, 'type'); let inverse = undefined; let linear = undefined; @@ -337,8 +370,8 @@ module.exports = class aax extends Exchange { symbol = base + '/' + quote; } const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; result.push ({ 'id': id, @@ -396,8 +429,8 @@ module.exports = class aax extends Exchange { const timestamp = this.safeInteger (ticker, 't'); const marketId = this.safeString (ticker, 's'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'c'); - const open = this.safeFloat (ticker, 'o'); + const last = this.safeNumber (ticker, 'c'); + const open = this.safeNumber (ticker, 'o'); let change = undefined; let percentage = undefined; let average = undefined; @@ -408,13 +441,13 @@ module.exports = class aax extends Exchange { } average = this.sum (last, open) / 2; } - const quoteVolume = this.safeFloat (ticker, 'v'); + const quoteVolume = this.safeNumber (ticker, 'v'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'h'), - 'low': this.safeFloat (ticker, 'l'), + 'high': this.safeNumber (ticker, 'h'), + 'low': this.safeNumber (ticker, 'l'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -561,8 +594,8 @@ module.exports = class aax extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let price = this.safeFloat2 (trade, 'p', 'filledPrice'); - const amount = this.safeFloat2 (trade, 'q', 'filledQty'); + let priceString = this.safeString2 (trade, 'p', 'filledPrice'); + const amountString = this.safeString2 (trade, 'q', 'filledQty'); const orderId = this.safeString (trade, 'orderID'); const isTaker = this.safeValue (trade, 'taker'); let takerOrMaker = undefined; @@ -576,17 +609,15 @@ module.exports = class aax extends Exchange { side = 'sell'; } if (side === undefined) { - side = (price > 0) ? 'buy' : 'sell'; - } - side = (price > 0) ? 'buy' : 'sell'; - price = Math.abs (price); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; + side = (priceString[0] === '-') ? 'sell' : 'buy'; } + priceString = (priceString[0] === '-') ? priceString.slice (1) : priceString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderType = this.parseOrderType (this.safeString (trade, 'orderType')); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { @@ -654,11 +685,11 @@ module.exports = class aax extends Exchange { // return [ this.safeTimestamp (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -743,12 +774,12 @@ module.exports = class aax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'unavailable'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'unavailable'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -776,7 +807,7 @@ module.exports = class aax extends Exchange { request['clOrdID'] = clientOrderId; params = this.omit (params, [ 'clOrdID', 'clientOrderId' ]); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { if ((orderType === 'STOP-LIMIT') || (orderType === 'STOP')) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for ' + orderType + ' orders'); @@ -894,7 +925,7 @@ module.exports = class aax extends Exchange { // 'price': this.priceToPrecision (symbol, price), // 'stopPrice': this.priceToPrecision (symbol, stopPrice), }; - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1531,15 +1562,18 @@ module.exports = class aax extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const price = this.safeFloat (order, 'price'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const price = this.safeNumber (order, 'price'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'Post-Only'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeString (order, 'leavesQty'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + let remaining = this.safeNumber (order, 'leavesQty'); + if ((filled === 0) && (remaining === 0)) { + remaining = undefined; + } let cost = undefined; let lastTradeTimestamp = undefined; if (filled !== undefined) { @@ -1554,7 +1588,7 @@ module.exports = class aax extends Exchange { } } let fee = undefined; - const feeCost = this.safeFloat (order, 'commission'); + const feeCost = this.safeNumber (order, 'commission'); if (feeCost !== undefined) { let feeCurrency = undefined; if (market !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/acx.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/acx.js deleted file mode 100644 index e10ec85ca..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/acx.js +++ /dev/null @@ -1,487 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { InsufficientFunds, OrderNotFound } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class acx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'acx', - 'name': 'ACX', - 'countries': [ 'AU' ], - 'rateLimit': 1000, - 'version': 'v2', - 'has': { - 'cancelOrder': true, - 'CORS': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchMarkets': true, - 'fetchOHLCV': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTime': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'timeframes': { - '1m': '1', - '5m': '5', - '15m': '15', - '30m': '30', - '1h': '60', - '2h': '120', - '4h': '240', - '12h': '720', - '1d': '1440', - '3d': '4320', - '1w': '10080', - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/30247614-1fe61c74-9621-11e7-9e8c-f1a627afa279.jpg', - 'extension': '.json', - 'api': 'https://acx.io/api', - 'www': 'https://acx.io', - 'doc': 'https://acx.io/documents/api_v2', - }, - 'api': { - 'public': { - 'get': [ - 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. - 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator - 'k', // Get OHLC(k line) of specific market - 'markets', // Get all available markets - 'order_book', // Get the order book of specified market - 'order_book/{market}', - 'tickers', // Get ticker of all markets - 'tickers/{market}', // Get ticker of specific market - 'timestamp', // Get server current time, in seconds since Unix epoch - 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. - 'trades/{market}', - ], - }, - 'private': { - 'get': [ - 'members/me', // Get your profile and accounts info - 'deposits', // Get your deposits history - 'deposit', // Get details of specific deposit - 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. - 'orders', // Get your orders, results is paginated - 'order', // Get information of specified order - 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. - 'withdraws', // Get your cryptocurrency withdraws - 'withdraw', // Get your cryptocurrency withdraw - ], - 'post': [ - 'orders', // Create a Sell/Buy order - 'orders/multi', // Create multiple sell/buy orders - 'orders/clear', // Cancel all my orders - 'order/delete', // Cancel an order - 'withdraw', // Create a withdraw - ], - }, - }, - 'fees': { - 'trading': { - 'tierBased': false, - 'percentage': true, - 'maker': 0.2 / 100, - 'taker': 0.2 / 100, - }, - 'funding': { - 'tierBased': false, - 'percentage': true, - 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account. - }, - }, - 'commonCurrencies': { - 'PLA': 'Plair', - }, - 'exceptions': { - '2002': InsufficientFunds, - '2003': OrderNotFound, - }, - }); - } - - async fetchMarkets (params = {}) { - const markets = await this.publicGetMarkets (params); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = market['id']; - const symbol = market['name']; - let baseId = this.safeString (market, 'base_unit'); - let quoteId = this.safeString (market, 'quote_unit'); - if ((baseId === undefined) || (quoteId === undefined)) { - const ids = symbol.split ('/'); - baseId = ids[0].toLowerCase (); - quoteId = ids[1].toLowerCase (); - } - let base = baseId.toUpperCase (); - let quote = quoteId.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - // todo: find out their undocumented precision and limits - const precision = { - 'amount': 8, - 'price': 8, - }; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'precision': precision, - 'info': market, - 'active': undefined, - 'limits': this.limits, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetMembersMe (params); - const balances = this.safeValue (response, 'accounts'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 300 - } - const orderbook = await this.publicGetDepth (this.extend (request, params)); - const timestamp = this.safeTimestamp (orderbook, 'timestamp'); - return this.parseOrderBook (orderbook, timestamp); - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.safeTimestamp (ticker, 'at'); - ticker = ticker['ticker']; - let symbol = undefined; - if (market) { - symbol = market['symbol']; - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': undefined, - 'info': ticker, - }; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetTickers (params); - const ids = Object.keys (response); - const result = {}; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let market = undefined; - let symbol = id; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } else { - let base = id.slice (0, 3); - let quote = id.slice (3, 6); - base = base.toUpperCase (); - quote = quote.toUpperCase (); - base = this.safeCurrencyCode (base); - quote = this.safeCurrencyCode (quote); - symbol = base + '/' + quote; - } - result[symbol] = this.parseTicker (response[id], market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTickersMarket (this.extend (request, params)); - return this.parseTicker (response, market); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const id = this.safeString (trade, 'tid'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'info': trade, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': undefined, - 'side': undefined, - 'order': undefined, - 'takerOrMaker': undefined, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), - 'cost': this.safeFloat (trade, 'funds'), - 'fee': undefined, - }; - } - - async fetchTime (params = {}) { - const response = await this.publicGetTimestamp (params); - // - // 1594911427 - // - return response * 1000; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - return [ - this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (limit === undefined) { - limit = 500; // default is 30 - } - const request = { - 'market': market['id'], - 'period': this.timeframes[timeframe], - 'limit': limit, - }; - if (since !== undefined) { - request['timestamp'] = parseInt (since / 1000); - } - const response = await this.publicGetK (this.extend (request, params)); - return this.parseOHLCVs (response, market, timeframe, since, limit); - } - - parseOrderStatus (status) { - const statuses = { - 'done': 'closed', - 'wait': 'open', - 'cancel': 'canceled', - }; - return this.safeString (statuses, status, status); - } - - parseOrder (order, market = undefined) { - const marketId = this.safeString (order, 'market'); - const symbol = this.safeSymbol (marketId, market); - const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const status = this.parseOrderStatus (this.safeString (order, 'state')); - const type = this.safeString (order, 'type'); - const side = this.safeString (order, 'side'); - const id = this.safeString (order, 'id'); - return { - 'id': id, - 'clientOrderId': undefined, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': this.safeFloat (order, 'price'), - 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'volume'), - 'filled': this.safeFloat (order, 'executed_volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'trades': undefined, - 'fee': undefined, - 'info': order, - 'cost': undefined, - 'average': undefined, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': parseInt (id), - }; - const response = await this.privateGetOrder (this.extend (request, params)); - return this.parseOrder (response); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'market': this.marketId (symbol), - 'side': side, - 'volume': amount.toString (), - 'ord_type': type, - }; - if (type === 'limit') { - request['price'] = price.toString (); - } - const response = await this.privatePostOrders (this.extend (request, params)); - const marketId = this.safeValue (response, 'market'); - const market = this.safeValue (this.markets_by_id, marketId); - return this.parseOrder (response, market); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - const response = await this.privatePostOrderDelete (this.extend (request, params)); - const order = this.parseOrder (response); - const status = order['status']; - if (status === 'closed' || status === 'canceled') { - throw new OrderNotFound (this.id + ' ' + this.json (order)); - } - return order; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - // they have XRP but no docs on memo/tag - const request = { - 'currency': currency['id'], - 'sum': amount, - 'address': address, - }; - const response = await this.privatePostWithdraw (this.extend (request, params)); - // withdrawal response is undocumented - return { - 'info': response, - 'id': undefined, - }; - } - - nonce () { - return this.milliseconds (); - } - - encodeParams (params) { - if ('orders' in params) { - const orders = params['orders']; - let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); - for (let i = 0; i < orders.length; i++) { - const order = orders[i]; - const keys = Object.keys (order); - for (let k = 0; k < keys.length; k++) { - const key = keys[k]; - const value = order[key]; - query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); - } - } - return query; - } - return this.urlencode (this.keysort (params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let request = '/api/' + this.version + '/' + this.implodeParams (path, params); - if ('extension' in this.urls) { - request += this.urls['extension']; - } - const query = this.omit (params, this.extractParams (path)); - let url = this.urls['api'] + request; - if (api === 'public') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce ().toString (); - const query = this.encodeParams (this.extend ({ - 'access_key': this.apiKey, - 'tonce': nonce, - }, params)); - const auth = method + '|' + request + '|' + query; - const signed = this.hmac (this.encode (auth), this.encode (this.secret)); - const suffix = query + '&signature=' + signed; - if (method === 'GET') { - url += '?' + suffix; - } else { - body = suffix; - headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; - } - if (code === 400) { - const error = this.safeValue (response, 'error'); - const errorCode = this.safeString (error, 'code'); - const feedback = this.id + ' ' + this.json (response); - this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); - // fallback to default error handler - } - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aofex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aofex.js index 7899f09d5..69264394e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aofex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/aofex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, BadSymbol, InvalidOrder, PermissionDenied, InvalidAddress, AuthenticationError, InvalidNonce, BadRequest, InsufficientFunds, OrderNotFound } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -193,8 +194,8 @@ module.exports = class aofex extends Exchange { const symbol = base + '/' + quote; const numericId = this.safeInteger (market, 'id'); const precision = this.safeValue (precisions, id, {}); - const makerFee = this.safeFloat (market, 'maker_fee'); - const takerFee = this.safeFloat (market, 'taker_fee'); + const makerFee = this.safeNumber (market, 'maker_fee'); + const takerFee = this.safeNumber (market, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -212,12 +213,12 @@ module.exports = class aofex extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -245,11 +246,11 @@ module.exports = class aofex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -328,11 +329,11 @@ module.exports = class aofex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -355,8 +356,8 @@ module.exports = class aofex extends Exchange { return { 'info': response, 'symbol': symbol, - 'maker': this.safeFloat (result, 'fromFee'), - 'taker': this.safeFloat (result, 'toFee'), + 'maker': this.safeNumber (result, 'fromFee'), + 'taker': this.safeNumber (result, 'toFee'), }; } @@ -413,8 +414,8 @@ module.exports = class aofex extends Exchange { if (market) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); let change = undefined; if (symbol !== undefined) { change = parseFloat (this.priceToPrecision (symbol, last - open)); @@ -423,8 +424,8 @@ module.exports = class aofex extends Exchange { } const average = this.sum (last, open) / 2; const percentage = change / open * 100; - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); let vwap = this.vwap (baseVolume, quoteVolume); if (vwap !== undefined) { vwap = parseFloat (this.priceToPrecision (symbol, vwap)); @@ -433,8 +434,8 @@ module.exports = class aofex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -552,13 +553,15 @@ module.exports = class aofex extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'number'); - let cost = this.safeFloat (trade, 'total_price'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'number'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total_price'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -702,21 +705,21 @@ module.exports = class aofex extends Exchange { const orderType = this.safeString (order, 'type'); const type = (orderType === '2') ? 'limit' : 'market'; const side = this.safeString (order, 'side'); - // const amount = this.safeFloat (order, 'number'); - // const price = this.safeFloat (order, 'price'); + // const amount = this.safeNumber (order, 'number'); + // const price = this.safeNumber (order, 'price'); let cost = undefined; let price = undefined; let amount = undefined; let average = undefined; - const number = this.safeFloat (order, 'number'); - const totalPrice = this.safeFloat (order, 'total_price'); + const number = this.safeNumber (order, 'number'); + const totalPrice = this.safeNumber (order, 'total_price'); if (type === 'limit') { amount = number; - price = this.safeFloat (order, 'price'); + price = this.safeNumber (order, 'price'); } else { - average = this.safeFloat (order, 'deal_price'); + average = this.safeNumber (order, 'deal_price'); if (side === 'buy') { - amount = this.safeFloat (order, 'deal_number'); + amount = this.safeNumber (order, 'deal_number'); } else { amount = number; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ascendex.js similarity index 93% rename from Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmax.js rename to Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ascendex.js index 62cbf55d5..753148db2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Sensor-Bot/Exchange-Raw-Data/node_modules/ccxt/js/bitmax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ascendex.js @@ -4,16 +4,17 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, InvalidOrder, BadSymbol, PermissionDenied, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class bitmax extends Exchange { +module.exports = class ascendex extends Exchange { describe () { return this.deepExtend (super.describe (), { - 'id': 'bitmax', - 'name': 'BitMax', - 'countries': [ 'CN' ], // China + 'id': 'ascendex', + 'name': 'AscendEX', + 'countries': [ 'SG', 'CN' ], // Singapore, China 'rateLimit': 500, // new metainfo interface 'has': { @@ -55,14 +56,14 @@ module.exports = class bitmax extends Exchange { }, 'version': 'v1', 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/66820319-19710880-ef49-11e9-8fbe-16be62a11992.jpg', - 'api': 'https://bitmax.io', + 'logo': 'https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg', + 'api': 'https://ascendex.com', 'test': 'https://bitmax-test.io', - 'www': 'https://bitmax.io', + 'www': 'https://ascendex.com', 'doc': [ 'https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation', ], - 'fees': 'https://bitmax.io/#/feeRate/tradeRate', + 'fees': 'https://ascendex.com/en/feerate/transactionfee-traderate', 'referral': 'https://bitmax.io/#/register?inviteCode=EL6BXBQM', }, 'api': { @@ -131,6 +132,7 @@ module.exports = class bitmax extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'taker': 0.002, @@ -212,6 +214,7 @@ module.exports = class bitmax extends Exchange { 'broad': {}, }, 'commonCurrencies': { + 'BOND': 'BONDED', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', }, @@ -294,7 +297,7 @@ module.exports = class bitmax extends Exchange { const code = this.safeCurrencyCode (id); const precision = this.safeInteger2 (currency, 'precisionScale', 'nativeScale'); // why would the exchange API have different names for the same field - const fee = this.safeFloat2 (currency, 'withdrawFee', 'withdrawalFee'); + const fee = this.safeNumber2 (currency, 'withdrawFee', 'withdrawalFee'); const status = this.safeString2 (currency, 'status', 'statusCode'); const active = (status === 'Normal'); const margin = ('borrowAssetCode' in currency); @@ -322,7 +325,7 @@ module.exports = class bitmax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawalAmt'), + 'min': this.safeNumber (currency, 'minWithdrawalAmt'), 'max': undefined, }, }, @@ -423,8 +426,8 @@ module.exports = class bitmax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'Normal'); @@ -450,16 +453,16 @@ module.exports = class bitmax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minQty'), - 'max': this.safeFloat (market, 'maxQty'), + 'min': this.safeNumber (market, 'minQty'), + 'max': this.safeNumber (market, 'maxQty'), }, 'price': { - 'min': this.safeFloat (market, 'tickSize'), + 'min': this.safeNumber (market, 'tickSize'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minNotional'), - 'max': this.safeFloat (market, 'maxNotional'), + 'min': this.safeNumber (market, 'minNotional'), + 'max': this.safeNumber (market, 'maxNotional'), }, }, }); @@ -467,28 +470,6 @@ module.exports = class bitmax extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - // TODO: fee calculation here is incorrect, we need to support tiered fee calculation. - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { let accountGroup = this.safeString (this.options, 'account-group'); let response = undefined; @@ -593,11 +574,11 @@ module.exports = class bitmax extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'asset')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -669,10 +650,10 @@ module.exports = class bitmax extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', []); const ask = this.safeValue (ticker, 'ask', []); - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; let average = undefined; @@ -687,12 +668,12 @@ module.exports = class bitmax extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 0), - 'bidVolume': this.safeFloat (bid, 1), - 'ask': this.safeFloat (ask, 0), - 'askVolume': this.safeFloat (ask, 1), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 0), + 'bidVolume': this.safeNumber (bid, 1), + 'ask': this.safeNumber (ask, 0), + 'askVolume': this.safeNumber (ask, 1), 'vwap': undefined, 'open': open, 'close': close, @@ -701,20 +682,12 @@ module.exports = class bitmax extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -791,11 +764,11 @@ module.exports = class bitmax extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.safeInteger (data, 'ts'), - this.safeFloat (data, 'o'), - this.safeFloat (data, 'h'), - this.safeFloat (data, 'l'), - this.safeFloat (data, 'c'), - this.safeFloat (data, 'v'), + this.safeNumber (data, 'o'), + this.safeNumber (data, 'h'), + this.safeNumber (data, 'l'), + this.safeNumber (data, 'c'), + this.safeNumber (data, 'v'), ]; } @@ -860,12 +833,11 @@ module.exports = class bitmax extends Exchange { // } // const timestamp = this.safeInteger (trade, 'ts'); - const price = this.safeFloat2 (trade, 'price', 'p'); - const amount = this.safeFloat (trade, 'q'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString2 (trade, 'price', 'p'); + const amountString = this.safeString (trade, 'q'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const buyerIsMaker = this.safeValue (trade, 'bm', false); const makerOrTaker = buyerIsMaker ? 'maker' : 'taker'; const side = buyerIsMaker ? 'buy' : 'sell'; @@ -989,26 +961,12 @@ module.exports = class bitmax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '/'); - let timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); - let lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const average = this.safeFloat (order, 'avgPx'); - const filled = this.safeFloat2 (order, 'cumFilledQty', 'cumQty'); - let remaining = undefined; - if (filled !== undefined) { - if (filled === 0) { - timestamp = lastTradeTimestamp; - lastTradeTimestamp = undefined; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - let cost = undefined; - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } + const timestamp = this.safeInteger2 (order, 'timestamp', 'sendingTime'); + const lastTradeTimestamp = this.safeInteger (order, 'lastExecTime'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const average = this.safeNumber (order, 'avgPx'); + const filled = this.safeNumber2 (order, 'cumFilledQty', 'cumQty'); const id = this.safeString (order, 'orderId'); let clientOrderId = this.safeString (order, 'id'); if (clientOrderId !== undefined) { @@ -1018,7 +976,7 @@ module.exports = class bitmax extends Exchange { } const type = this.safeStringLower (order, 'orderType'); const side = this.safeStringLower (order, 'side'); - const feeCost = this.safeFloat (order, 'cumFee'); + const feeCost = this.safeNumber (order, 'cumFee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeAsset'); @@ -1028,8 +986,8 @@ module.exports = class bitmax extends Exchange { 'currency': feeCurrencyCode, }; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1044,14 +1002,14 @@ module.exports = class bitmax extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1088,7 +1046,7 @@ module.exports = class bitmax extends Exchange { request['orderPrice'] = this.priceToPrecision (symbol, price); } if ((type === 'stop_limit') || (type === 'stop_market')) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice parameter for ' + type + ' orders'); } else { @@ -1624,7 +1582,7 @@ module.exports = class bitmax extends Exchange { // } // const id = this.safeString (transaction, 'requestId'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const destAddress = this.safeValue (transaction, 'destAddress', {}); const address = this.safeString (destAddress, 'address'); const tag = this.safeString (destAddress, 'destTag'); @@ -1634,7 +1592,7 @@ module.exports = class bitmax extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'commission'); + const feeCost = this.safeNumber (transaction, 'commission'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Exchange.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Exchange.js index eb017b5bf..0cf2c9fb0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Exchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Exchange.js @@ -44,6 +44,7 @@ const { // eslint-disable-line object-curly-newline const { TRUNCATE, ROUND, DECIMAL_PLACES, NO_PADDING } = functions.precisionConstants const BN = require ('../static_dependencies/BN/bn') +const Precise = require ('./Precise') // ---------------------------------------------------------------------------- @@ -224,6 +225,11 @@ module.exports = class Exchange { this.minFundingAddressLength = 1 // used in checkAddress this.substituteCommonCurrencyCodes = true // reserved + this.quoteJsonNumbers = true // treat numbers in json as quoted precise strings + this.number = Number // or String (a pointer to a function) + + // whether fees should be summed by currency code + this.reduceFees = true // do not delete this line, it is needed for users to be able to define their own fetchImplementation this.fetchImplementation = defaultFetch @@ -519,7 +525,7 @@ module.exports = class Exchange { parseJson (jsonString) { try { if (this.isJsonEncodedObject (jsonString)) { - return JSON.parse (jsonString) + return JSON.parse (this.onJsonResponse (jsonString)) } } catch (e) { // SyntaxError @@ -598,7 +604,11 @@ module.exports = class Exchange { } onRestResponse (statusCode, statusText, url, method, responseHeaders, responseBody, requestHeaders, requestBody) { - return responseBody.trim ().replace (/:(\d{15,}),/g, ':"$1",'); + return responseBody.trim () + } + + onJsonResponse (responseBody) { + return this.quoteJsonNumbers ? responseBody.replace (/":([+.0-9eE-]+),/g, '":"$1",') : responseBody; } setMarkets (markets, currencies = undefined) { @@ -918,8 +928,8 @@ module.exports = class Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = parseFloat (bidask[priceKey]) - const amount = parseFloat (bidask[amountKey]) + const price = this.safeNumber (bidask, priceKey) + const amount = this.safeNumber (bidask, amountKey) return [ price, amount ] } @@ -945,7 +955,7 @@ module.exports = class Exchange { } } - parseBalance (balance) { + parseBalance (balance, legacy = true) { const codes = Object.keys (this.omit (balance, [ 'info', 'free', 'used', 'total' ])); @@ -957,20 +967,34 @@ module.exports = class Exchange { const code = codes[i] if (balance[code].total === undefined) { if (balance[code].free !== undefined && balance[code].used !== undefined) { - balance[code].total = this.sum (balance[code].free, balance[code].used) + if (legacy) { + balance[code].total = this.sum (balance[code].free, balance[code].used) + } else { + balance[code].total = Precise.stringAdd (balance[code].free, balance[code].used) + } } } if (balance[code].free === undefined) { if (balance[code].total !== undefined && balance[code].used !== undefined) { - balance[code].free = this.sum (balance[code].total, -balance[code].used) + if (legacy) { + balance[code].free = this.sum (balance[code].total, -balance[code].used) + } else { + balance[code].free = Precise.stringSub (balance[code].total, balance[code].used) + } } } if (balance[code].used === undefined) { if (balance[code].total !== undefined && balance[code].free !== undefined) { - balance[code].used = this.sum (balance[code].total, -balance[code].free) + if (legacy) { + balance[code].used = this.sum (balance[code].total, -balance[code].free) + } else { + balance[code].used = Precise.stringSub (balance[code].total, balance[code].free) + } } } - + balance[code].free = this.parseNumber (balance[code].free) + balance[code].used = this.parseNumber (balance[code].used) + balance[code].total = this.parseNumber (balance[code].total) balance.free[code] = balance[code].free balance.used[code] = balance[code].used balance.total[code] = balance[code].total @@ -979,6 +1003,10 @@ module.exports = class Exchange { return balance } + async fetchBalance (params = {}) { + throw new NotSupported (this.id + ' fetchBalance not supported yet') + } + async fetchPartialBalance (part, params = {}) { const balance = await this.fetchBalance (params) return balance[part] @@ -1088,11 +1116,27 @@ module.exports = class Exchange { return indexed ? indexBy (result, key) : result } + parseTickers (tickers, symbols = undefined) { + const result = []; + for (let i = 0; i < tickers.length; i++) { + result.push (this.parseTicker (tickers[i])); + } + return this.filterByArray (result, 'symbol', symbols); + } + + parseDepositAddresses (addresses, codes = undefined) { + let result = []; + for (let i = 0; i < addresses.length; i++) { + const address = this.parseDepositAddress (addresses[i]); + result.push (address); + } + if (codes) { + result = this.filterByArray (result, 'currency', codes); + } + return this.indexBy (result, 'currency'); + } + parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (trades)) { - // throw new ExchangeError (this.id + ' parseTrades expected an array in the trades argument, but got ' + typeof trades); - // } let result = Object.values (trades || []).map ((trade) => this.extend (this.parseTrade (trade, market), params)) result = sortBy (result, 'timestamp') const symbol = (market !== undefined) ? market['symbol'] : undefined @@ -1101,10 +1145,6 @@ module.exports = class Exchange { } parseTransactions (transactions, currency = undefined, since = undefined, limit = undefined, params = {}) { - // this code is commented out temporarily to catch for exchange-specific errors - // if (!this.isArray (transactions)) { - // throw new ExchangeError (this.id + ' parseTransactions expected an array in the transactions argument, but got ' + typeof transactions); - // } let result = Object.values (transactions || []).map ((transaction) => this.extend (this.parseTransaction (transaction, currency), params)) result = this.sortBy (result, 'timestamp'); const code = (currency !== undefined) ? currency['code'] : undefined; @@ -1112,6 +1152,14 @@ module.exports = class Exchange { return this.filterByCurrencySinceLimit (result, code, since, limit, tail); } + parseTransfers (transfers, currency = undefined, since = undefined, limit = undefined, params = {}) { + let result = Object.values (transfers || []).map ((transfer) => this.extend (this.parseTransfer (transfer, currency), params)) + result = this.sortBy (result, 'timestamp'); + const code = (currency !== undefined) ? currency['code'] : undefined; + const tail = since === undefined; + return this.filterByCurrencySinceLimit (result, code, since, limit, tail); + } + parseLedger (data, currency = undefined, since = undefined, limit = undefined, params = {}) { let result = []; const array = Object.values (data || []); @@ -1256,19 +1304,19 @@ module.exports = class Exchange { return this.createOrder (symbol, ...args) } - createLimitOrder (symbol, side, amount, price = undefined, params = {}) { + createLimitOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'limit', side, amount, price, params) } - createMarketOrder (symbol, side, amount, price = undefined, params = {}) { + createMarketOrder (symbol, side, amount, price, params = {}) { return this.createOrder (symbol, 'market', side, amount, price, params) } - createLimitBuyOrder (symbol, amount, price = undefined, params = {}) { + createLimitBuyOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'buy', amount, price, params) } - createLimitSellOrder (symbol, amount, price = undefined, params = {}) { + createLimitSellOrder (symbol, amount, price, params = {}) { return this.createOrder (symbol, 'limit', 'sell', amount, price, params) } @@ -1301,15 +1349,43 @@ module.exports = class Exchange { } calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol] - const rate = market[takerOrMaker] - const cost = parseFloat (this.costToPrecision (symbol, amount * price)) + const market = this.markets[symbol]; + const feeSide = this.safeString (market, 'feeSide', 'quote'); + let key = 'quote'; + let cost = undefined; + if (feeSide === 'quote') { + // the fee is always in quote currency + cost = amount * price; + } else if (feeSide === 'base') { + // the fee is always in base currency + cost = amount; + } else if (feeSide === 'get') { + // the fee is always in the currency you get + cost = amount; + if (side === 'sell') { + cost *= price; + } else { + key = 'base'; + } + } else if (feeSide === 'give') { + // the fee is always in the currency you give + cost = amount; + if (side === 'buy') { + cost *= price; + } else { + key = 'base'; + } + } + const rate = market[takerOrMaker]; + if (cost !== undefined) { + cost *= rate; + } return { 'type': takerOrMaker, - 'currency': market['quote'], + 'currency': market[key], 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, rate * cost)), - } + 'cost': cost, + }; } checkRequiredDependencies () { @@ -1393,6 +1469,25 @@ module.exports = class Exchange { return new BN (a).pow (new BN (b)) } + reduceFeesByCurrency (fees) { + const reduced = {}; + for (let i = 0; i < fees.length; i++) { + const fee = fees[i]; + const feeCurrencyCode = this.safeValue (fee, 'currency'); + if (feeCurrencyCode !== undefined) { + if (feeCurrencyCode in reduced) { + reduced[feeCurrencyCode]['cost'] = this.sum (reduced[feeCurrencyCode]['cost'], fee['cost']); + } else { + reduced[feeCurrencyCode] = { + 'cost': fee['cost'], + 'currency': feeCurrencyCode, + }; + } + } + } + return Object.values (reduced); + } + safeOrder (order) { // Cost // Remaining @@ -1401,65 +1496,143 @@ module.exports = class Exchange { // Amount // Filled // - // First we try to calculate filled from the trades - const parseFilled = order['filled'] === undefined; - const parseCost = order['cost'] === undefined; - if (parseFilled) { - order['filled'] = 0 - } - if (parseCost) { - order['cost'] = 0 - } - if (parseFilled || parseCost) { - if (Array.isArray (order['trades'])) { - for (let i = 0; i < order['trades'].length; i++) { - const trade = order['trades'][i] - if (parseFilled) { - order['filled'] = this.sum (order['filled'], trade['amount']) + // first we try to calculate the order fields from the trades + let amount = this.safeValue (order, 'amount'); + let remaining = this.safeValue (order, 'remaining'); + let filled = this.safeValue (order, 'filled'); + let cost = this.safeValue (order, 'cost'); + let average = this.safeValue (order, 'average'); + let price = this.safeValue (order, 'price'); + let lastTradeTimeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); + const parseFilled = (filled === undefined); + const parseCost = (cost === undefined); + const parseLastTradeTimeTimestamp = (lastTradeTimeTimestamp === undefined); + const parseFee = this.safeValue (order, 'fee') === undefined; + const parseFees = this.safeValue (order, 'fees') === undefined; + const shouldParseFees = parseFee || parseFees; + const fees = shouldParseFees ? [] : undefined; + if (parseFilled || parseCost || shouldParseFees) { + const trades = this.safeValue (order, 'trades'); + if (trades !== undefined) { + if (parseFilled) { + filled = 0; + } + if (parseCost) { + cost = 0; + } + for (let i = 0; i < trades.length; i++) { + const trade = trades[i]; + const tradeAmount = this.safeValue (trade, 'amount'); + if (parseFilled && (tradeAmount !== undefined)) { + filled = this.sum (filled, tradeAmount); } - if (parseCost) { - order['cost'] = this.sum (order['cost'], trade['cost']) + const tradeCost = this.safeValue (trade, 'cost'); + if (parseCost && (tradeCost !== undefined)) { + cost = this.sum (cost, tradeCost); + } + const tradeTimestamp = this.safeValue (trade, 'timestamp'); + if (parseLastTradeTimeTimestamp && (tradeTimestamp !== undefined)) { + if (lastTradeTimeTimestamp === undefined) { + lastTradeTimeTimestamp = tradeTimestamp; + } else { + lastTradeTimeTimestamp = Math.max (lastTradeTimeTimestamp, tradeTimestamp); + } + } + if (shouldParseFees) { + const tradeFees = this.safeValue (trade, 'fees'); + if (tradeFees !== undefined) { + for (let j = 0; j < tradeFees.length; j++) { + const tradeFee = tradeFees[j]; + fees.push (this.extend ({}, tradeFee)); + } + } else { + const tradeFee = this.safeValue (trade, 'fee'); + if (tradeFee !== undefined) { + fees.push (this.extend ({}, tradeFee)); + } + } } } } } - // We ensure amount = filled + remaining - if (order['amount'] === undefined) { - if (order['filled'] !== undefined && order['remaining'] !== undefined) { - order['amount'] = this.sum (order['filled'], order['remaining']) + if (shouldParseFees) { + const reducedFees = this.reduceFees ? this.reduceFeesByCurrency (fees) : fees; + const reducedLength = reducedFees.length; + if (!parseFee && (reducedLength === 0)) { + reducedFees.push (order['fee']); + } + if (parseFees) { + order['fees'] = reducedFees; + } + if (parseFee && (reducedLength === 1)) { + order['fee'] = reducedFees[0]; } } - if (order['filled'] === undefined) { - if (order['amount'] !== undefined && order['remaining'] !== undefined) { - order['filled'] = Math.max (this.sum (order['amount'], -order['remaining']), 0) + if (amount === undefined) { + // ensure amount = filled + remaining + if (filled !== undefined && remaining !== undefined) { + amount = this.sum (filled, remaining); + } else if (this.safeString (order, 'status') === 'closed') { + amount = filled; } } - if (order['remaining'] === undefined) { - if (order['amount'] !== undefined && order['filled'] !== undefined) { - order['remaining'] = Math.max (this.sum (order['amount'], -order['filled']), 0) + if (filled === undefined) { + if (amount !== undefined && remaining !== undefined) { + filled = Math.max (this.sum (amount, -remaining), 0); } } - // We ensure that the average field is calculated correctly - if (order['average'] === undefined) { - if (order['filled'] !== undefined && order['cost'] !== undefined && order['cost'] > 0) { - order['average'] = order['filled'] / order['cost'] + if (remaining === undefined) { + if (amount !== undefined && filled !== undefined) { + remaining = Math.max (this.sum (amount, -filled), 0); } } - // We also ensure the cost field is calculated correctly - const costPriceExists = (order['average'] !== undefined) || (order['price'] !== undefined) - if ((order['filled'] !== undefined) && costPriceExists) { - let costPrice = undefined; - if (order['average'] === undefined) { - costPrice = order['price'] - } else { - costPrice = order['average'] + // ensure that the average field is calculated correctly + if (average === undefined) { + if ((filled !== undefined) && (cost !== undefined) && (cost > 0)) { + average = cost / filled; } - order['cost'] = costPrice * order['filled'] } - // We add support for market orders - if (order['price'] === undefined && order['type'] === 'market') { - order['price'] = order['average'] + // also ensure the cost field is calculated correctly + const costPriceExists = (average !== undefined) || (price !== undefined); + if (parseCost && (filled !== undefined) && costPriceExists) { + cost = (average === undefined) ? (price * filled) : (average * filled); } - return order + // support for market orders + const orderType = this.safeValue (order, 'type'); + const emptyPrice = (price === undefined) || (price === 0.0); + if (emptyPrice && (orderType === 'market')) { + price = average; + } + return this.extend (order, { + 'lastTradeTimestamp': lastTradeTimeTimestamp, + 'price': price, + 'amount': amount, + 'cost': cost, + 'average': average, + 'filled': filled, + 'remaining': remaining, + }); + } + + parseNumber (value, d = undefined) { + if (value === undefined) { + return d + } else { + try { + return this.number (value) + } catch (e) { + return d + } + } + } + + safeNumber (object, key, d = undefined) { + const value = this.safeString (object, key) + return this.parseNumber (value, d) + } + + safeNumber2 (object, key1, key2, d = undefined) { + const value = this.safeString2 (object, key1, key2) + return this.parseNumber (value, d) } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Precise.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Precise.js new file mode 100644 index 000000000..9bf17ad8d --- /dev/null +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/Precise.js @@ -0,0 +1,145 @@ +'use strict' + +const BN = require ('../static_dependencies/BN/bn') + +class Precise { + constructor (number, decimals = 0) { + const isBN = number instanceof BN + const isString = typeof number === 'string' + if (!(isBN || isString)) { + throw new Error ('Precise initiated with something other than a string or BN') + } + if (isBN) { + this.integer = number + this.decimals = decimals + } else { + if (decimals) { + throw new Error ('Cannot set decimals when initializing with a string') + } + let modifier = 0 + number = number.toLowerCase () + if (number.indexOf ('e') > -1) { + [ number, modifier ] = number.split ('e') + modifier = parseInt (modifier) + } + const decimalIndex = number.indexOf ('.') + this.decimals = (decimalIndex > -1) ? number.length - decimalIndex - 1 : 0 + const integerString = number.replace ('.', '') + this.integer = new BN (integerString) + this.decimals = this.decimals - modifier + } + this.base = 10 + this.reduce () + } + + mul (other) { + // other must be another instance of Precise + const integerResult = this.integer.mul (other.integer) + return new Precise (integerResult, this.decimals + other.decimals) + } + + div (other, precision = 18) { + const distance = precision - this.decimals + other.decimals + let numerator + if (distance === 0) { + numerator = this.integer + } else if (distance < 0) { + const exponent = new BN (this.base).pow (new BN (-distance)) + numerator = this.integer.div (exponent) + } else { + const exponent = new BN (this.base).pow (new BN (distance)) + numerator = this.integer.mul (exponent) + } + const result = numerator.div (other.integer) + return new Precise (result, precision) + } + + add (other) { + if (this.decimals === other.decimals) { + const integerResult = this.integer.add (other.integer) + return new Precise (integerResult, this.decimals) + } else { + const [ smaller, bigger ] = + (this.decimals > other.decimals) ? [ other, this ] : [ this, other ] + const exponent = new BN (bigger.decimals - smaller.decimals) + const normalised = smaller.integer.mul (new BN (this.base).pow (exponent)) + const result = normalised.add (bigger.integer) + return new Precise (result, bigger.decimals) + } + } + + sub (other) { + const negative = new Precise (other.integer.neg (), other.decimals) + return this.add (negative) + } + + reduce () { + const zero = new BN (0) + if (this.integer.eq (zero)) { + this.decimals = 0 + return this + } + const base = new BN (this.base) + let divmod = this.integer.divmod (base) + while (divmod.mod.eq (zero)) { + this.integer = divmod.div + this.decimals-- + divmod = this.integer.divmod (base) + } + return this + } + + toString () { + const sign = this.integer.negative ? '-' : '' + const integerArray = Array.from (this.integer.abs ().toString (this.base).padStart (this.decimals, '0')) + const index = integerArray.length - this.decimals + let item + if (index === 0) { + // if we are adding to the front + item = '0.' + } else if (this.decimals < 0) { + item = '0'.repeat (-this.decimals) + } else if (this.decimals === 0) { + item = '' + } else { + item = '.' + } + integerArray.splice (index, 0, item) + return sign + integerArray.join ('') + } + + static stringMul (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).mul (new Precise (string2)).toString () + } + + static stringDiv (string1, string2, precision = 18) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).div (new Precise (string2), precision).toString () + } + + static stringAdd (string1, string2) { + if ((string1 === undefined) && (string2 === undefined)) { + return undefined + } + if (string1 === undefined) { + return string2 + } else if (string2 === undefined) { + return string1 + } + return (new Precise (string1)).add (new Precise (string2)).toString () + } + + static stringSub (string1, string2) { + if ((string1 === undefined) || (string2 === undefined)) { + return undefined + } + return (new Precise (string1)).sub (new Precise (string2)).toString () + } +} + +module.exports = Precise; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/functions/encode.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/functions/encode.js index 0b4331ccf..e64251dbc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/functions/encode.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/base/functions/encode.js @@ -19,7 +19,6 @@ let base58Encoder = null module.exports = { json: (data, params = undefined) => JSON.stringify (data) - , unjson: JSON.parse , isJsonEncodedObject: object => ( (typeof object === 'string') && diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bibox.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bibox.js index 4d46d8f35..ed9826a1a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bibox.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bibox.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AccountSuspended, ArgumentsRequired, AuthenticationError, DDoSProtection, ExchangeNotAvailable, InvalidOrder, OrderNotFound, PermissionDenied, InsufficientFunds, BadSymbol, RateLimitExceeded, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -229,9 +230,9 @@ module.exports = class bibox extends Exchange { const quote = this.safeCurrencyCode (quoteId); symbol = base + '/' + quote; } - const last = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); - const baseVolume = this.safeFloat2 (ticker, 'vol', 'vol24H'); + const last = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); + const baseVolume = this.safeNumber2 (ticker, 'vol', 'vol24H'); let open = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; @@ -245,11 +246,11 @@ module.exports = class bibox extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -260,7 +261,7 @@ module.exports = class bibox extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': baseVolume, - 'quoteVolume': this.safeFloat (ticker, 'amount'), + 'quoteVolume': this.safeNumber (ticker, 'amount'), 'info': ticker, }; } @@ -276,17 +277,6 @@ module.exports = class bibox extends Exchange { return this.parseTicker (response['result'], market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - const ticker = this.parseTicker (rawTickers[i]); - if ((symbols === undefined) || (this.inArray (ticker['symbol'], symbols))) { - tickers.push (ticker); - } - } - return tickers; - } - async fetchTickers (symbols = undefined, params = {}) { const request = { 'cmd': 'marketAll', @@ -319,7 +309,7 @@ module.exports = class bibox extends Exchange { symbol = market['symbol']; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = this.safeString (trade, 'fee_symbol'); if (feeCurrency !== undefined) { if (feeCurrency in this.currencies_by_id) { @@ -329,12 +319,11 @@ module.exports = class bibox extends Exchange { } } const feeRate = undefined; // todo: deduce from market if market is defined - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if (feeCost !== undefined) { fee = { 'cost': -feeCost, @@ -385,7 +374,7 @@ module.exports = class bibox extends Exchange { request['size'] = limit; // default = 200 } const response = await this.publicGetMdata (this.extend (request, params)); - return this.parseOrderBook (response['result'], this.safeFloat (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); + return this.parseOrderBook (response['result'], this.safeNumber (response['result'], 'update_time'), 'bids', 'asks', 'price', 'volume'); } parseOHLCV (ohlcv, market = undefined) { @@ -401,11 +390,11 @@ module.exports = class bibox extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -497,7 +486,7 @@ module.exports = class bibox extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw_min'), + 'min': this.safeNumber (currency, 'withdraw_min'), 'max': undefined, }, }, @@ -629,19 +618,17 @@ module.exports = class bibox extends Exchange { code = this.currencies_by_id[code]['code']; } const account = this.account (); - let balance = indexed[id]; + const balance = indexed[id]; if (typeof balance === 'string') { - balance = parseFloat (balance); account['free'] = balance; - account['used'] = 0.0; account['total'] = balance; } else { - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -732,8 +719,8 @@ module.exports = class bibox extends Exchange { let tag = this.safeString (transaction, 'addr_remark'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'fee'); if (type === 'deposit') { feeCost = 0; tag = undefined; @@ -841,26 +828,19 @@ module.exports = class bibox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const type = (order['order_type'] === 1) ? 'market' : 'limit'; - const timestamp = order['createdAt']; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'deal_price'); - const filled = this.safeFloat (order, 'deal_amount'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat2 (order, 'deal_money', 'money'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - cost = price * filled; - } - } - const side = (order['order_side'] === 1) ? 'buy' : 'sell'; + const rawType = this.safeString (order, 'order_type'); + const type = (rawType === '1') ? 'market' : 'limit'; + const timestamp = this.safeInteger (order, 'createdAt'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'deal_price'); + const filled = this.safeNumber (order, 'deal_amount'); + const amount = this.safeNumber (order, 'amount'); + const cost = this.safeNumber2 (order, 'deal_money', 'money'); + const rawSide = this.safeString (order, 'order_side'); + const side = (rawSide === '1') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -868,8 +848,7 @@ module.exports = class bibox extends Exchange { 'currency': undefined, }; } - cost = cost ? cost : (parseFloat (price) * filled); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -887,11 +866,11 @@ module.exports = class bibox extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -1059,7 +1038,7 @@ module.exports = class bibox extends Exchange { }; const response = await this.privatePostTransfer (request); info[code] = response; - withdrawFees[code] = this.safeFloat (response['result'], 'withdraw_fee'); + withdrawFees[code] = this.safeNumber (response['result'], 'withdraw_fee'); } return { 'info': info, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bigone.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bigone.js index d6e940c4d..f30eec7a4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bigone.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bigone.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, OrderNotFound, InsufficientFunds, PermissionDenied, BadRequest, RateLimitExceeded, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -260,28 +261,28 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (ticker, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = undefined; - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const bid = this.safeValue (ticker, 'bid', {}); const ask = this.safeValue (ticker, 'ask', {}); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (bid, 'price'), - 'bidVolume': this.safeFloat (bid, 'quantity'), - 'ask': this.safeFloat (ask, 'price'), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (bid, 'price'), + 'bidVolume': this.safeNumber (bid, 'quantity'), + 'ask': this.safeNumber (ask, 'price'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, 'last': close, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'daily_change'), + 'change': this.safeNumber (ticker, 'daily_change'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -446,16 +447,13 @@ module.exports = class bigone extends Exchange { // } // const timestamp = this.parse8601 (this.safeString2 (trade, 'created_at', 'inserted_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } let side = this.safeString (trade, 'side'); const takerSide = this.safeString (trade, 'taker_side'); let takerOrMaker = undefined; @@ -529,8 +527,8 @@ module.exports = class bigone extends Exchange { takerCurrencyCode = market['quote']; } } - const makerFeeCost = this.safeFloat (trade, 'maker_fee'); - const takerFeeCost = this.safeFloat (trade, 'taker_fee'); + const makerFeeCost = this.safeNumber (trade, 'maker_fee'); + const takerFeeCost = this.safeNumber (trade, 'taker_fee'); if (makerFeeCost !== undefined) { if (takerFeeCost !== undefined) { result['fees'] = [ @@ -593,11 +591,11 @@ module.exports = class bigone extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -668,11 +666,11 @@ module.exports = class bigone extends Exchange { const symbol = this.safeString (balance, 'asset_symbol'); const code = this.safeCurrencyCode (symbol); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -694,13 +692,9 @@ module.exports = class bigone extends Exchange { const marketId = this.safeString (order, 'asset_pair_name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (amount !== undefined && filled !== undefined) { - remaining = Math.max (0, amount - filled); - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); const status = this.parseOrderStatus (this.safeString (order, 'state')); let side = this.safeString (order, 'side'); if (side === 'BID') { @@ -708,15 +702,9 @@ module.exports = class bigone extends Exchange { } else { side = 'sell'; } - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'updated_at')); - const average = this.safeFloat (order, 'avg_deal_price'); - return { + const average = this.safeNumber (order, 'avg_deal_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -731,14 +719,14 @@ module.exports = class bigone extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -762,7 +750,7 @@ module.exports = class bigone extends Exchange { const isStopLimit = (uppercaseType === 'STOP_LIMIT'); const isStopMarket = (uppercaseType === 'STOP_MARKET'); if (isStopLimit || isStopMarket) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price parameter'); } @@ -1101,7 +1089,7 @@ module.exports = class bigone extends Exchange { const currencyId = this.safeString (transaction, 'asset_symbol'); const code = this.safeCurrencyCode (currencyId); const id = this.safeInteger (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const timestamp = this.parse8601 (this.safeString (transaction, 'inserted_at')); const updated = this.parse8601 (this.safeString2 (transaction, 'updated_at', 'completed_at')); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/binance.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/binance.js index a115b3f7b..a5865c442 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/binance.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/binance.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, NotSupported, BadRequest, BadSymbol, AccountSuspended, OrderImmediatelyFillable } = require ('./base/errors'); -const { ROUND, TRUNCATE } = require ('./base/functions/number'); +const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -47,6 +48,8 @@ module.exports = class binance extends Exchange { 'fetchTransactions': false, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, + 'fetchTransfers': true, }, 'timeframes': { '1m': '1m', @@ -195,6 +198,26 @@ module.exports = class binance extends Exchange { 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/recentRecord', 'apiReferral/kickback/historicalRecord', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccount', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/info', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/recentRecord', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/status', + 'broker/subAccount/depositHist', + 'broker/subAccount/spotSummary', + 'broker/subAccount/marginSummary', + 'broker/subAccount/futuresSummary', + 'broker/rebate/futures/recentRecord', + 'broker/subAccountApi/ipRestriction', + 'broker/universalTransfer', + // v2 not supported yet + // GET /sapi/v2/broker/subAccount/futuresSummary ], 'post': [ 'asset/dust', @@ -234,11 +257,30 @@ module.exports = class binance extends Exchange { // leveraged token endpoints 'blvt/subscribe', 'blvt/redeem', - // broker api + // brokerage API 'apiReferral/customization', 'apiReferral/userCustomization', 'apiReferral/rebate/historicalRecord', 'apiReferral/kickback/historicalRecord', + 'broker/subAccount', + 'broker/subAccount/margin', + 'broker/subAccount/futures', + 'broker/subAccountApi', + 'broker/subAccountApi/permission', + 'broker/subAccountApi/commission', + 'broker/subAccountApi/commission/futures', + 'broker/subAccountApi/commission/coinFutures', + 'broker/transfer', + 'broker/transfer/futures', + 'broker/rebate/historicalRecord', + 'broker/subAccount/bnbBurn/spot', + 'broker/subAccount/bnbBurn/marginInterest', + 'broker/subAccount/blvt', + 'broker/subAccountApi/ipRestriction', + 'broker/subAccountApi/ipRestriction/ipList', + 'broker/universalTransfer', + 'broker/subAccountApi/permission/universalTransfer', + 'broker/subAccountApi/permission/vanillaOptions', ], 'put': [ 'userDataStream', @@ -249,6 +291,9 @@ module.exports = class binance extends Exchange { 'margin/order', 'userDataStream', 'userDataStream/isolated', + // brokerage API + 'broker/subAccountApi', + 'broker/subAccountApi/ipRestriction/ipList', ], }, 'wapi': { @@ -385,6 +430,8 @@ module.exports = class binance extends Exchange { 'positionSide/dual', 'userTrades', 'income', + 'commissionRate', + 'apiTradingStatus', // broker endpoints 'apiReferral/ifNewUser', 'apiReferral/customization', @@ -474,6 +521,7 @@ module.exports = class binance extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.001, @@ -498,7 +546,7 @@ module.exports = class binance extends Exchange { 'parseOrderToPrecision': false, // force amounts and costs in parseOrder to precision 'newOrderRespType': { 'market': 'FULL', // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills - 'limit': 'RESULT', // we change it from 'ACK' by default to 'RESULT' + 'limit': 'FULL', // we change it from 'ACK' by default to 'FULL' (returns immediately if limit is not hit) }, 'quoteOrderQty': true, // whether market orders support amounts in quote currency 'broker': { @@ -507,6 +555,25 @@ module.exports = class binance extends Exchange { 'future': 'x-xcKtGhcu', 'delivery': 'x-xcKtGhcu', }, + 'fetchPositions': { + 'future': 'fapiPrivateV2GetAccount', // 'fapiPrivateGetPositionRisk' + 'delivery': 'dapiPrivateGetAccount', // 'dapiPrivateGetPositionRisk' + }, + 'accountsByType': { + 'main': 'MAIN', + 'spot': 'MAIN', + 'margin': 'MARGIN', + 'future': 'UMFUTURE', + 'delivery': 'CMFUTURE', + 'mining': 'MINING', + }, + 'typesByAccount': { + 'MAIN': 'spot', + 'MARGIN': 'margin', + 'UMFUTURE': 'future', + 'CMFUTURE': 'delivery', + 'MINING': 'mining', + }, }, // https://binance-docs.github.io/apidocs/spot/en/#error-codes-2 'exceptions': { @@ -564,6 +631,8 @@ module.exports = class binance extends Exchange { '-3010': ExchangeError, // {"code":-3010,"msg":"Repay not allowed. Repay amount exceeds borrow amount."} '-3022': AccountSuspended, // You account's trading is banned. '-4028': BadRequest, // {"code":-4028,"msg":"Leverage 100 is not valid"} + '-3020': InsufficientFunds, // {"code":-3020,"msg":"Transfer out amount exceeds max amount."} + '-3041': InsufficientFunds, // {"code":-3041,"msg":"Balance is not enough"} '-5013': InsufficientFunds, // Asset transfer failed: insufficient balance" }, }); @@ -706,13 +775,14 @@ module.exports = class binance extends Exchange { let fee = undefined; for (let j = 0; j < networkList.length; j++) { const networkItem = networkList[j]; - const name = this.safeString (networkItem, 'name'); - const withdrawFee = this.safeFloat (networkItem, 'withdrawFee'); + const network = this.safeString (networkItem, 'network'); + // const name = this.safeString (networkItem, 'name'); + const withdrawFee = this.safeNumber (networkItem, 'withdrawFee'); const depositEnable = this.safeValue (networkItem, 'depositEnable'); const withdrawEnable = this.safeValue (networkItem, 'withdrawEnable'); isDepositEnabled = isDepositEnabled || depositEnable; isWithdrawEnabled = isWithdrawEnabled || withdrawEnable; - fees[name] = withdrawFee; + fees[network] = withdrawFee; const isDefault = this.safeValue (networkItem, 'isDefault'); if (isDefault || fee === undefined) { fee = withdrawFee; @@ -898,7 +968,7 @@ module.exports = class binance extends Exchange { if (this.options['adjustForTimeDifference']) { await this.loadTimeDifference (); } - const markets = this.safeValue (response, 'symbols'); + const markets = this.safeValue (response, 'symbols', []); const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -963,10 +1033,10 @@ module.exports = class binance extends Exchange { // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } @@ -977,47 +1047,26 @@ module.exports = class binance extends Exchange { const stepSize = this.safeString (filter, 'stepSize'); entry['precision']['amount'] = this.precisionFromString (stepSize); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat2 (filter, 'minNotional', 'notional'); + entry['limits']['cost']['min'] = this.safeNumber2 (filter, 'minNotional', 'notional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'spot'); @@ -1188,8 +1237,8 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -1202,13 +1251,13 @@ module.exports = class binance extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['used'] = this.safeFloat (balance, 'initialMargin'); - account['total'] = this.safeFloat2 (balance, 'marginBalance', 'balance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['used'] = this.safeString (balance, 'initialMargin'); + account['total'] = this.safeString2 (balance, 'marginBalance', 'balance'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -1261,36 +1310,36 @@ module.exports = class binance extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'openPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'openPrice'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } async fetchStatus (params = {}) { const response = await this.wapiGetSystemStatus (params); - let status = this.safeValue (response, 'status'); + let status = this.safeString (response, 'status'); if (status !== undefined) { - status = (status === 0) ? 'ok' : 'maintenance'; + status = (status === '0') ? 'ok' : 'maintenance'; this.status = this.extend (this.status, { 'status': status, 'updated': this.milliseconds (), @@ -1319,14 +1368,6 @@ module.exports = class binance extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchBidsAsks', 'defaultType', 'spot'); @@ -1381,11 +1422,11 @@ module.exports = class binance extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -1516,8 +1557,11 @@ module.exports = class binance extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -1535,7 +1579,7 @@ module.exports = class binance extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -1548,10 +1592,6 @@ module.exports = class binance extends Exchange { } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } return { 'info': trade, 'timestamp': timestamp, @@ -1670,7 +1710,7 @@ module.exports = class binance extends Exchange { parseOrder (order, market = undefined) { // - // spot + // spot // // { // "symbol": "LTCBTC", @@ -1691,7 +1731,7 @@ module.exports = class binance extends Exchange { // "isWorking": true // } // - // futures + // futures // // { // "symbol": "BTCUSDT", @@ -1709,6 +1749,33 @@ module.exports = class binance extends Exchange { // "updateTime": 1499827319559 // } // + // createOrder with { "newOrderRespType": "FULL" } + // + // { + // "symbol": "BTCUSDT", + // "orderId": 5403233939, + // "orderListId": -1, + // "clientOrderId": "x-R4BD3S825e669e75b6c14f69a2c43e", + // "transactTime": 1617151923742, + // "price": "0.00000000", + // "origQty": "0.00050000", + // "executedQty": "0.00050000", + // "cummulativeQuoteQty": "29.47081500", + // "status": "FILLED", + // "timeInForce": "GTC", + // "type": "MARKET", + // "side": "BUY", + // "fills": [ + // { + // "price": "58941.63000000", + // "qty": "0.00050000", + // "commission": "0.00007050", + // "commissionAsset": "BNB", + // "tradeId": 737466631 + // } + // ] + // } + // const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -1718,80 +1785,26 @@ module.exports = class binance extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); // - Spot/Margin market: cummulativeQuoteQty // - Futures market: cumQuote. // Note this is not the actual cost, since Binance futures uses leverage to calculate margins. - let cost = this.safeFloat2 (order, 'cummulativeQuoteQty', 'cumQuote'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const cost = this.safeNumber2 (order, 'cummulativeQuoteQty', 'cumQuote'); const id = this.safeString (order, 'orderId'); let type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - if (this.options['parseOrderToPrecision']) { - price = parseFloat (this.priceToPrecision (symbol, price)); - } - } - } - } - } else if (type === 'limit_maker') { + if (type === 'limit_maker') { type = 'limit'; } const side = this.safeStringLower (order, 'side'); - let fee = undefined; - let trades = undefined; - const fills = this.safeValue (order, 'fills'); - if (fills !== undefined) { - trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - if (this.options['parseOrderToPrecision']) { - average = parseFloat (this.priceToPrecision (symbol, average)); - } - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const fills = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (fills, market); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1807,13 +1820,13 @@ module.exports = class binance extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1860,8 +1873,11 @@ module.exports = class binance extends Exchange { } else { request['newClientOrderId'] = clientOrderId; } - if (market['spot']) { + if ((orderType === 'spot') || (orderType === 'margin')) { request['newOrderRespType'] = this.safeValue (this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills + } else { + // delivery and future + request['newOrderRespType'] = 'RESULT'; // "ACK", "RESULT", default "ACK" } // additional required fields depending on the order type let timeInForceIsRequired = false; @@ -1891,7 +1907,7 @@ module.exports = class binance extends Exchange { if (uppercaseType === 'MARKET') { const quoteOrderQty = this.safeValue (this.options, 'quoteOrderQty', false); if (quoteOrderQty) { - const quoteOrderQty = this.safeFloat (params, 'quoteOrderQty'); + const quoteOrderQty = this.safeNumber (params, 'quoteOrderQty'); const precision = market['precision']['price']; if (quoteOrderQty !== undefined) { request['quoteOrderQty'] = this.decimalToPrecision (quoteOrderQty, TRUNCATE, precision, this.precisionMode); @@ -1911,7 +1927,7 @@ module.exports = class binance extends Exchange { } else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) { stopPriceIsRequired = true; quantityIsRequired = true; - if (market['future']) { + if (market['future'] || market['delivery']) { priceIsRequired = true; } } else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) { @@ -1934,7 +1950,7 @@ module.exports = class binance extends Exchange { stopPriceIsRequired = true; } else if (uppercaseType === 'TRAILING_STOP_MARKET') { quantityIsRequired = true; - const callbackRate = this.safeFloat (params, 'callbackRate'); + const callbackRate = this.safeNumber (params, 'callbackRate'); if (callbackRate === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a callbackRate extra param for a ' + type + ' order'); } @@ -1952,7 +1968,7 @@ module.exports = class binance extends Exchange { request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -2168,10 +2184,15 @@ module.exports = class binance extends Exchange { } } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.fetchBalance (params); - const info = this.safeValue (response, 'info', {}); + const defaultType = this.safeString (this.options, 'defaultType', 'future'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + const options = this.safeValue (this.options, 'fetchPositions', {}); + const defaultMethod = (type === 'delivery') ? 'dapiPrivateGetAccount' : 'fapiPrivateV2GetAccount'; + const method = this.safeString (options, type, defaultMethod); + const response = await this[method] (params); // // futures, delivery // @@ -2214,9 +2235,44 @@ module.exports = class binance extends Exchange { // ] // } // - const positions = this.safeValue2 (info, 'positions', 'userAssets', []); - // todo unify parsePosition/parsePositions - return positions; + // fapiPrivateGetPositionRisk, dapiPrivateGetPositionRisk + // + // [ + // { + // symbol: 'XRPUSD_210625', + // positionAmt: '0', + // entryPrice: '0.00000000', + // markPrice: '0.00000000', + // unRealizedProfit: '0.00000000', + // liquidationPrice: '0', + // leverage: '20', + // maxQty: '500000', + // marginType: 'cross', + // isolatedMargin: '0.00000000', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0', + // isolatedWallet: '0' + // }, + // { + // symbol: 'BTCUSD_210326', + // positionAmt: '1', + // entryPrice: '60665.79999885', + // markPrice: '60696.76856843', + // unRealizedProfit: '0.00000084', + // liquidationPrice: '58034.68208092', + // leverage: '20', + // maxQty: '50', + // marginType: 'isolated', + // isolatedMargin: '0.00008345', + // isAutoAddMargin: 'false', + // positionSide: 'BOTH', + // notionalValue: '0.00164753', + // isolatedWallet: '0.00008261' + // }, + // ] + // + return this.safeValue (response, 'positions', response); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -2354,7 +2410,7 @@ module.exports = class binance extends Exchange { // const fee = { 'currency': earnedCurrency, - 'cost': this.safeFloat (trade, 'serviceChargeAmount'), + 'cost': this.safeNumber (trade, 'serviceChargeAmount'), }; let symbol = undefined; let amount = undefined; @@ -2362,13 +2418,13 @@ module.exports = class binance extends Exchange { let side = undefined; if (tradedCurrencyIsQuote) { symbol = applicantSymbol; - amount = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); - cost = this.safeFloat (trade, 'amount'); + amount = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); + cost = this.safeNumber (trade, 'amount'); side = 'buy'; } else { symbol = tradedCurrency + '/' + earnedCurrency; - amount = this.safeFloat (trade, 'amount'); - cost = this.sum (this.safeFloat (trade, 'transferedAmount'), fee['cost']); + amount = this.safeNumber (trade, 'amount'); + cost = this.sum (this.safeNumber (trade, 'transferedAmount'), fee['cost']); side = 'sell'; } let price = undefined; @@ -2541,8 +2597,8 @@ module.exports = class binance extends Exchange { } } const status = this.parseTransactionStatusByType (this.safeString (transaction, 'status'), type); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'transactionFee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'transactionFee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -2569,6 +2625,151 @@ module.exports = class binance extends Exchange { }; } + parseTransferStatus (status) { + const statuses = { + 'CONFIRMED': 'ok', + }; + return this.safeString (statuses, status, status); + } + + parseTransfer (transfer, currency = undefined) { + // + // transfer + // + // { + // "tranId":13526853623 + // } + // + // fetchTransfers + // + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // } + // + const id = this.safeString (transfer, 'tranId'); + const currencyId = this.safeString (transfer, 'asset'); + const code = this.safeCurrencyCode (currencyId, currency); + const amount = this.safeNumber (transfer, 'amount'); + const type = this.safeString (transfer, 'type'); + let fromAccount = undefined; + let toAccount = undefined; + const typesByAccount = this.safeValue (this.options, 'typesByAccount', {}); + if (type !== undefined) { + const parts = type.split ('_'); + fromAccount = this.safeValue (parts, 0); + toAccount = this.safeValue (parts, 1); + fromAccount = this.safeString (typesByAccount, fromAccount, fromAccount); + toAccount = this.safeString (typesByAccount, toAccount, toAccount); + } + const timestamp = this.safeInteger (transfer, 'timestamp'); + const status = this.parseTransferStatus (this.safeString (transfer, 'status')); + return { + 'info': transfer, + 'id': id, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'currency': code, + 'amount': amount, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': status, + }; + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount, fromAccount); + const toId = this.safeString (accountsByType, toAccount, toAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'asset': currency['id'], + 'amount': this.currencyToPrecision (code, amount), + 'type': type, + }; + const response = await this.sapiPostAssetTransfer (this.extend (request, params)); + // + // { + // "tranId":13526853623 + // } + // + const transfer = this.parseTransfer (response, currency); + return this.extend (transfer, { + 'amount': amount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + }); + } + + async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const defaultType = this.safeString2 (this.options, 'fetchTransfers', 'defaultType', 'spot'); + const fromAccount = this.safeString (params, 'fromAccount', defaultType); + const defaultTo = (fromAccount === 'future') ? 'spot' : 'future'; + const toAccount = this.safeString (params, 'toAccount', defaultTo); + let type = this.safeString (params, 'type'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + if (type === undefined) { + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fromAccount parameter must be one of ' + keys.join (', ')); + } + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' toAccount parameter must be one of ' + keys.join (', ')); + } + type = fromId + '_' + toId; + } + const request = { + 'type': type, + }; + if (since !== undefined) { + request['startTime'] = since; + } + if (limit !== undefined) { + request['size'] = limit; + } + const response = await this.sapiGetAssetTransfer (this.extend (request, params)); + // + // { + // total: 3, + // rows: [ + // { + // timestamp: 1614640878000, + // asset: 'USDT', + // amount: '25', + // type: 'MAIN_UMFUTURE', + // status: 'CONFIRMED', + // tranId: 43000126248 + // }, + // ] + // } + // + const rows = this.safeValue (response, 'rows', []); + return this.parseTransfers (rows, currency, since, limit); + } + async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -2631,7 +2832,7 @@ module.exports = class binance extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (detail[id], 'withdrawFee'); + withdrawFees[code] = this.safeNumber (detail[id], 'withdrawFee'); } return { 'withdraw': withdrawFees, @@ -2678,8 +2879,8 @@ module.exports = class binance extends Exchange { return { 'info': fee, 'symbol': symbol, - 'maker': this.safeFloat (fee, 'maker'), - 'taker': this.safeFloat (fee, 'taker'), + 'maker': this.safeNumber (fee, 'maker'), + 'taker': this.safeNumber (fee, 'taker'), }; } @@ -2741,7 +2942,6 @@ module.exports = class binance extends Exchange { if (api === 'wapi') { url += '.html'; } - const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); if (path === 'historicalTrades') { if (this.apiKey) { headers = { @@ -2750,19 +2950,22 @@ module.exports = class binance extends Exchange { } else { throw new AuthenticationError (this.id + ' historicalTrades endpoint requires `apiKey` credential'); } - } else if (userDataStream) { + } + const userDataStream = (path === 'userDataStream') || (path === 'listenKey'); + if (userDataStream) { if (this.apiKey) { // v1 special case for userDataStream - body = this.urlencode (params); headers = { 'X-MBX-APIKEY': this.apiKey, 'Content-Type': 'application/x-www-form-urlencoded', }; + if (method !== 'GET') { + body = this.urlencode (params); + } } else { throw new AuthenticationError (this.id + ' userDataStream endpoint requires `apiKey` credential'); } - } - if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { + } else if ((api === 'private') || (api === 'sapi') || (api === 'wapi' && path !== 'systemStatus') || (api === 'dapiPrivate') || (api === 'fapiPrivate') || (api === 'fapiPrivateV2')) { this.checkRequiredCredentials (); let query = undefined; const recvWindow = this.safeInteger (this.options, 'recvWindow', 5000); @@ -2794,13 +2997,8 @@ module.exports = class binance extends Exchange { headers['Content-Type'] = 'application/x-www-form-urlencoded'; } } else { - // userDataStream endpoints are public, but POST, PUT, DELETE - // therefore they don't accept URL query arguments - // https://github.com/ccxt/ccxt/issues/5224 - if (!userDataStream) { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } + if (Object.keys (params).length) { + url += '?' + this.urlencode (params); } } return { 'url': url, 'method': method, 'body': body, 'headers': headers }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bit2c.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bit2c.js index a4d60733a..1f58d3f75 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bit2c.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bit2c.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, ExchangeError, InvalidNonce, AuthenticationError, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -155,12 +156,12 @@ module.exports = class bit2c extends Exchange { const currencyId = this.currencyId (code); const uppercase = currencyId.toUpperCase (); if (uppercase in balance) { - account['free'] = this.safeFloat (balance, 'AVAILABLE_' + uppercase); - account['total'] = this.safeFloat (balance, uppercase); + account['free'] = this.safeString (balance, 'AVAILABLE_' + uppercase); + account['total'] = this.safeString (balance, uppercase); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -179,22 +180,22 @@ module.exports = class bit2c extends Exchange { }; const ticker = await this.publicGetExchangesPairTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const averagePrice = this.safeFloat (ticker, 'av'); - const baseVolume = this.safeFloat (ticker, 'a'); + const averagePrice = this.safeNumber (ticker, 'av'); + const baseVolume = this.safeNumber (ticker, 'a'); let quoteVolume = undefined; if (baseVolume !== undefined && averagePrice !== undefined) { quoteVolume = baseVolume * averagePrice; } - const last = this.safeFloat (ticker, 'll'); + const last = this.safeNumber (ticker, 'll'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'h'), + 'bid': this.safeNumber (ticker, 'h'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'l'), + 'ask': this.safeNumber (ticker, 'l'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -276,14 +277,8 @@ module.exports = class bit2c extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -296,7 +291,7 @@ module.exports = class bit2c extends Exchange { } const id = this.safeString (order, 'id'); const status = this.safeString (order, 'status'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -313,12 +308,12 @@ module.exports = class bit2c extends Exchange { 'amount': amount, 'filled': undefined, 'remaining': undefined, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -344,16 +339,16 @@ module.exports = class bit2c extends Exchange { parseTrade (trade, market = undefined) { let timestamp = undefined; let id = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let orderId = undefined; let feeCost = undefined; let side = undefined; const reference = this.safeString (trade, 'reference'); if (reference !== undefined) { timestamp = this.safeTimestamp (trade, 'ticks'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'firstAmount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'firstAmount'); const reference_parts = reference.split ('|'); // reference contains 'pair|orderId|tradeId' if (market === undefined) { const marketId = this.safeString (trade, 'pair'); @@ -371,12 +366,12 @@ module.exports = class bit2c extends Exchange { } else if (side === 1) { side = 'sell'; } - feeCost = this.safeFloat (trade, 'feeAmount'); + feeCost = this.safeNumber (trade, 'feeAmount'); } else { timestamp = this.safeTimestamp (trade, 'date'); id = this.safeString (trade, 'tid'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'amount'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'amount'); side = this.safeValue (trade, 'isBid'); if (side !== undefined) { if (side) { @@ -390,6 +385,9 @@ module.exports = class bit2c extends Exchange { if (market !== undefined) { symbol = market['symbol']; } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, @@ -402,7 +400,7 @@ module.exports = class bit2c extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': { 'cost': feeCost, 'currency': 'NIS', diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbank.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbank.js index d357531d7..c3626b01f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbank.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbank.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -78,21 +79,23 @@ module.exports = class bitbank extends Exchange { }, }, 'markets': { + 'BAT/JPY': { 'id': 'bat_jpy', 'symbol': 'BAT/JPY', 'base': 'BAT', 'quote': 'JPY', 'baseId': 'bat', 'quoteId': 'jpy' }, + 'BAT/BTC': { 'id': 'bat_btc', 'symbol': 'BAT/BTC', 'base': 'BAT', 'quote': 'BTC', 'baseId': 'bat', 'quoteId': 'btc' }, 'BCH/BTC': { 'id': 'bcc_btc', 'symbol': 'BCH/BTC', 'base': 'BCH', 'quote': 'BTC', 'baseId': 'bcc', 'quoteId': 'btc' }, 'BCH/JPY': { 'id': 'bcc_jpy', 'symbol': 'BCH/JPY', 'base': 'BCH', 'quote': 'JPY', 'baseId': 'bcc', 'quoteId': 'jpy' }, + 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, + 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, + 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, + 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, + 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, 'MONA/BTC': { 'id': 'mona_btc', 'symbol': 'MONA/BTC', 'base': 'MONA', 'quote': 'BTC', 'baseId': 'mona', 'quoteId': 'btc' }, 'MONA/JPY': { 'id': 'mona_jpy', 'symbol': 'MONA/JPY', 'base': 'MONA', 'quote': 'JPY', 'baseId': 'mona', 'quoteId': 'jpy' }, 'QTUM/BTC': { 'id': 'qtum_btc', 'symbol': 'QTUM/BTC', 'base': 'QTUM', 'quote': 'BTC', 'baseId': 'qtum', 'quoteId': 'btc' }, 'QTUM/JPY': { 'id': 'qtum_jpy', 'symbol': 'QTUM/JPY', 'base': 'QTUM', 'quote': 'JPY', 'baseId': 'qtum', 'quoteId': 'jpy' }, - 'ETH/BTC': { 'id': 'eth_btc', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', 'baseId': 'eth', 'quoteId': 'btc' }, - 'LTC/BTC': { 'id': 'ltc_btc', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'baseId': 'ltc', 'quoteId': 'btc' }, - 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, - 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, - 'BTC/JPY': { 'id': 'btc_jpy', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY', 'baseId': 'btc', 'quoteId': 'jpy' }, - 'ETH/JPY': { 'id': 'eth_jpy', 'symbol': 'ETH/JPY', 'base': 'ETH', 'quote': 'JPY', 'baseId': 'eth', 'quoteId': 'jpy' }, - 'LTC/JPY': { 'id': 'ltc_jpy', 'symbol': 'LTC/JPY', 'base': 'LTC', 'quote': 'JPY', 'baseId': 'ltc', 'quoteId': 'jpy' }, - 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, 'XLM/BTC': { 'id': 'xlm_btc', 'symbol': 'XLM/BTC', 'base': 'XLM', 'quote': 'BTC', 'baseId': 'xlm', 'quoteId': 'btc' }, + 'XLM/JPY': { 'id': 'xlm_jpy', 'symbol': 'XLM/JPY', 'base': 'XLM', 'quote': 'JPY', 'baseId': 'xlm', 'quoteId': 'jpy' }, + 'XRP/BTC': { 'id': 'xrp_btc', 'symbol': 'XRP/BTC', 'base': 'XRP', 'quote': 'BTC', 'baseId': 'xrp', 'quoteId': 'btc' }, + 'XRP/JPY': { 'id': 'xrp_jpy', 'symbol': 'XRP/JPY', 'base': 'XRP', 'quote': 'JPY', 'baseId': 'xrp', 'quoteId': 'jpy' }, }, 'fees': { 'trading': { @@ -141,16 +144,16 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -160,7 +163,7 @@ module.exports = class bitbank extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -196,18 +199,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; feeCurrency = market['quote']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'transaction_id', 'trade_id'); const takerOrMaker = this.safeString (trade, 'maker_taker'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee_amount_quote'); + const feeCost = this.safeNumber (trade, 'fee_amount_quote'); if (feeCost !== undefined) { fee = { 'currency': feeCurrency, @@ -259,11 +259,11 @@ module.exports = class bitbank extends Exchange { // return [ this.safeInteger (ohlcv, 5), - this.safeFloat (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), + this.safeNumber (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), ]; } @@ -314,14 +314,13 @@ module.exports = class bitbank extends Exchange { const balance = assets[i]; const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'free_amount'), - 'used': this.safeFloat (balance, 'locked_amount'), - 'total': this.safeFloat (balance, 'onhand_amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'free_amount'); + account['used'] = this.safeString (balance, 'locked_amount'); + account['total'] = this.safeString (balance, 'onhand_amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -346,21 +345,15 @@ module.exports = class bitbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (order, 'ordered_at'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'start_amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const average = this.safeFloat (order, 'average_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'start_amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const average = this.safeNumber (order, 'average_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -374,7 +367,7 @@ module.exports = class bitbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, @@ -382,7 +375,7 @@ module.exports = class bitbank extends Exchange { 'trades': undefined, 'fee': undefined, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbay.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbay.js index 4f502e934..760fc7aa2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbay.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitbay.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { InvalidNonce, InsufficientFunds, AuthenticationError, InvalidOrder, ExchangeError, OrderNotFound, AccountSuspended, BadSymbol, OrderImmediatelyFillable, RateLimitExceeded, OnMaintenance, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -278,8 +279,8 @@ module.exports = class bitbay extends Exchange { if (this.inArray (base, fiatCurrencies) || this.inArray (quote, fiatCurrencies)) { fees = this.safeValue (this.fees, 'fiat', {}); } - const maker = this.safeFloat (fees, 'maker'); - const taker = this.safeFloat (fees, 'taker'); + const maker = this.safeNumber (fees, 'maker'); + const taker = this.safeNumber (fees, 'taker'); // todo: check that the limits have ben interpreted correctly // todo: parse the fees page result.push ({ @@ -295,7 +296,7 @@ module.exports = class bitbay extends Exchange { 'taker': taker, 'limits': { 'amount': { - 'min': this.safeFloat (first, 'minOffer'), + 'min': this.safeNumber (first, 'minOffer'), 'max': undefined, }, 'price': { @@ -303,7 +304,7 @@ module.exports = class bitbay extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (second, 'minOffer'), + 'min': this.safeNumber (second, 'minOffer'), 'max': undefined, }, }, @@ -343,16 +344,10 @@ module.exports = class bitbay extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (order, 'time'); - const amount = this.safeFloat (order, 'startAmount'); - const remaining = this.safeFloat (order, 'currentAmount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } + const amount = this.safeNumber (order, 'startAmount'); + const remaining = this.safeNumber (order, 'currentAmount'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'info': order, @@ -365,16 +360,16 @@ module.exports = class bitbay extends Exchange { 'timeInForce': undefined, 'postOnly': postOnly, 'side': this.safeStringLower (order, 'offerType'), - 'price': this.safeFloat (order, 'rate'), + 'price': this.safeNumber (order, 'rate'), 'stopPrice': undefined, 'amount': amount, 'cost': undefined, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'average': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -427,11 +422,11 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lockedFunds'); - account['free'] = this.safeFloat (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'lockedFunds'); + account['free'] = this.safeString (balance, 'availableFunds'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -450,22 +445,22 @@ module.exports = class bitbay extends Exchange { }; const ticker = await this.publicGetIdTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'volume'); - const vwap = this.safeFloat (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max'), + 'low': this.safeNumber (ticker, 'min'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -474,7 +469,7 @@ module.exports = class bitbay extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), + 'average': this.safeNumber (ticker, 'average'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -775,7 +770,7 @@ module.exports = class bitbay extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const change = this.safeValue (item, 'change', {}); - let amount = this.safeFloat (change, 'total'); + let amount = this.safeNumber (change, 'total'); let direction = 'in'; if (amount < 0) { direction = 'out'; @@ -787,9 +782,9 @@ module.exports = class bitbay extends Exchange { const referenceId = this.safeString (item, 'detailId'); const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const fundsBefore = this.safeValue (item, 'fundsBefore', {}); - const before = this.safeFloat (fundsBefore, 'total'); + const before = this.safeNumber (fundsBefore, 'total'); const fundsAfter = this.safeValue (item, 'fundsAfter', {}); - const after = this.safeFloat (fundsAfter, 'total'); + const after = this.safeNumber (fundsAfter, 'total'); return { 'info': item, 'id': id, @@ -846,11 +841,11 @@ module.exports = class bitbay extends Exchange { const first = this.safeValue (ohlcv, 1, {}); return [ this.safeInteger (ohlcv, 0), - this.safeFloat (first, 'o'), - this.safeFloat (first, 'h'), - this.safeFloat (first, 'l'), - this.safeFloat (first, 'c'), - this.safeFloat (first, 'v'), + this.safeNumber (first, 'o'), + this.safeNumber (first, 'h'), + this.safeNumber (first, 'l'), + this.safeNumber (first, 'c'), + this.safeNumber (first, 'v'), ]; } @@ -933,15 +928,12 @@ module.exports = class bitbay extends Exchange { if (wasTaker !== undefined) { takerOrMaker = wasTaker ? 'taker' : 'maker'; } - const price = this.safeFloat2 (trade, 'rate', 'r'); - const amount = this.safeFloat2 (trade, 'amount', 'a'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'commissionValue'); + const priceString = this.safeString2 (trade, 'rate', 'r'); + const amountString = this.safeString2 (trade, 'amount', 'a'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'commissionValue'); const marketId = this.safeString (trade, 'market'); market = this.safeMarket (marketId, market, '-'); const symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex.js index 6d34687ff..1d7643454 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { NotSupported, RateLimitExceeded, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, InvalidNonce, BadSymbol } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -45,6 +46,7 @@ module.exports = class bitfinex extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': '1m', @@ -158,6 +160,7 @@ module.exports = class bitfinex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': true, 'percentage': true, 'maker': 0.1 / 100, @@ -344,6 +347,8 @@ module.exports = class bitfinex extends Exchange { 'No summary found.': ExchangeError, // fetchTradingFees (summary) endpoint can give this vague error message 'Cannot evaluate your available balance, please try again': ExchangeNotAvailable, 'Unknown symbol': BadSymbol, + 'Cannot complete transfer. Exchange balance insufficient.': InsufficientFunds, + 'Momentary balance check. Please wait few seconds and try the transfer again.': ExchangeError, }, 'broad': { 'Invalid X-BFX-SIGNATURE': AuthenticationError, @@ -441,6 +446,15 @@ module.exports = class bitfinex extends Exchange { 'limit': 'exchange limit', 'market': 'exchange market', }, + 'accountsByType': { + 'spot': 'exchange', + 'margin': 'trading', + 'funding': 'deposit', + 'exchange': 'exchange', + 'trading': 'trading', + 'deposit': 'deposit', + 'derivatives': 'trading', + }, }, }); } @@ -454,7 +468,7 @@ module.exports = class bitfinex extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const code = this.safeCurrencyCode (id); - withdraw[code] = this.safeFloat (fees, id); + withdraw[code] = this.safeNumber (fees, id); } return { 'info': response, @@ -490,14 +504,31 @@ module.exports = class bitfinex extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } async fetchMarkets (params = {}) { const ids = await this.publicGetSymbols (); + // + // [ "btcusd", "ltcusd", "ltcbtc" ] + // const details = await this.publicGetSymbolsDetails (); + // + // [ + // { + // "pair":"btcusd", + // "price_precision":5, + // "initial_margin":"10.0", + // "minimum_margin":"5.0", + // "maximum_order_size":"2000.0", + // "minimum_order_size":"0.0002", + // "expiration":"NA", + // "margin":true + // }, + // ] + // const result = []; for (let i = 0; i < details.length; i++) { const market = details[i]; @@ -528,8 +559,8 @@ module.exports = class bitfinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -540,6 +571,7 @@ module.exports = class bitfinex extends Exchange { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -548,6 +580,8 @@ module.exports = class bitfinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': true, + 'type': 'spot', + 'margin': margin, 'precision': precision, 'limits': limits, 'info': market, @@ -572,40 +606,15 @@ module.exports = class bitfinex extends Exchange { return this.decimalToPrecision (price, TRUNCATE, 8, DECIMAL_PLACES); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - const code = market[key]; - const currency = this.safeValue (this.currencies, code); - if (currency !== undefined) { - const precision = this.safeInteger (currency, 'precision'); - if (precision !== undefined) { - cost = parseFloat (this.currencyToPrecision (code, cost)); - } - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); - const types = { - 'exchange': 'exchange', - 'deposit': 'funding', - 'trading': 'margin', - }; - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } const query = this.omit (params, 'type'); const response = await this.privatePostBalances (query); // [ { type: 'deposit', @@ -621,12 +630,16 @@ module.exports = class bitfinex extends Exchange { // amount: '0.0005', // available: '0.0005' } ], const result = { 'info': response }; + const isDerivative = requestedType === 'derivatives'; for (let i = 0; i < response.length; i++) { const balance = response[i]; const type = this.safeString (balance, 'type'); - const parsedType = this.safeString (types, type); - if ((parsedType === balanceType) || (type === balanceType)) { - const currencyId = this.safeString (balance, 'currency'); + const currencyId = this.safeStringLower (balance, 'currency', ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { const code = this.safeCurrencyCode (currencyId); // bitfinex had BCH previously, now it's BAB, but the old // BCH symbol is kept for backward-compatibility @@ -635,13 +648,80 @@ module.exports = class bitfinex extends Exchange { // https://github.com/ccxt/ccxt/issues/4989 if (!(code in result)) { const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currencyId = this.currencyId (code); + const fromCurrencyId = this.convertDerivativesId (currencyId, fromAccount); + const toCurrencyId = this.convertDerivativesId (currencyId, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'walletfrom': fromId, + 'walletto': toId, + }; + const response = await this.privatePostTransfer (this.extend (request, params)); + // [ + // { + // status: 'success', + // message: '0.0001 Bitcoin transfered from Margin to Exchange' + // } + // ] + const result = this.safeValue (response, 0); + const status = this.safeString (result, 'status'); + const message = this.safeString (result, 'message'); + if (message === undefined) { + throw new ExchangeError (this.id + ' transfer failed'); + } + // [{"status":"error","message":"Momentary balance check. Please wait few seconds and try the transfer again."}] + if (status === 'error') { + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + return { + 'info': response, + 'status': status, + 'amount': requestedAmount, + 'code': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'timestamp': undefined, + 'datetime': undefined, + }; + } + + convertDerivativesId (currencyId, type) { + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if ((type !== 'derivatives' && type !== 'trading' && type !== 'margin') && isDerivativeCode) { + currencyId = currencyId.slice (0, start); + } else if (type === 'derivatives' && !isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + return currencyId; } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -680,7 +760,7 @@ module.exports = class bitfinex extends Exchange { } parseTicker (ticker, market = undefined) { - let timestamp = this.safeFloat (ticker, 'timestamp'); + let timestamp = this.safeNumber (ticker, 'timestamp'); if (timestamp !== undefined) { timestamp *= 1000; } @@ -703,16 +783,16 @@ module.exports = class bitfinex extends Exchange { } } } - const last = this.safeFloat (ticker, 'last_price'); + const last = this.safeNumber (ticker, 'last_price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -721,8 +801,8 @@ module.exports = class bitfinex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'mid'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'mid'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -730,24 +810,21 @@ module.exports = class bitfinex extends Exchange { parseTrade (trade, market) { const id = this.safeString (trade, 'tid'); - let timestamp = this.safeFloat (trade, 'timestamp'); + let timestamp = this.safeNumber (trade, 'timestamp'); if (timestamp !== undefined) { timestamp = parseInt (timestamp) * 1000; } const type = undefined; const side = this.safeStringLower (trade, 'type'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; if ('fee_amount' in trade) { - const feeCost = -this.safeFloat (trade, 'fee_amount'); + const feeCost = -this.safeNumber (trade, 'fee_amount'); const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { @@ -862,6 +939,30 @@ module.exports = class bitfinex extends Exchange { } parseOrder (order, market = undefined) { + // + // { + // id: 57334010955, + // cid: 1611584840966, + // cid_date: null, + // gid: null, + // symbol: 'ltcbtc', + // exchange: null, + // price: '0.0042125', + // avg_execution_price: '0.0042097', + // side: 'sell', + // type: 'exchange market', + // timestamp: '1611584841.0', + // is_live: false, + // is_cancelled: false, + // is_hidden: 0, + // oco_order: 0, + // was_forced: false, + // original_amount: '0.205176', + // remaining_amount: '0.0', + // executed_amount: '0.205176', + // src: 'web' + // } + // const side = this.safeString (order, 'side'); const open = this.safeValue (order, 'is_live'); const canceled = this.safeValue (order, 'is_cancelled'); @@ -873,30 +974,17 @@ module.exports = class bitfinex extends Exchange { } else { status = 'closed'; } - let symbol = undefined; - if (market === undefined) { - const marketId = this.safeStringUpper (order, 'symbol'); - if (marketId !== undefined) { - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - } - } - } - if (market !== undefined) { - symbol = market['symbol']; - } - let orderType = order['type']; + const marketId = this.safeStringUpper (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market); + let orderType = this.safeString (order, 'type', ''); const exchange = orderType.indexOf ('exchange ') >= 0; if (exchange) { const parts = order['type'].split (' '); orderType = parts[1]; } - let timestamp = this.safeFloat (order, 'timestamp'); - if (timestamp !== undefined) { - timestamp = parseInt (timestamp) * 1000; - } + const timestamp = this.safeTimestamp (order, 'timestamp'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -908,17 +996,17 @@ module.exports = class bitfinex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': side, - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_execution_price'), - 'amount': this.safeFloat (order, 'original_amount'), - 'remaining': this.safeFloat (order, 'remaining_amount'), - 'filled': this.safeFloat (order, 'executed_amount'), + 'average': this.safeNumber (order, 'avg_execution_price'), + 'amount': this.safeNumber (order, 'original_amount'), + 'remaining': this.safeNumber (order, 'remaining_amount'), + 'filled': this.safeNumber (order, 'executed_amount'), 'status': status, 'fee': undefined, 'cost': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -973,11 +1061,11 @@ module.exports = class bitfinex extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -1125,11 +1213,11 @@ module.exports = class bitfinex extends Exchange { // "timestamp_created": "1561716066.0" // } // - let timestamp = this.safeFloat (transaction, 'timestamp_created'); + let timestamp = this.safeNumber (transaction, 'timestamp_created'); if (timestamp !== undefined) { timestamp = parseInt (timestamp * 1000); } - let updated = this.safeFloat (transaction, 'timestamp'); + let updated = this.safeNumber (transaction, 'timestamp'); if (updated !== undefined) { updated = parseInt (updated * 1000); } @@ -1137,7 +1225,7 @@ module.exports = class bitfinex extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const type = this.safeStringLower (transaction, 'type'); // DEPOSIT or WITHDRAWAL const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -1150,7 +1238,7 @@ module.exports = class bitfinex extends Exchange { 'address': this.safeString (transaction, 'address'), // todo: this is actually the tag for XRP transfers (the address is missing) 'tag': undefined, // refix it properly for the tag from description 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -1204,7 +1292,7 @@ module.exports = class bitfinex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex2.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex2.js index b47da9faf..9313f2025 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex2.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitfinex2.js @@ -286,6 +286,15 @@ module.exports = class bitfinex2 extends bitfinex { 'JPY': 'JPY', 'GBP': 'GBP', }, + // actually the correct names unlike the v1 + // we don't want to extend this with accountsByType in v1 + 'v2AccountsByType': { + 'spot': 'exchange', + 'exchange': 'exchange', + 'funding': 'funding', + 'margin': 'margin', + 'derivatives': 'margin', + }, }, 'exceptions': { 'exact': { @@ -367,8 +376,8 @@ module.exports = class bitfinex2 extends bitfinex { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -379,6 +388,7 @@ module.exports = class bitfinex2 extends bitfinex { 'min': limits['amount']['min'] * limits['price']['min'], 'max': undefined, }; + const margin = this.safeValue (market, 'margin'); result.push ({ 'id': id, 'symbol': symbol, @@ -393,6 +403,7 @@ module.exports = class bitfinex2 extends bitfinex { 'type': type, 'swap': false, 'spot': spot, + 'margin': margin, 'futures': futures, }); } @@ -505,7 +516,7 @@ module.exports = class bitfinex2 extends bitfinex { const ids = this.safeValue (response, 0, []); const result = {}; for (let i = 0; i < ids.length; i++) { - let id = ids[i]; + const id = ids[i]; const code = this.safeCurrencyCode (id); const label = this.safeValue (indexed['label'], id, []); const name = this.safeString (label, 1); @@ -513,13 +524,14 @@ module.exports = class bitfinex2 extends bitfinex { const type = this.safeString (pool, 1); const feeValues = this.safeValue (indexed['fees'], id, []); const fees = this.safeValue (feeValues, 1, []); - const fee = this.safeFloat (fees, 1); + const fee = this.safeNumber (fees, 1); + const undl = this.safeValue (indexed['undl'], id, []); const precision = 8; // default precision, todo: fix "magic constants" - id = 'f' + id; + const fid = 'f' + id; result[code] = { - 'id': id, + 'id': fid, 'code': code, - 'info': [ id, label, pool, feeValues ], + 'info': [ id, label, pool, feeValues, undl ], 'type': type, 'name': name, 'active': true, @@ -550,40 +562,117 @@ module.exports = class bitfinex2 extends bitfinex { async fetchBalance (params = {}) { // this api call does not return the 'used' amount - use the v1 version instead (which also returns zero balances) + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 await this.loadMarkets (); - const response = await this.privatePostAuthRWallets (params); - const balanceType = this.safeString (params, 'type', 'exchange'); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const requestedType = this.safeString (params, 'type', 'exchange'); + const accountType = this.safeString (accountsByType, requestedType); + if (accountType === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' fetchBalance type parameter must be one of ' + keys.join (', ')); + } + const isDerivative = requestedType === 'derivatives'; + const query = this.omit (params, 'type'); + const response = await this.privatePostAuthRWallets (query); const result = { 'info': response }; - for (let b = 0; b < response.length; b++) { - const balance = response[b]; - const accountType = balance[0]; - let currency = balance[1]; - const total = balance[2]; - const available = balance[4]; - if (accountType === balanceType) { - if (currency[0] === 't') { - currency = currency.slice (1); - } - const code = this.safeCurrencyCode (currency); + for (let i = 0; i < response.length; i++) { + const balance = response[i]; + const type = this.safeString (balance, 0); + const currencyId = this.safeStringLower (balance, 1, ''); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'f0'; + // this will only filter the derivative codes if the requestedType is 'derivatives' + const derivativeCondition = (!isDerivative || isDerivativeCode); + if ((accountType === type) && derivativeCondition) { + const code = this.safeCurrencyCode (currencyId); const account = this.account (); - // do not fill in zeroes and missing values in the parser - // rewrite and unify the following to use the unified parseBalance - account['total'] = total; - if (!available) { - if (available === 0) { - account['free'] = 0; - account['used'] = total; - } else { - account['free'] = total; - } - } else { - account['free'] = available; - account['used'] = account['total'] - account['free']; - } + account['total'] = this.safeString (balance, 2); + account['free'] = this.safeString (balance, 4); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // transferring between derivatives wallet and regular wallet is not documented in their API + // however we support it in CCXT (from just looking at web inspector) + await this.loadMarkets (); + const accountsByType = this.safeValue (this.options, 'v2AccountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsByType, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' transfer toAccount must be one of ' + keys.join (', ')); + } + const currency = this.currency (code); + const fromCurrencyId = this.convertDerivativesId (currency, fromAccount); + const toCurrencyId = this.convertDerivativesId (currency, toAccount); + const requestedAmount = this.currencyToPrecision (code, amount); + // this request is slightly different from v1 fromAccount -> from + const request = { + 'amount': requestedAmount, + 'currency': fromCurrencyId, + 'currency_to': toCurrencyId, + 'from': fromId, + 'to': toId, + }; + const response = await this.privatePostAuthWTransfer (this.extend (request, params)); + // [1616451183763,"acc_tf",null,null,[1616451183763,"exchange","margin",null,"UST","UST",null,1],null,"SUCCESS","1.0 Tether USDt transfered from Exchange to Margin"] + const timestamp = this.safeInteger (response, 0); + // ["error",10001,"Momentary balance check. Please wait few seconds and try the transfer again."] + const error = this.safeString (response, 0); + if (error === 'error') { + const message = this.safeString (response, 2, ''); + // same message as in v1 + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + throw new ExchangeError (this.id + ' ' + message); + } + const info = this.safeValue (response, 4); + const fromResponse = this.safeString (info, 1); + const toResponse = this.safeString (info, 2); + const toCode = this.safeCurrencyCode (this.safeString (info, 5)); + const success = this.safeString (response, 6); + const status = (success === 'SUCCESS') ? 'ok' : undefined; + return { + 'info': response, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'status': status, + 'amount': requestedAmount, + 'code': toCode, + 'fromAccount': fromResponse, + 'toAccount': toResponse, + }; + } + + convertDerivativesId (currency, type) { + // there is a difference between this and the v1 api, namely trading wallet is called margin in v2 + // { + // id: 'fUSTF0', + // code: 'USTF0', + // info: [ 'USTF0', [], [], [], [ 'USTF0', 'UST' ] ], + const info = this.safeValue (currency, 'info'); + const transferId = this.safeString (info, 0); + const underlying = this.safeValue (info, 4, []); + let currencyId = undefined; + if (type === 'derivatives') { + currencyId = this.safeString (underlying, 0, transferId); + const start = currencyId.length - 2; + const isDerivativeCode = currencyId.slice (start) === 'F0'; + if (!isDerivativeCode) { + currencyId = currencyId + 'F0'; + } + } else if (type !== 'margin') { + currencyId = this.safeString (underlying, 1, transferId); + } else { + currencyId = transferId; + } + return currencyId; } async fetchOrder (id, symbol = undefined, params = {}) { @@ -613,9 +702,10 @@ module.exports = class bitfinex2 extends bitfinex { const priceIndex = (fullRequest['precision'] === 'R0') ? 1 : 0; for (let i = 0; i < orderbook.length; i++) { const order = orderbook[i]; - const price = order[priceIndex]; - const amount = Math.abs (order[2]); - const side = (order[2] > 0) ? 'bids' : 'asks'; + const price = this.safeNumber (order, priceIndex); + const signedAmount = this.safeNumber (order, 2); + const amount = Math.abs (signedAmount); + const side = (signedAmount > 0) ? 'bids' : 'asks'; result[side].push ([ price, amount ]); } result['bids'] = this.sortBy (result['bids'], 0, true); @@ -630,26 +720,26 @@ module.exports = class bitfinex2 extends bitfinex { symbol = market['symbol']; } const length = ticker.length; - const last = ticker[length - 4]; + const last = this.safeNumber (ticker, length - 4); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': ticker[length - 2], - 'low': ticker[length - 1], - 'bid': ticker[length - 10], + 'high': this.safeNumber (ticker, length - 2), + 'low': this.safeNumber (ticker, length - 1), + 'bid': this.safeNumber (ticker, length - 10), 'bidVolume': undefined, - 'ask': ticker[length - 8], + 'ask': this.safeNumber (ticker, length - 8), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': ticker[length - 6], - 'percentage': ticker[length - 5] * 100, + 'change': this.safeNumber (ticker, length - 6), + 'percentage': this.safeNumber (ticker, length - 5) * 100, 'average': undefined, - 'baseVolume': ticker[length - 3], + 'baseVolume': this.safeNumber (ticker, length - 3), 'quoteVolume': undefined, 'info': ticker, }; @@ -738,12 +828,12 @@ module.exports = class bitfinex2 extends bitfinex { // const tradeLength = trade.length; const isPrivate = (tradeLength > 5); - const id = trade[0].toString (); + const id = this.safeString (trade, 0); const amountIndex = isPrivate ? 4 : 2; - let amount = trade[amountIndex]; + let amount = this.safeNumber (trade, amountIndex); let cost = undefined; const priceIndex = isPrivate ? 5 : 3; - const price = trade[priceIndex]; + const price = this.safeNumber (trade, priceIndex); let side = undefined; let orderId = undefined; let takerOrMaker = undefined; @@ -751,7 +841,7 @@ module.exports = class bitfinex2 extends bitfinex { let fee = undefined; let symbol = undefined; const timestampIndex = isPrivate ? 2 : 1; - const timestamp = trade[timestampIndex]; + const timestamp = this.safeInteger (trade, timestampIndex); if (isPrivate) { const marketId = trade[1]; if (marketId in this.markets_by_id) { @@ -760,10 +850,12 @@ module.exports = class bitfinex2 extends bitfinex { } else { symbol = this.parseSymbol (marketId); } - orderId = trade[3].toString (); - takerOrMaker = (trade[8] === 1) ? 'maker' : 'taker'; - let feeCost = trade[9]; - const feeCurrency = this.safeCurrencyCode (trade[10]); + orderId = this.safeString (trade, 3); + const maker = this.safeInteger (trade, 8); + takerOrMaker = (maker === 1) ? 'maker' : 'taker'; + let feeCost = this.safeNumber (trade, 9); + const feeCurrencyId = this.safeString (trade, 10); + const feeCurrency = this.safeCurrencyCode (feeCurrencyId); if (feeCost !== undefined) { feeCost = -feeCost; if (symbol in this.markets) { @@ -904,10 +996,10 @@ module.exports = class bitfinex2 extends bitfinex { // https://github.com/ccxt/ccxt/issues/6686 // const timestamp = this.safeTimestamp (order, 5); const timestamp = this.safeInteger (order, 5); - const remaining = Math.abs (this.safeFloat (order, 6)); - const amount = Math.abs (this.safeFloat (order, 7)); - const filled = amount - remaining; - const side = (order[7] < 0) ? 'sell' : 'buy'; + const remaining = Math.abs (this.safeNumber (order, 6)); + const signedAmount = this.safeNumber (order, 7); + const amount = Math.abs (signedAmount); + const side = (signedAmount < 0) ? 'sell' : 'buy'; const orderType = this.safeString (order, 8); const type = this.safeString (this.safeValue (this.options, 'exchangeTypes'), orderType); let status = undefined; @@ -916,11 +1008,10 @@ module.exports = class bitfinex2 extends bitfinex { const parts = statusString.split (' @ '); status = this.parseOrderStatus (this.safeString (parts, 0)); } - const price = this.safeFloat (order, 16); - const average = this.safeFloat (order, 17); - const cost = price * filled; + const price = this.safeNumber (order, 16); + const average = this.safeNumber (order, 17); const clientOrderId = this.safeString (order, 2); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -935,14 +1026,14 @@ module.exports = class bitfinex2 extends bitfinex { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -959,11 +1050,11 @@ module.exports = class bitfinex2 extends bitfinex { if ((orderType === 'LIMIT') || (orderType === 'EXCHANGE LIMIT')) { request['price'] = this.numberToString (price); } else if ((orderType === 'STOP') || (orderType === 'EXCHANGE STOP')) { - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'STOP LIMIT') || (orderType === 'EXCHANGE STOP LIMIT')) { - const priceAuxLimit = this.safeFloat (params, 'price_aux_limit'); - let stopPrice = this.safeFloat (params, 'stopPrice'); + const priceAuxLimit = this.safeNumber (params, 'price_aux_limit'); + let stopPrice = this.safeNumber (params, 'stopPrice'); if (priceAuxLimit === undefined) { if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter or a price_aux_limit parameter for a ' + orderType + ' order'); @@ -978,9 +1069,9 @@ module.exports = class bitfinex2 extends bitfinex { } request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'TRAILING STOP') || (orderType === 'EXCHANGE TRAILING STOP')) { - const priceTrailing = this.safeFloat (params, 'price_trailing'); + const priceTrailing = this.safeNumber (params, 'price_trailing'); request['price_trailing'] = this.numberToString (priceTrailing); - const stopPrice = this.safeFloat (params, 'stopPrice', price); + const stopPrice = this.safeNumber (params, 'stopPrice', price); request['price'] = this.numberToString (stopPrice); } else if ((orderType === 'FOK') || (orderType === 'EXCHANGE FOK') || (orderType === 'IOC') || (orderType === 'EXCHANGE IOC')) { request['price'] = this.numberToString (price); @@ -1312,11 +1403,11 @@ module.exports = class bitfinex2 extends bitfinex { if (currency !== undefined) { code = currency['code']; } - feeCost = this.safeFloat (data, 8); + feeCost = this.safeNumber (data, 8); if (feeCost !== undefined) { feeCost = -feeCost; } - amount = this.safeFloat (data, 5); + amount = this.safeNumber (data, 5); id = this.safeValue (data, 0); status = 'ok'; if (id === 0) { @@ -1330,7 +1421,7 @@ module.exports = class bitfinex2 extends bitfinex { timestamp = this.safeInteger (transaction, 5); updated = this.safeInteger (transaction, 6); status = this.parseTransactionStatus (this.safeString (transaction, 9)); - amount = this.safeFloat (transaction, 12); + amount = this.safeNumber (transaction, 12); if (amount !== undefined) { if (amount < 0) { type = 'withdrawal'; @@ -1338,7 +1429,7 @@ module.exports = class bitfinex2 extends bitfinex { type = 'deposit'; } } - feeCost = this.safeFloat (transaction, 13); + feeCost = this.safeNumber (transaction, 13); if (feeCost !== undefined) { feeCost = -feeCost; } @@ -1466,7 +1557,7 @@ module.exports = class bitfinex2 extends bitfinex { }); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privatePostPositions (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitflyer.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitflyer.js index f9c19b59a..911cb61f0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitflyer.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitflyer.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -185,11 +186,11 @@ module.exports = class bitflyer extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'amount'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -208,16 +209,16 @@ module.exports = class bitflyer extends Exchange { }; const ticker = await this.publicGetGetticker (this.extend (request, params)); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'ltp'); + const last = this.safeNumber (ticker, 'ltp'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'best_bid'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -227,7 +228,7 @@ module.exports = class bitflyer extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_by_product'), + 'baseVolume': this.safeNumber (ticker, 'volume_by_product'), 'quoteVolume': undefined, 'info': ticker, }; @@ -251,14 +252,11 @@ module.exports = class bitflyer extends Exchange { order = this.safeString (trade, 'child_order_acceptance_id'); } const timestamp = this.parse8601 (this.safeString (trade, 'exec_date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -334,18 +332,17 @@ module.exports = class bitflyer extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'child_order_date')); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'outstanding_size'); - const filled = this.safeFloat (order, 'executed_size'); - const price = this.safeFloat (order, 'price'); - const cost = price * filled; + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'outstanding_size'); + const filled = this.safeNumber (order, 'executed_size'); + const price = this.safeNumber (order, 'price'); const status = this.parseOrderStatus (this.safeString (order, 'child_order_state')); const type = this.safeStringLower (order, 'child_order_type'); const side = this.safeStringLower (order, 'side'); const marketId = this.safeString (order, 'product_code'); const symbol = this.safeSymbol (marketId, market); let fee = undefined; - const feeCost = this.safeFloat (order, 'total_commission'); + const feeCost = this.safeNumber (order, 'total_commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -354,7 +351,7 @@ module.exports = class bitflyer extends Exchange { }; } const id = this.safeString (order, 'child_order_acceptance_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -369,14 +366,14 @@ module.exports = class bitflyer extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrders (symbol = undefined, since = undefined, limit = 100, params = {}) { @@ -439,7 +436,7 @@ module.exports = class bitflyer extends Exchange { return this.parseTrades (response, market, since, limit); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { if (symbols === undefined) { throw new ArgumentsRequired (this.id + ' fetchPositions() requires a `symbols` argument, exactly one symbol in an array'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitforex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitforex.js index 8fa337979..0dfebbef7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitforex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitforex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, DDoSProtection, PermissionDenied, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -259,7 +260,7 @@ module.exports = class bitforex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -295,14 +296,11 @@ module.exports = class bitforex extends Exchange { const timestamp = this.safeInteger (trade, 'time'); const id = this.safeString (trade, 'tid'); const orderId = undefined; - const amount = this.safeFloat (trade, 'amount'); - const price = this.safeFloat (trade, 'price'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const sideId = this.safeInteger (trade, 'direction'); const side = this.parseSide (sideId); return { @@ -345,12 +343,12 @@ module.exports = class bitforex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'active'); - account['total'] = this.safeFloat (balance, 'fix'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'active'); + account['total'] = this.safeString (balance, 'fix'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTicker (symbol, params = {}) { @@ -366,21 +364,21 @@ module.exports = class bitforex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (data, 'high'), - 'low': this.safeFloat (data, 'low'), - 'bid': this.safeFloat (data, 'buy'), + 'high': this.safeNumber (data, 'high'), + 'low': this.safeNumber (data, 'low'), + 'bid': this.safeNumber (data, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (data, 'sell'), + 'ask': this.safeNumber (data, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (data, 'last'), - 'last': this.safeFloat (data, 'last'), + 'close': this.safeNumber (data, 'last'), + 'last': this.safeNumber (data, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (data, 'vol'), + 'baseVolume': this.safeNumber (data, 'vol'), 'quoteVolume': undefined, 'info': response, }; @@ -400,11 +398,11 @@ module.exports = class bitforex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'vol'), ]; } @@ -472,26 +470,24 @@ module.exports = class bitforex extends Exchange { parseOrder (order, market = undefined) { const id = this.safeString (order, 'orderId'); - const timestamp = this.safeFloat (order, 'createTime'); - const lastTradeTimestamp = this.safeFloat (order, 'lastTime'); + const timestamp = this.safeNumber (order, 'createTime'); + const lastTradeTimestamp = this.safeNumber (order, 'lastTime'); const symbol = market['symbol']; const sideId = this.safeInteger (order, 'tradeType'); const side = this.parseSide (sideId); const type = undefined; - const price = this.safeFloat (order, 'orderPrice'); - const average = this.safeFloat (order, 'avgPrice'); - const amount = this.safeFloat (order, 'orderAmount'); - const filled = this.safeFloat (order, 'dealAmount'); - const remaining = amount - filled; + const price = this.safeNumber (order, 'orderPrice'); + const average = this.safeNumber (order, 'avgPrice'); + const amount = this.safeNumber (order, 'orderAmount'); + const filled = this.safeNumber (order, 'dealAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderState')); - const cost = filled * price; const feeSide = (side === 'buy') ? 'base' : 'quote'; const feeCurrency = market[feeSide]; const fee = { - 'cost': this.safeFloat (order, 'tradeFee'), + 'cost': this.safeNumber (order, 'tradeFee'), 'currency': feeCurrency, }; - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -505,16 +501,15 @@ module.exports = class bitforex extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitget.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitget.js index 3c9581955..75e458fe0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitget.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitget.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -793,7 +794,7 @@ module.exports = class bitget extends Exchange { let swap = false; const baseId = this.safeString2 (market, 'base_currency', 'coin'); const quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { marketType = 'swap'; spot = false; @@ -811,7 +812,7 @@ module.exports = class bitget extends Exchange { 'amount': parseFloat ('1e-' + sizeIncrement), 'price': parseFloat ('1e-' + tickSize), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const status = this.safeString (market, 'status'); let active = undefined; if (status !== undefined) { @@ -1068,26 +1069,26 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat2 (ticker, 'last', 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'last', 'close'); + const open = this.safeNumber (ticker, 'open'); let bidVolume = undefined; let askVolume = undefined; let bid = this.safeValue (ticker, 'bid'); if (bid === undefined) { - bid = this.safeFloat (ticker, 'best_bid'); + bid = this.safeNumber (ticker, 'best_bid'); } else { - bidVolume = this.safeFloat (bid, 1); - bid = this.safeFloat (bid, 0); + bidVolume = this.safeNumber (bid, 1); + bid = this.safeNumber (bid, 0); } let ask = this.safeValue (ticker, 'ask'); if (ask === undefined) { - ask = this.safeFloat (ticker, 'best_ask'); + ask = this.safeNumber (ticker, 'best_ask'); } else { - askVolume = this.safeFloat (ask, 1); - ask = this.safeFloat (ask, 0); + askVolume = this.safeNumber (ask, 1); + ask = this.safeNumber (ask, 0); } - const baseVolume = this.safeFloat2 (ticker, 'amount', 'volume_24h'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber2 (ticker, 'amount', 'volume_24h'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; @@ -1101,8 +1102,8 @@ module.exports = class bitget extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -1337,9 +1338,12 @@ module.exports = class bitget extends Exchange { } let timestamp = this.safeInteger (trade, 'created_at'); timestamp = this.safeInteger2 (trade, 'timestamp', 'ts', timestamp); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'filled_amount', 'order_qty'); - amount = this.safeFloat2 (trade, 'size', 'amount', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'filled_amount', 'order_qty'); + amountString = this.safeString2 (trade, 'size', 'amount', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -1358,18 +1362,13 @@ module.exports = class bitget extends Exchange { type = this.parseOrderType (side); side = this.parseOrderSide (side); } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - let feeCost = this.safeFloat (trade, 'fee'); - if (feeCost === undefined) { - feeCost = this.safeFloat (trade, 'filled_fees'); + let feeCostString = this.safeString (trade, 'fee'); + if (feeCostString === undefined) { + feeCostString = this.safeString (trade, 'filled_fees'); } else { - feeCost = -feeCost; + feeCostString = (feeCostString[0] === '-') ? feeCostString.slice (1) : feeCostString; } + const feeCost = this.parseNumber (feeCostString); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -1492,23 +1491,23 @@ module.exports = class bitget extends Exchange { const volumeIndex = this.safeString (volume, market['type'], 'amount'); return [ this.safeInteger (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, bitget will return base volume in the 7th element for future markets ]; } else { const volumeIndex = this.safeValue (volume, market['type'], 6); return [ this.safeInteger (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, volumeIndex), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, volumeIndex), // Base Volume ]; } } @@ -1610,13 +1609,13 @@ module.exports = class bitget extends Exchange { } const type = this.safeValue (balance, 'type'); if (type === 'trade') { - result[code]['free'] = this.safeFloat (balance, 'balance'); + result[code]['free'] = this.safeString (balance, 'balance'); } else if ((type === 'frozen') || (type === 'lock')) { - const used = this.safeFloat (result[code], 'used'); - result[code]['used'] = this.sum (used, this.safeFloat (balance, 'balance')); + const used = this.safeString (result[code], 'used'); + result[code]['used'] = Precise.stringAdd (used, this.safeString (balance, 'balance')); } } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseSwapBalance (response) { @@ -1640,11 +1639,11 @@ module.exports = class bitget extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeString (balance, 'equity'); + account['free'] = this.safeString (balance, 'total_avail_balance'); result[symbol] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchAccounts (params = {}) { @@ -1921,26 +1920,13 @@ module.exports = class bitget extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let amount = this.safeFloat2 (order, 'amount', 'size'); - const filled = this.safeFloat2 (order, 'filled_amount', 'filled_qty'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - amount = Math.max (amount, filled); - remaining = Math.max (0, amount - filled); - } - } - if (type === 'market') { - remaining = 0; - } - const cost = this.safeFloat (order, 'filled_cash_amount'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); - if ((average === undefined) && (filled !== undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } + const amount = this.safeNumber2 (order, 'amount', 'size'); + const filled = this.safeNumber2 (order, 'filled_amount', 'filled_qty'); + const cost = this.safeNumber (order, 'filled_cash_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'price_avg'); const status = this.parseOrderStatus (this.safeString2 (order, 'state', 'status')); - const feeCost = this.safeFloat2 (order, 'filled_fees', 'fee'); + const feeCost = this.safeNumber2 (order, 'filled_fees', 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -1950,7 +1936,7 @@ module.exports = class bitget extends Exchange { }; } const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1968,11 +1954,11 @@ module.exports = class bitget extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -2019,7 +2005,7 @@ module.exports = class bitget extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'amount'); + let cost = this.safeNumber (params, 'amount'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2569,12 +2555,12 @@ module.exports = class bitget extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const txid = this.safeString (transaction, 'tx_hash'); const timestamp = this.safeInteger (transaction, 'created_at'); const updated = this.safeInteger (transaction, 'updated_at'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -2764,7 +2750,7 @@ module.exports = class bitget extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.swapGetPositionAllPosition (params); // diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bithumb.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bithumb.js index ef4e7d479..051562718 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bithumb.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bithumb.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, AuthenticationError, BadRequest, PermissionDenied, InvalidAddress, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); const { DECIMAL_PLACES, SIGNIFICANT_DIGITS, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -198,12 +199,12 @@ module.exports = class bithumb extends Exchange { const account = this.account (); const currency = this.currency (code); const lowerCurrencyId = this.safeStringLower (currency, 'id'); - account['total'] = this.safeFloat (balances, 'total_' + lowerCurrencyId); - account['used'] = this.safeFloat (balances, 'in_use_' + lowerCurrencyId); - account['free'] = this.safeFloat (balances, 'available_' + lowerCurrencyId); + account['total'] = this.safeString (balances, 'total_' + lowerCurrencyId); + account['used'] = this.safeString (balances, 'in_use_' + lowerCurrencyId); + account['free'] = this.safeString (balances, 'available_' + lowerCurrencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -265,8 +266,8 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const open = this.safeFloat (ticker, 'opening_price'); - const close = this.safeFloat (ticker, 'closing_price'); + const open = this.safeNumber (ticker, 'opening_price'); + const close = this.safeNumber (ticker, 'closing_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -277,18 +278,18 @@ module.exports = class bithumb extends Exchange { } average = this.sum (open, close) / 2; } - const baseVolume = this.safeFloat (ticker, 'units_traded_24H'); - const quoteVolume = this.safeFloat (ticker, 'acc_trade_value_24H'); + const baseVolume = this.safeNumber (ticker, 'units_traded_24H'); + const quoteVolume = this.safeNumber (ticker, 'acc_trade_value_24H'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -394,11 +395,11 @@ module.exports = class bithumb extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -488,18 +489,16 @@ module.exports = class bithumb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'units_traded', 'units'); - let cost = this.safeFloat (trade, 'total'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'units_traded', 'units'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.commonCurrencyCode (feeCurrencyId); @@ -702,14 +701,14 @@ module.exports = class bithumb extends Exchange { const sideProperty = this.safeValue2 (order, 'type', 'side'); const side = (sideProperty === 'bid') ? 'buy' : 'sell'; const status = this.parseOrderStatus (this.safeString (order, 'order_status')); - let price = this.safeFloat2 (order, 'order_price', 'price'); + let price = this.safeNumber2 (order, 'order_price', 'price'); let type = 'limit'; if (price === 0) { price = undefined; type = 'market'; } - const amount = this.safeFloat2 (order, 'order_qty', 'units'); - let remaining = this.safeFloat (order, 'units_remaining'); + const amount = this.safeNumber2 (order, 'order_qty', 'units'); + let remaining = this.safeNumber (order, 'units_remaining'); if (remaining === undefined) { if (status === 'closed') { remaining = 0; @@ -728,65 +727,14 @@ module.exports = class bithumb extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let filled = undefined; - let cost = undefined; - let average = undefined; const id = this.safeString (order, 'order_id'); - const rawTrades = this.safeValue (order, 'contract'); - let trades = undefined; - let fee = undefined; - let fees = undefined; - let feesByCurrency = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'side': side, - 'symbol': symbol, - 'order': id, - }); - filled = 0; - feesByCurrency = {}; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - filled = this.sum (filled, trade['amount']); - cost = this.sum (cost, trade['cost']); - const tradeFee = trade['fee']; - const feeCurrency = tradeFee['currency']; - if (feeCurrency in feesByCurrency) { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': this.sum (feesByCurrency[feeCurrency]['cost'], tradeFee['cost']), - }; - } else { - feesByCurrency[feeCurrency] = { - 'currency': feeCurrency, - 'cost': tradeFee['cost'], - }; - } - } - const feeCurrencies = Object.keys (feesByCurrency); - const feeCurrenciesLength = feeCurrencies.length; - if (feeCurrenciesLength > 1) { - fees = []; - for (let i = 0; i < feeCurrencies.length; i++) { - const feeCurrency = feeCurrencies[i]; - fees.push (feesByCurrency[feeCurrency]); - } - } else { - fee = this.safeValue (feesByCurrency, feeCurrencies[0]); - } - if (filled !== 0) { - average = cost / filled; - } - } - if (amount !== undefined) { - if ((filled === undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if ((remaining === undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const result = { + const rawTrades = this.safeValue (order, 'contract', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'side': side, + 'symbol': symbol, + 'order': id, + }); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -801,20 +749,14 @@ module.exports = class bithumb extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'average': average, - 'filled': filled, + 'cost': undefined, + 'average': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': trades, - }; - if (fee !== undefined) { - result['fee'] = fee; - } else if (fees !== undefined) { - result['fees'] = fees; - } - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmart.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmart.js index 4ad47118a..9ec806c6e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmart.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmart.js @@ -435,16 +435,16 @@ module.exports = class bitmart extends Exchange { // const pricePrecision = this.safeInteger (market, 'price_max_precision'); const precision = { - 'amount': this.safeFloat (market, 'base_min_size'), + 'amount': this.safeNumber (market, 'base_min_size'), 'price': parseFloat (this.decimalToPrecision (Math.pow (10, -pricePrecision), ROUND, 10)), }; - const minBuyCost = this.safeFloat (market, 'min_buy_amount'); - const minSellCost = this.safeFloat (market, 'min_sell_amount'); + const minBuyCost = this.safeNumber (market, 'min_buy_amount'); + const minSellCost = this.safeNumber (market, 'min_sell_amount'); const minCost = Math.max (minBuyCost, minSellCost); const limits = { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': { 'min': undefined, @@ -554,16 +554,16 @@ module.exports = class bitmart extends Exchange { // // the docs are wrong: https://github.com/ccxt/ccxt/issues/5612 // - const amountPrecision = this.safeFloat (contract, 'vol_unit'); - const pricePrecision = this.safeFloat (contract, 'price_unit'); + const amountPrecision = this.safeNumber (contract, 'vol_unit'); + const pricePrecision = this.safeNumber (contract, 'price_unit'); const precision = { 'amount': amountPrecision, 'price': pricePrecision, }; const limits = { 'amount': { - 'min': this.safeFloat (contract, 'min_vol'), - 'max': this.safeFloat (contract, 'max_vol'), + 'min': this.safeNumber (contract, 'min_vol'), + 'max': this.safeNumber (contract, 'max_vol'), }, 'price': { 'min': undefined, @@ -586,8 +586,8 @@ module.exports = class bitmart extends Exchange { future = true; } const feeConfig = this.safeValue (market, 'fee_config', {}); - const maker = this.safeFloat (feeConfig, 'maker_fee'); - const taker = this.safeFloat (feeConfig, 'taker_fee'); + const maker = this.safeNumber (feeConfig, 'maker_fee'); + const taker = this.safeNumber (feeConfig, 'taker_fee'); result.push ({ 'id': id, 'numericId': numericId, @@ -675,33 +675,33 @@ module.exports = class bitmart extends Exchange { const timestamp = this.safeTimestamp (ticker, 'timestamp', this.milliseconds ()); const marketId = this.safeString2 (ticker, 'symbol', 'contract_id'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat2 (ticker, 'close_24h', 'last_price'); - let percentage = this.safeFloat (ticker, 'fluctuation', 'rise_fall_rate'); + const last = this.safeNumber2 (ticker, 'close_24h', 'last_price'); + let percentage = this.safeNumber (ticker, 'fluctuation', 'rise_fall_rate'); if (percentage !== undefined) { percentage *= 100; } - const baseVolume = this.safeFloat2 (ticker, 'base_volume_24h', 'base_coin_volume'); - const quoteVolume = this.safeFloat2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); + const baseVolume = this.safeNumber2 (ticker, 'base_volume_24h', 'base_coin_volume'); + const quoteVolume = this.safeNumber2 (ticker, 'quote_volume_24h', 'quote_coin_volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const open = this.safeFloat2 (ticker, 'open_24h', 'open'); + const open = this.safeNumber2 (ticker, 'open_24h', 'open'); let average = undefined; if ((last !== undefined) && (open !== undefined)) { average = this.sum (last, open) / 2; } - average = this.safeFloat (ticker, 'avg_price', average); + average = this.safeNumber (ticker, 'avg_price', average); const price = this.safeValue (ticker, 'depth_price', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high', 'high_24h'), - 'low': this.safeFloat2 (ticker, 'low', 'low_24h'), - 'bid': this.safeFloat (price, 'best_bid', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (price, 'best_ask', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber2 (ticker, 'high', 'high_24h'), + 'low': this.safeNumber2 (ticker, 'low', 'low_24h'), + 'bid': this.safeNumber (price, 'best_bid', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (price, 'best_ask', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open_24h'), + 'open': this.safeNumber (ticker, 'open_24h'), 'close': last, 'last': last, 'previousClose': undefined, @@ -1005,18 +1005,18 @@ module.exports = class bitmart extends Exchange { if (execType !== undefined) { takerOrMaker = (execType === 'M') ? 'maker' : 'taker'; } - let price = this.safeFloat2 (trade, 'price', 'deal_price'); - price = this.safeFloat (trade, 'price_avg', price); - let amount = this.safeFloat2 (trade, 'amount', 'deal_vol'); - amount = this.safeFloat (trade, 'size', amount); - let cost = this.safeFloat2 (trade, 'count', 'notional'); + let price = this.safeNumber2 (trade, 'price', 'deal_price'); + price = this.safeNumber (trade, 'price_avg', price); + let amount = this.safeNumber2 (trade, 'amount', 'deal_vol'); + amount = this.safeNumber (trade, 'size', amount); + let cost = this.safeNumber2 (trade, 'count', 'notional'); if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { cost = amount * price; } const orderId = this.safeInteger (trade, 'order_id'); const marketId = this.safeString2 (trade, 'contract_id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (trade, 'fees'); + const feeCost = this.safeNumber (trade, 'fees'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_coin_name'); @@ -1144,11 +1144,11 @@ module.exports = class bitmart extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1475,11 +1475,11 @@ module.exports = class bitmart extends Exchange { currencyId = this.safeString (balance, 'coind_code', currencyId); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat2 (balance, 'available', 'available_vol'); - account['used'] = this.safeFloat2 (balance, 'frozen', 'freeze_vol'); + account['free'] = this.safeString2 (balance, 'available', 'available_vol'); + account['used'] = this.safeString2 (balance, 'frozen', 'freeze_vol'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -1548,29 +1548,10 @@ module.exports = class bitmart extends Exchange { if (market !== undefined) { status = this.parseOrderStatusByType (market['type'], this.safeString (order, 'status')); } - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat2 (order, 'price_avg', 'done_avg_price'); - const amount = this.safeFloat2 (order, 'size', 'vol'); - let cost = undefined; - let filled = this.safeFloat2 (order, 'filled_size', 'done_vol'); - let remaining = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - if (filled === undefined) { - filled = Math.max (0, amount - remaining); - } - } - if (filled !== undefined) { - if (remaining === undefined) { - remaining = Math.max (0, amount - filled); - } - if (cost === undefined) { - if (average !== undefined) { - cost = average * filled; - } - } - } - } + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber2 (order, 'price_avg', 'done_avg_price'); + const amount = this.safeNumber2 (order, 'size', 'vol'); + const filled = this.safeNumber2 (order, 'filled_size', 'done_vol'); let side = this.safeString (order, 'side'); // 1 = Open long // 2 = Close short @@ -1592,7 +1573,7 @@ module.exports = class bitmart extends Exchange { average = undefined; } } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -1607,14 +1588,14 @@ module.exports = class bitmart extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatusByType (type, status) { @@ -1655,7 +1636,7 @@ module.exports = class bitmart extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2241,12 +2222,12 @@ module.exports = class bitmart extends Exchange { type = 'deposit'; id = depositId; } - const amount = this.safeFloat (transaction, 'arrival_amount'); + const amount = this.safeNumber (transaction, 'arrival_amount'); const timestamp = this.safeInteger (transaction, 'tapply_timeime'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmex.js index 4f5a0552a..8eddc8287 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitmex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, BadRequest, DDoSProtection, ExchangeError, ExchangeNotAvailable, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -215,8 +216,8 @@ module.exports = class bitmex extends Exchange { 'amount': undefined, 'price': undefined, }; - const lotSize = this.safeFloat (market, 'lotSize'); - const tickSize = this.safeFloat (market, 'tickSize'); + const lotSize = this.safeNumber (market, 'lotSize'); + const tickSize = this.safeNumber (market, 'tickSize'); if (lotSize !== undefined) { precision['amount'] = lotSize; } @@ -230,7 +231,7 @@ module.exports = class bitmex extends Exchange { }, 'price': { 'min': tickSize, - 'max': this.safeFloat (market, 'maxPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { 'min': undefined, @@ -240,7 +241,7 @@ module.exports = class bitmex extends Exchange { const limitField = (position === quote) ? 'cost' : 'amount'; limits[limitField] = { 'min': lotSize, - 'max': this.safeFloat (market, 'maxOrderQty'), + 'max': this.safeNumber (market, 'maxOrderQty'), }; result.push ({ 'id': id, @@ -252,8 +253,8 @@ module.exports = class bitmex extends Exchange { 'active': active, 'precision': precision, 'limits': limits, - 'taker': this.safeFloat (market, 'takerFee'), - 'maker': this.safeFloat (market, 'makerFee'), + 'taker': this.safeNumber (market, 'takerFee'), + 'maker': this.safeNumber (market, 'makerFee'), 'type': type, 'spot': false, 'swap': swap, @@ -319,21 +320,17 @@ module.exports = class bitmex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - let free = this.safeFloat (balance, 'availableMargin'); - let total = this.safeFloat (balance, 'marginBalance'); + let free = this.safeString (balance, 'availableMargin'); + let total = this.safeString (balance, 'marginBalance'); if (code === 'BTC') { - if (free !== undefined) { - free /= 100000000; - } - if (total !== undefined) { - total /= 100000000; - } + free = Precise.stringDiv (free, '1e8'); + total = Precise.stringDiv (total, '1e8'); } account['free'] = free; account['total'] = total; result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -412,8 +409,8 @@ module.exports = class bitmex extends Exchange { for (let i = 0; i < response.length; i++) { const order = response[i]; const side = (order['side'] === 'Sell') ? 'asks' : 'bids'; - const amount = this.safeFloat (order, 'size'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const price = this.safeNumber (order, 'price'); // https://github.com/ccxt/ccxt/issues/4926 // https://github.com/ccxt/ccxt/issues/4927 // the exchange sometimes returns null price in the orderbook @@ -619,7 +616,7 @@ module.exports = class bitmex extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'transactType')); const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount !== undefined) { amount = amount / 100000000; } @@ -630,7 +627,7 @@ module.exports = class bitmex extends Exchange { // for unrealized pnl and other transactions without a timestamp timestamp = 0; // see comments above } - let feeCost = this.safeFloat (item, 'fee', 0); + let feeCost = this.safeNumber (item, 'fee', 0); if (feeCost !== undefined) { feeCost = feeCost / 100000000; } @@ -638,7 +635,7 @@ module.exports = class bitmex extends Exchange { 'cost': feeCost, 'currency': code, }; - let after = this.safeFloat (item, 'walletBalance'); + let after = this.safeNumber (item, 'walletBalance'); if (after !== undefined) { after = after / 100000000; } @@ -957,8 +954,8 @@ module.exports = class bitmex extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const open = this.safeFloat (ticker, 'prevPrice24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'prevPrice24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; if (last !== undefined && open !== undefined) { @@ -971,13 +968,13 @@ module.exports = class bitmex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askPrice'), + 'ask': this.safeNumber (ticker, 'askPrice'), 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'vwap'), + 'vwap': this.safeNumber (ticker, 'vwap'), 'open': open, 'close': last, 'last': last, @@ -985,8 +982,8 @@ module.exports = class bitmex extends Exchange { 'change': change, 'percentage': percentage, 'average': this.sum (open, last) / 2, - 'baseVolume': this.safeFloat (ticker, 'homeNotional24h'), - 'quoteVolume': this.safeFloat (ticker, 'foreignNotional24h'), + 'baseVolume': this.safeNumber (ticker, 'homeNotional24h'), + 'quoteVolume': this.safeNumber (ticker, 'foreignNotional24h'), 'info': ticker, }; } @@ -1011,11 +1008,11 @@ module.exports = class bitmex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1144,23 +1141,23 @@ module.exports = class bitmex extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat2 (trade, 'avgPx', 'price'); - const amount = this.safeFloat2 (trade, 'size', 'lastQty'); + const price = this.safeNumber2 (trade, 'avgPx', 'price'); + const amount = this.safeNumber2 (trade, 'size', 'lastQty'); const id = this.safeString (trade, 'trdMatchID'); const order = this.safeString (trade, 'orderID'); const side = this.safeStringLower (trade, 'side'); // price * amount doesn't work for all symbols (e.g. XBT, ETH) - let cost = this.safeFloat (trade, 'execCost'); + let cost = this.safeNumber (trade, 'execCost'); if (cost !== undefined) { cost = Math.abs (cost) / 100000000; } let fee = undefined; if ('execComm' in trade) { - let feeCost = this.safeFloat (trade, 'execComm'); + let feeCost = this.safeNumber (trade, 'execComm'); feeCost = feeCost / 100000000; const currencyId = this.safeString (trade, 'settlCurrency'); const feeCurrency = this.safeCurrencyCode (currencyId); - const feeRate = this.safeFloat (trade, 'commission'); + const feeRate = this.safeNumber (trade, 'commission'); fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -1262,33 +1259,19 @@ module.exports = class bitmex extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'transactTime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty', 0.0); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (amount - filled, 0.0); - } - } - const average = this.safeFloat (order, 'avgPx'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = average * filled; - } else if (price !== undefined) { - cost = price * filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty', 0.0); + const average = this.safeNumber (order, 'avgPx'); const id = this.safeString (order, 'orderID'); const type = this.safeStringLower (order, 'ordType'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'clOrdID'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const execInst = this.safeString (order, 'execInst'); const postOnly = (execInst === 'ParticipateDoNotInitiate'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1303,14 +1286,14 @@ module.exports = class bitmex extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { @@ -1371,7 +1354,7 @@ module.exports = class bitmex extends Exchange { 'ordType': orderType, }; if ((orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched')) { - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPx or stopPrice parameter for the ' + orderType + ' order type'); } else { @@ -1488,7 +1471,7 @@ module.exports = class bitmex extends Exchange { return this.parseOrders (response, market); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPosition (params); // [ diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitpanda.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitpanda.js index b440aba7d..5f857014b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitpanda.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitpanda.js @@ -328,7 +328,7 @@ module.exports = class bitpanda extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; @@ -401,9 +401,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -450,8 +450,8 @@ module.exports = class bitpanda extends Exchange { const activeFeeTier = this.safeValue (response, 'active_fee_tier', {}); const result = { 'info': response, - 'maker': this.safeFloat (activeFeeTier, 'maker_fee'), - 'taker': this.safeFloat (activeFeeTier, 'taker_fee'), + 'maker': this.safeNumber (activeFeeTier, 'maker_fee'), + 'taker': this.safeNumber (activeFeeTier, 'taker_fee'), 'percentage': true, 'tierBased': true, }; @@ -460,9 +460,9 @@ module.exports = class bitpanda extends Exchange { const makerFees = []; for (let i = 0; i < feeTiers.length; i++) { const tier = feeTiers[i]; - const volume = this.safeFloat (tier, 'volume'); - let taker = this.safeFloat (tier, 'taker_fee'); - let maker = this.safeFloat (tier, 'maker_fee'); + const volume = this.safeNumber (tier, 'volume'); + let taker = this.safeNumber (tier, 'taker_fee'); + let maker = this.safeNumber (tier, 'maker_fee'); taker /= 100; maker /= 100; takerFees.push ([ volume, taker ]); @@ -500,27 +500,27 @@ module.exports = class bitpanda extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last_price'); - const percentage = this.safeFloat (ticker, 'price_change_percentage'); - const change = this.safeFloat (ticker, 'price_change'); + const last = this.safeNumber (ticker, 'last_price'); + const percentage = this.safeNumber (ticker, 'price_change_percentage'); + const change = this.safeNumber (ticker, 'price_change'); let open = undefined; let average = undefined; if ((last !== undefined) && (change !== undefined)) { open = last - change; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'best_bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'best_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'best_ask'), + 'ask': this.safeNumber (ticker, 'best_ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -705,11 +705,11 @@ module.exports = class bitpanda extends Exchange { const volumeField = this.safeString (options, 'volume', 'total_amount'); return [ alignedTimestamp, - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -795,21 +795,21 @@ module.exports = class bitpanda extends Exchange { timestamp = this.parse8601 (this.safeString (trade, 'time')); } const side = this.safeStringLower2 (trade, 'side', 'taker_side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + let cost = this.safeNumber (trade, 'volume'); if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { cost = amount * price; } const marketId = this.safeString (trade, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const feeCost = this.safeFloat (feeInfo, 'fee_amount'); + const feeCost = this.safeNumber (feeInfo, 'fee_amount'); let takerOrMaker = undefined; let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (feeInfo, 'fee_percentage'); + const feeRate = this.safeNumber (feeInfo, 'fee_percentage'); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, @@ -892,11 +892,11 @@ module.exports = class bitpanda extends Exchange { const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -1150,12 +1150,12 @@ module.exports = class bitpanda extends Exchange { // } // const id = this.safeString (transaction, 'transaction_id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const currencyId = this.safeString (transaction, 'currency'); currency = this.safeCurrency (currencyId, currency); const status = 'ok'; // the exchange returns cleared transactions only - const feeCost = this.safeFloat2 (transaction, 'fee_amount', 'fee'); + const feeCost = this.safeNumber2 (transaction, 'fee_amount', 'fee'); let fee = undefined; const addressTo = this.safeString (transaction, 'recipient'); const tagTo = this.safeString (transaction, 'destination_tag'); @@ -1270,72 +1270,34 @@ module.exports = class bitpanda extends Exchange { // ] // } // - const rawTrades = this.safeValue (order, 'trades', []); - order = this.safeValue (order, 'order', order); - const id = this.safeString (order, 'order_id'); - const clientOrderId = this.safeString (order, 'client_id'); - const timestamp = this.parse8601 (this.safeString (order, 'time')); - let status = this.parseOrderStatus (this.safeString (order, 'status')); - const marketId = this.safeString (order, 'instrument_code'); + const rawOrder = this.safeValue (order, 'order', order); + const id = this.safeString (rawOrder, 'order_id'); + const clientOrderId = this.safeString (rawOrder, 'client_id'); + const timestamp = this.parse8601 (this.safeString (rawOrder, 'time')); + const rawStatus = this.parseOrderStatus (this.safeString (rawOrder, 'status')); + const status = this.parseOrderStatus (rawStatus); + const marketId = this.safeString (rawOrder, 'instrument_code'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - if (status === undefined) { - if (remaining > 0) { - status = 'open'; - } else { - status = 'closed'; - } - } - } - } - const side = this.safeStringLower (order, 'side'); - const type = this.safeStringLower (order, 'type'); - const trades = this.parseTrades (rawTrades, market, undefined, undefined); - const fees = []; - const numTrades = trades.length; - let lastTradeTimestamp = undefined; - let tradeCost = undefined; - let tradeAmount = undefined; - if (numTrades > 0) { - lastTradeTimestamp = trades[0]['timestamp']; - tradeCost = 0; - tradeAmount = 0; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - fees.push (trade['fee']); - lastTradeTimestamp = Math.max (lastTradeTimestamp, trade['timestamp']); - tradeCost = this.sum (tradeCost, trade['cost']); - tradeAmount = this.sum (tradeAmount, trade['amount']); - } - } - let average = this.safeFloat (order, 'average_price'); - if (average === undefined) { - if ((tradeCost !== undefined) && (tradeAmount !== undefined) && (tradeAmount !== 0)) { - average = tradeCost / tradeAmount; - } - } - if (cost === undefined) { - if ((average !== undefined) && (filled !== undefined)) { - cost = average * filled; - } - } - const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'trigger_price'); - const postOnly = this.safeValue (order, 'is_post_only'); - const result = { + const price = this.safeNumber (rawOrder, 'price'); + const amount = this.safeNumber (rawOrder, 'amount'); + const filledString = this.safeString (rawOrder, 'filled_amount'); + const filled = this.parseNumber (filledString); + const side = this.safeStringLower (rawOrder, 'side'); + const type = this.safeStringLower (rawOrder, 'type'); + const timeInForce = this.parseTimeInForce (this.safeString (rawOrder, 'time_in_force')); + const stopPrice = this.safeNumber (rawOrder, 'trigger_price'); + const postOnly = this.safeValue (rawOrder, 'is_post_only'); + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'type': type, + }); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -1344,41 +1306,14 @@ module.exports = class bitpanda extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, // 'fee': undefined, 'trades': trades, - }; - const numFees = fees.length; - if (numFees > 0) { - if (numFees === 1) { - result['fee'] = fees[0]; - } else { - const feesByCurrency = this.groupBy (fees, 'currency'); - const feeCurrencies = Object.keys (feesByCurrency); - const numFeesByCurrency = feeCurrencies.length; - if (numFeesByCurrency === 1) { - const feeCurrency = feeCurrencies[0]; - const feeArray = this.safeValue (feesByCurrency, feeCurrency); - let feeCost = 0; - for (let i = 0; i < feeArray.length; i++) { - feeCost = this.sum (feeCost, feeArray[i]['cost']); - } - result['fee'] = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } else { - result['fees'] = fees; - } - } - } else { - result['fee'] = undefined; - } - return result; + }); } parseTimeInForce (timeInForce) { @@ -1412,7 +1347,7 @@ module.exports = class bitpanda extends Exchange { priceIsRequired = true; } if (uppercaseType === 'STOP') { - const triggerPrice = this.safeFloat (params, 'trigger_price'); + const triggerPrice = this.safeNumber (params, 'trigger_price'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a trigger_price param for ' + type + ' orders'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitso.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitso.js index d8bc07145..defcece54 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitso.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitso.js @@ -157,28 +157,28 @@ module.exports = class bitso extends Exchange { const symbol = base + '/' + quote; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), - 'max': this.safeFloat (market, 'maximum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), + 'max': this.safeNumber (market, 'maximum_amount'), }, 'price': { - 'min': this.safeFloat (market, 'minimum_price'), - 'max': this.safeFloat (market, 'maximum_price'), + 'min': this.safeNumber (market, 'minimum_price'), + 'max': this.safeNumber (market, 'maximum_price'), }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), - 'max': this.safeFloat (market, 'maximum_value'), + 'min': this.safeNumber (market, 'minimum_value'), + 'max': this.safeNumber (market, 'maximum_value'), }, }; - const defaultPricePrecision = this.safeFloat (this.options['precision'], quote, this.options['defaultPrecision']); - const pricePrecision = this.safeFloat (market, 'tick_size', defaultPricePrecision); + const defaultPricePrecision = this.safeNumber (this.options['precision'], quote, this.options['defaultPrecision']); + const pricePrecision = this.safeNumber (market, 'tick_size', defaultPricePrecision); const precision = { - 'amount': this.safeFloat (this.options['precision'], base, this.options['defaultPrecision']), + 'amount': this.safeNumber (this.options['precision'], base, this.options['defaultPrecision']), 'price': pricePrecision, }; const fees = this.safeValue (market, 'fees', {}); const flatRate = this.safeValue (fees, 'flat_rate', {}); - const maker = this.safeFloat (flatRate, 'maker'); - const taker = this.safeFloat (flatRate, 'taker'); + const maker = this.safeNumber (flatRate, 'maker'); + const taker = this.safeNumber (flatRate, 'taker'); const feeTiers = this.safeValue (fees, 'structure', []); const fee = { 'taker': parseFloat (this.decimalToPrecision (taker / 100, ROUND, 0.00000001, TICK_SIZE)), @@ -190,9 +190,9 @@ module.exports = class bitso extends Exchange { const makerFees = []; for (let j = 0; j < feeTiers.length; j++) { const tier = feeTiers[j]; - const volume = this.safeFloat (tier, 'volume'); - const takerFee = this.safeFloat (tier, 'taker'); - const makerFee = this.safeFloat (tier, 'maker'); + const volume = this.safeNumber (tier, 'volume'); + const takerFee = this.safeNumber (tier, 'taker'); + const makerFee = this.safeNumber (tier, 'maker'); const takerFeeToPrecision = parseFloat (this.decimalToPrecision (takerFee / 100, ROUND, 0.00000001, TICK_SIZE)); const makerFeeToPrecision = parseFloat (this.decimalToPrecision (makerFee / 100, ROUND, 0.00000001, TICK_SIZE)); takerFees.push ([ volume, takerFeeToPrecision ]); @@ -232,14 +232,13 @@ module.exports = class bitso extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'locked'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -261,22 +260,22 @@ module.exports = class bitso extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'payload'); const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -297,12 +296,12 @@ module.exports = class bitso extends Exchange { const marketId = this.safeString (trade, 'book'); const symbol = this.safeSymbol (marketId, market, '_'); const side = this.safeString2 (trade, 'side', 'maker_side'); - let amount = this.safeFloat2 (trade, 'amount', 'major'); + let amount = this.safeNumber2 (trade, 'amount', 'major'); if (amount !== undefined) { amount = Math.abs (amount); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fees_amount'); + const feeCost = this.safeNumber (trade, 'fees_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fees_currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -311,11 +310,11 @@ module.exports = class bitso extends Exchange { 'currency': feeCurrency, }; } - let cost = this.safeFloat (trade, 'minor'); + let cost = this.safeNumber (trade, 'minor'); if (cost !== undefined) { cost = Math.abs (cost); } - const price = this.safeFloat (trade, 'price'); + const price = this.safeNumber (trade, 'price'); const orderId = this.safeString (trade, 'oid'); const id = this.safeString (trade, 'tid'); return { @@ -416,17 +415,11 @@ module.exports = class bitso extends Exchange { const symbol = this.safeSymbol (marketId, market, '_'); const orderType = this.safeString (order, 'type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'unfilled_amount'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'unfilled_amount'); const clientOrderId = this.safeString (order, 'client_id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -443,12 +436,12 @@ module.exports = class bitso extends Exchange { 'amount': amount, 'cost': undefined, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = 25, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp.js index 4671385bf..0ac6fe9f7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp.js @@ -115,6 +115,16 @@ module.exports = class bitstamp extends Exchange { 'usdc_address/', 'omg_withdrawal/', 'omg_address/', + 'dai_withdrawal/', + 'dai_address/', + 'knc_withdrawal/', + 'knc_address/', + 'mkr_withdrawal/', + 'mkr_address/', + 'zrx_withdrawal/', + 'zrx_address/', + 'gusd_withdrawal/', + 'gusd_address/', 'transfer-to-main/', 'transfer-from-main/', 'withdrawal-requests/', @@ -249,13 +259,15 @@ module.exports = class bitstamp extends Exchange { const symbolId = baseId + '_' + quoteId; const id = this.safeString (market, 'url_symbol'); const precision = { - 'amount': market['base_decimals'], - 'price': market['counter_decimals'], + 'amount': this.safeInteger (market, 'base_decimals'), + 'price': this.safeInteger (market, 'counter_decimals'), }; - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; // let [ cost, currency ] = market['minimum_order'].split (' '); - const active = (market['trading'] === 'Enabled'); + const trading = this.safeString (market, 'trading'); + const active = (trading === 'Enabled'); result.push ({ 'id': id, 'symbol': symbol, @@ -299,7 +311,7 @@ module.exports = class bitstamp extends Exchange { 'type': currencyType, 'name': name, 'active': true, - 'fee': this.safeFloat (description['fees']['funding']['withdraw'], code), + 'fee': this.safeNumber (description['fees']['funding']['withdraw'], code), 'precision': precision, 'limits': { 'amount': { @@ -352,13 +364,16 @@ module.exports = class bitstamp extends Exchange { quote = this.safeCurrencyCode (quote); const description = this.safeString (market, 'description'); const [ baseDescription, quoteDescription ] = description.split (' / '); - const parts = market['minimum_order'].split (' '); + const minimumOrder = this.safeString (market, 'minimum_order'); + const parts = minimumOrder.split (' '); const cost = parts[0]; if (!(base in result)) { - result[base] = this.constructCurrencyObject (baseId, base, baseDescription, market['base_decimals'], undefined, market); + const baseDecimals = this.safeInteger (market, 'base_decimals'); + result[base] = this.constructCurrencyObject (baseId, base, baseDescription, baseDecimals, undefined, market); } if (!(quote in result)) { - result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, market['counter_decimals'], parseFloat (cost), market); + const counterDecimals = this.safeInteger (market, 'counter_decimals'); + result[quote] = this.constructCurrencyObject (quoteId, quote, quoteDescription, counterDecimals, parseFloat (cost), market); } } return result; @@ -400,25 +415,25 @@ module.exports = class bitstamp extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -461,7 +476,7 @@ module.exports = class bitstamp extends Exchange { for (let i = 0; i < ids.length; i++) { const id = ids[i]; if (id.indexOf ('_') < 0) { - const value = this.safeFloat (transaction, id); + const value = this.safeNumber (transaction, id); if ((value !== undefined) && (value !== 0)) { return id; } @@ -543,11 +558,11 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString2 (trade, 'id', 'tid'); let symbol = undefined; let side = undefined; - let price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat (trade, 'amount'); + let price = this.safeNumber (trade, 'price'); + let amount = this.safeNumber (trade, 'amount'); const orderId = this.safeString (trade, 'order_id'); const type = undefined; - let cost = this.safeFloat (trade, 'cost'); + let cost = this.safeNumber (trade, 'cost'); if (market === undefined) { const keys = Object.keys (trade); for (let i = 0; i < keys.length; i++) { @@ -564,12 +579,12 @@ module.exports = class bitstamp extends Exchange { market = this.getMarketFromTrade (trade); } } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let feeCurrency = undefined; if (market !== undefined) { - price = this.safeFloat (trade, market['symbolId'], price); - amount = this.safeFloat (trade, market['baseId'], amount); - cost = this.safeFloat (trade, market['quoteId'], cost); + price = this.safeNumber (trade, market['symbolId'], price); + amount = this.safeNumber (trade, market['baseId'], amount); + cost = this.safeNumber (trade, market['quoteId'], cost); feeCurrency = market['quote']; symbol = market['symbol']; } @@ -638,7 +653,7 @@ module.exports = class bitstamp extends Exchange { parseTradingFee (balances, symbol) { const market = this.market (symbol); - const tradeFee = this.safeFloat (balances, market['id'] + '_fee'); + const tradeFee = this.safeNumber (balances, market['id'] + '_fee'); return { 'symbol': symbol, 'maker': tradeFee, @@ -688,11 +703,11 @@ module.exports = class bitstamp extends Exchange { // return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -750,12 +765,12 @@ module.exports = class bitstamp extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFee (symbol, params = {}) { @@ -802,7 +817,7 @@ module.exports = class bitstamp extends Exchange { if (id.indexOf ('_withdrawal_fee') >= 0) { const currencyId = id.split ('_')[0]; const code = this.safeCurrencyCode (currencyId); - withdraw[code] = this.safeFloat (balance, id); + withdraw[code] = this.safeNumber (balance, id); } } return { @@ -1048,16 +1063,16 @@ module.exports = class bitstamp extends Exchange { const id = this.safeString (transaction, 'id'); const currencyId = this.getCurrencyIdFromTransaction (transaction); const code = this.safeCurrencyCode (currencyId, currency); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let feeCurrency = undefined; let amount = undefined; if ('amount' in transaction) { - amount = this.safeFloat (transaction, 'amount'); + amount = this.safeNumber (transaction, 'amount'); } else if (currency !== undefined) { - amount = this.safeFloat (transaction, currency['id'], amount); + amount = this.safeNumber (transaction, currency['id'], amount); feeCurrency = currency['code']; } else if ((code !== undefined) && (currencyId !== undefined)) { - amount = this.safeFloat (transaction, currencyId, amount); + amount = this.safeNumber (transaction, currencyId, amount); feeCurrency = code; } if (amount !== undefined) { @@ -1182,83 +1197,23 @@ module.exports = class bitstamp extends Exchange { } // there is no timestamp from fetchOrder const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - let lastTradeTimestamp = undefined; - let symbol = undefined; - let marketId = this.safeStringLower (order, 'currency_pair'); - if (marketId !== undefined) { - marketId = marketId.replace ('/', ''); - if (marketId in this.markets_by_id) { - market = this.markets_by_id[marketId]; - symbol = market['symbol']; - } - } - let amount = this.safeFloat (order, 'amount'); - let filled = 0.0; - const trades = []; - const transactions = this.safeValue (order, 'transactions', []); - let feeCost = undefined; - let cost = undefined; - const numTransactions = transactions.length; - if (numTransactions > 0) { - feeCost = 0.0; - for (let i = 0; i < numTransactions; i++) { - const trade = this.parseTrade (this.extend ({ - 'order_id': id, - 'side': side, - }, transactions[i]), market); - filled = this.sum (filled, trade['amount']); - feeCost = this.sum (feeCost, trade['fee']['cost']); - if (cost === undefined) { - cost = 0.0; - } - cost = this.sum (cost, trade['cost']); - trades.push (trade); - } - lastTradeTimestamp = trades[numTransactions - 1]['timestamp']; - } + const marketId = this.safeStringLower (order, 'currency_pair'); + let symbol = this.safeSymbol (marketId, market, '/'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((status === 'closed') && (amount === undefined)) { - amount = filled; + const amount = this.safeNumber (order, 'amount'); + const transactions = this.safeValue (order, 'transactions', []); + const trades = this.parseTrades (transactions, market); + const length = trades.length; + if (length) { + symbol = trades[0]['symbol']; } - let remaining = undefined; - if (amount !== undefined) { - remaining = amount - filled; - } - let price = this.safeFloat (order, 'price'); - if (market === undefined) { - market = this.getMarketFromTrades (trades); - } - let feeCurrency = undefined; - if (market !== undefined) { - if (symbol === undefined) { - symbol = market['symbol']; - } - feeCurrency = market['quote']; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if (price === undefined) { - if (filled > 0) { - price = cost / filled; - } - } - let fee = undefined; - if (feeCost !== undefined) { - if (feeCurrency !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { + const price = this.safeNumber (order, 'price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'status': status, 'symbol': symbol, 'type': undefined, @@ -1267,15 +1222,15 @@ module.exports = class bitstamp extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, - 'filled': filled, - 'remaining': remaining, + 'filled': undefined, + 'remaining': undefined, 'trades': trades, - 'fee': fee, + 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } parseLedgerEntryType (type) { @@ -1355,11 +1310,11 @@ module.exports = class bitstamp extends Exchange { const parsedTransaction = this.parseTransaction (item); let direction = undefined; if ('amount' in item) { - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); direction = amount > 0 ? 'in' : 'out'; } else if (('currency' in parsedTransaction) && parsedTransaction['currency'] !== undefined) { const currencyId = this.currencyId (parsedTransaction['currency']); - const amount = this.safeFloat (item, currencyId); + const amount = this.safeNumber (item, currencyId); direction = amount > 0 ? 'in' : 'out'; } return { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp1.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp1.js index 8d8de5db1..2b6b70a04 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp1.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitstamp1.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -100,25 +101,25 @@ module.exports = class bitstamp1 extends Exchange { await this.loadMarkets (); const ticker = await this.publicGetTicker (params); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, @@ -141,14 +142,11 @@ module.exports = class bitstamp1 extends Exchange { } } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -192,12 +190,12 @@ module.exports = class bitstamp1 extends Exchange { const currency = this.currency (code); const currencyId = currency['id']; const account = this.account (); - account['free'] = this.safeFloat (balance, currencyId + '_available'); - account['used'] = this.safeFloat (balance, currencyId + '_reserved'); - account['total'] = this.safeFloat (balance, currencyId + '_balance'); + account['free'] = this.safeString (balance, currencyId + '_available'); + account['used'] = this.safeString (balance, currencyId + '_reserved'); + account['total'] = this.safeString (balance, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bittrex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bittrex.js index 1e11d600a..fb8f6fb09 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bittrex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bittrex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, DDoSProtection, PermissionDenied, AddressPending, OnMaintenance, BadRequest, InvalidAddress } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -280,7 +281,7 @@ module.exports = class bittrex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeSize'), + 'min': this.safeNumber (market, 'minTradeSize'), 'max': undefined, }, 'price': { @@ -308,11 +309,11 @@ module.exports = class bittrex extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); const balance = indexed[currencyId]; - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -372,7 +373,7 @@ module.exports = class bittrex extends Exchange { const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); const precision = 8; // default precision, todo: fix "magic constants" - const fee = this.safeFloat (currency, 'txFee'); // todo: redesign + const fee = this.safeNumber (currency, 'txFee'); // todo: redesign const isActive = this.safeString (currency, 'status'); result[code] = { 'id': id, @@ -433,17 +434,17 @@ module.exports = class bittrex extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'updatedAt')); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const percentage = this.safeFloat (ticker, 'percentChange'); - const last = this.safeFloat (ticker, 'lastTradeRate'); + const percentage = this.safeNumber (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'lastTradeRate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidRate'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidRate'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'askRate'), + 'ask': this.safeNumber (ticker, 'askRate'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -453,8 +454,8 @@ module.exports = class bittrex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -567,21 +568,18 @@ module.exports = class bittrex extends Exchange { const order = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'marketSymbol'); market = this.safeMarket (marketId, market, '-'); - let cost = undefined; - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'quantity'); - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = undefined; const isTaker = this.safeValue (trade, 'isTaker'); if (isTaker !== undefined) { takerOrMaker = isTaker ? 'taker' : 'maker'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -651,11 +649,11 @@ module.exports = class bittrex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'startsAt')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -762,9 +760,9 @@ module.exports = class bittrex extends Exchange { let cost = undefined; if (isCeilingLimit) { request['limit'] = this.priceToPrecision (symbol, price); - cost = this.safeFloat2 (params, 'ceiling', 'cost', amount); + cost = this.safeNumber2 (params, 'ceiling', 'cost', amount); } else if (isCeilingMarket) { - cost = this.safeFloat2 (params, 'ceiling', 'cost'); + cost = this.safeNumber2 (params, 'ceiling', 'cost'); if (cost === undefined) { if (price === undefined) { cost = amount; @@ -923,7 +921,7 @@ module.exports = class bittrex extends Exchange { // } // const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const address = this.safeString (transaction, 'cryptoAddress'); const txid = this.safeString (transaction, 'txId'); const updated = this.parse8601 (this.safeString (transaction, 'updatedAt')); @@ -959,7 +957,7 @@ module.exports = class bittrex extends Exchange { status = 'ok'; } } - let feeCost = this.safeFloat (transaction, 'txCost'); + let feeCost = this.safeNumber (transaction, 'txCost'); if (feeCost === undefined) { if (type === 'deposit') { // according to https://support.bittrex.com/hc/en-us/articles/115000199651-What-fees-does-Bittrex-charge- @@ -1016,15 +1014,9 @@ module.exports = class bittrex extends Exchange { // } // const marketSymbol = this.safeString (order, 'marketSymbol'); - let symbol = undefined; - let feeCurrency = undefined; - if (marketSymbol !== undefined) { - const [ baseId, quoteId ] = marketSymbol.split ('-'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - symbol = base + '/' + quote; - feeCurrency = quote; - } + market = this.safeMarket (marketSymbol, market, '-'); + const symbol = market['symbol']; + const feeCurrency = market['quote']; const direction = this.safeStringLower (order, 'direction'); const createdAt = this.safeString (order, 'createdAt'); const updatedAt = this.safeString (order, 'updatedAt'); @@ -1037,32 +1029,15 @@ module.exports = class bittrex extends Exchange { } const timestamp = this.parse8601 (createdAt); const type = this.safeStringLower (order, 'type'); - const quantity = this.safeFloat (order, 'quantity'); - const limit = this.safeFloat (order, 'limit'); - const fillQuantity = this.safeFloat (order, 'fillQuantity'); - const commission = this.safeFloat (order, 'commission'); - const proceeds = this.safeFloat (order, 'proceeds'); - let average = undefined; - let remaining = undefined; - if (fillQuantity !== undefined) { - if (proceeds !== undefined) { - if (fillQuantity > 0) { - average = proceeds / fillQuantity; - } else if (proceeds === 0) { - average = 0; - } - } - if (quantity !== undefined) { - remaining = quantity - fillQuantity; - } - } - let status = this.safeStringLower (order, 'status'); - if ((status === 'closed') && (remaining !== undefined) && (remaining > 0)) { - status = 'canceled'; - } + const quantity = this.safeNumber (order, 'quantity'); + const limit = this.safeNumber (order, 'limit'); + const fillQuantity = this.safeNumber (order, 'fillQuantity'); + const commission = this.safeNumber (order, 'commission'); + const proceeds = this.safeNumber (order, 'proceeds'); + const status = this.safeStringLower (order, 'status'); const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'timestamp': timestamp, @@ -1076,10 +1051,10 @@ module.exports = class bittrex extends Exchange { 'price': limit, 'stopPrice': undefined, 'cost': proceeds, - 'average': average, + 'average': undefined, 'amount': quantity, 'filled': fillQuantity, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': { 'cost': commission, @@ -1087,7 +1062,7 @@ module.exports = class bittrex extends Exchange { }, 'info': order, 'trades': undefined, - }; + }); } parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { @@ -1136,9 +1111,9 @@ module.exports = class bittrex extends Exchange { 'side': this.safeString (order, 'side'), 'order': this.safeString (order, 'id'), 'type': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'average'), - 'amount': this.safeFloat (order, 'filled'), - 'cost': this.safeFloat (order, 'cost'), + 'price': this.safeNumber (order, 'average'), + 'amount': this.safeNumber (order, 'filled'), + 'cost': this.safeNumber (order, 'cost'), 'symbol': this.safeString (order, 'symbol'), 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitvavo.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitvavo.js index e6633b568..ef66620ca 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitvavo.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitvavo.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadSymbol, AuthenticationError, InsufficientFunds, InvalidOrder, ArgumentsRequired, OrderNotFound, InvalidAddress, BadRequest, RateLimitExceeded, PermissionDenied, ExchangeNotAvailable, AccountSuspended, OnMaintenance } = require ('./base/errors'); const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -306,7 +307,7 @@ module.exports = class bitvavo extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minOrderInBaseAsset'), + 'min': this.safeNumber (market, 'minOrderInBaseAsset'), 'max': undefined, }, 'price': { @@ -314,7 +315,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderInQuoteAsset'), + 'min': this.safeNumber (market, 'minOrderInQuoteAsset'), 'max': undefined, }, }, @@ -377,7 +378,7 @@ module.exports = class bitvavo extends Exchange { 'code': code, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -393,7 +394,7 @@ module.exports = class bitvavo extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMinAmount'), + 'min': this.safeNumber (currency, 'withdrawalMinAmount'), 'max': undefined, }, }, @@ -450,14 +451,14 @@ module.exports = class bitvavo extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.safeInteger (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); + const last = this.safeNumber (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); const vwap = this.vwap (baseVolume, quoteVolume); let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'open'); + const open = this.safeNumber (ticker, 'open'); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -469,12 +470,12 @@ module.exports = class bitvavo extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': vwap, 'open': open, 'close': last, @@ -490,14 +491,6 @@ module.exports = class bitvavo extends Exchange { return result; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24h (params); @@ -611,12 +604,11 @@ module.exports = class bitvavo extends Exchange { // feeCurrency: 'EUR' // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'side'); const id = this.safeString2 (trade, 'id', 'fillId'); @@ -627,7 +619,7 @@ module.exports = class bitvavo extends Exchange { if (taker !== undefined) { takerOrMaker = taker ? 'taker' : 'maker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); @@ -698,11 +690,11 @@ module.exports = class bitvavo extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -750,13 +742,12 @@ module.exports = class bitvavo extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'inOrder'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'inOrder'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchDepositAddress (code, params = {}) { @@ -806,7 +797,7 @@ module.exports = class bitvavo extends Exchange { if (price !== undefined) { cost = amount * price; } else { - cost = this.safeFloat2 (params, 'cost', 'amountQuote'); + cost = this.safeNumber2 (params, 'cost', 'amountQuote'); } if (cost !== undefined) { const precision = market['precision']['price']; @@ -819,7 +810,7 @@ module.exports = class bitvavo extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['amount'] = this.amountToPrecision (symbol, amount); } else if (isStopMarket || isStopLimit) { - let stopPrice = this.safeFloat2 (params, 'stopPrice', 'triggerAmount'); + let stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerAmount'); if (stopPrice === undefined) { if (isStopLimit) { throw new ArgumentsRequired (this.id + ' createOrder requires a stopPrice parameter for a ' + type + ' order'); @@ -881,7 +872,7 @@ module.exports = class bitvavo extends Exchange { await this.loadMarkets (); const market = this.market (symbol); let request = {}; - const amountRemaining = this.safeFloat (params, 'amountRemaining'); + const amountRemaining = this.safeNumber (params, 'amountRemaining'); params = this.omit (params, 'amountRemaining'); if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); @@ -946,7 +937,6 @@ module.exports = class bitvavo extends Exchange { throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument'); } await this.loadMarkets (); - await this.loadMarkets (); const market = this.market (symbol); const request = { 'orderId': id, @@ -1172,26 +1162,13 @@ module.exports = class bitvavo extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let remaining = this.safeFloat (order, 'amountRemaining'); - let filled = this.safeFloat (order, 'filledAmount'); - const remainingCost = this.safeFloat (order, 'remainingCost'); - if ((remainingCost !== undefined) && (remainingCost === 0.0)) { - remaining = 0; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - const cost = this.safeFloat (order, 'filledAmountQuote'); - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amountRemaining'); + const filled = this.safeNumber (order, 'filledAmount'); + const cost = this.safeNumber (order, 'filledAmountQuote'); let fee = undefined; - const feeCost = this.safeFloat (order, 'feePaid'); + const feeCost = this.safeNumber (order, 'feePaid'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1200,32 +1177,24 @@ module.exports = class bitvavo extends Exchange { 'currency': feeCurrencyCode, }; } - let lastTradeTimestamp = undefined; - const rawTrades = this.safeValue (order, 'fills'); - let trades = undefined; - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'symbol': symbol, - 'order': id, - 'side': side, - }); - const numTrades = trades.length; - if (numTrades > 0) { - const lastTrade = this.safeValue (trades, numTrades - 1); - lastTradeTimestamp = lastTrade['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'fills', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'symbol': symbol, + 'order': id, + 'side': side, + 'type': type, + }); const timeInForce = this.safeString (order, 'timeInForce'); const postOnly = this.safeValue (order, 'postOnly'); // https://github.com/ccxt/ccxt/issues/8489 - const stopPrice = this.safeFloat (order, 'triggerPrice'); - return { + const stopPrice = this.safeNumber (order, 'triggerPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': timeInForce, @@ -1235,13 +1204,13 @@ module.exports = class bitvavo extends Exchange { 'stopPrice': stopPrice, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1436,11 +1405,11 @@ module.exports = class bitvavo extends Exchange { const currencyId = this.safeString (transaction, 'symbol'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitz.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitz.js index 816bb15a4..d78900841 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitz.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bitz.js @@ -59,7 +59,7 @@ module.exports = class bitz extends Exchange { 'assets': 'https://{hostname}', }, 'www': 'https://www.bitz.com', - 'doc': 'https://apidoc.bitz.com/en/', + 'doc': 'https://apidocv2.bitz.plus/en/', 'fees': 'https://www.bitz.com/fee?type=1', 'referral': 'https://u.bitz.com/register?invite_code=1429193', }, @@ -76,6 +76,11 @@ module.exports = class bitz extends Exchange { 'currencyRate', 'currencyCoinRate', 'coinRate', + 'getContractCoin', + 'getContractKline', + 'getContractOrderBook', + 'getContractTradesHistory', + 'getContractTickers', ], }, 'trade': { @@ -88,6 +93,10 @@ module.exports = class bitz extends Exchange { 'getUserNowEntrustSheet', // open orders 'getEntrustSheetInfo', // order 'depositOrWithdraw', // transactions + 'getCoinAddress', + 'getCoinAddressList', + 'marketTrade', + 'addEntrustSheetBatch', ], }, 'assets': { @@ -95,6 +104,20 @@ module.exports = class bitz extends Exchange { 'getUserAssets', ], }, + 'contract': { + 'post': [ + 'addContractTrade', + 'cancelContractTrade', + 'getContractActivePositions', + 'getContractAccountInfo', + 'getContractMyPositions', + 'getContractOrderResult', + 'getContractTradeResult', + 'getContractOrder', + 'getContractMyHistoryTrade', + 'getContractMyTrades', + ], + }, }, 'fees': { 'trading': { @@ -281,8 +304,8 @@ module.exports = class bitz extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTrade'), - 'max': this.safeFloat (market, 'maxTrade'), + 'min': this.safeNumber (market, 'minTrade'), + 'max': this.safeNumber (market, 'maxTrade'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -331,12 +354,12 @@ module.exports = class bitz extends Exchange { const currencyId = this.safeString (balance, 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'lock'); - account['total'] = this.safeFloat (balance, 'num'); - account['free'] = this.safeFloat (balance, 'over'); + account['used'] = this.safeString (balance, 'lock'); + account['total'] = this.safeString (balance, 'num'); + account['free'] = this.safeString (balance, 'over'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTicker (ticker, market = undefined) { @@ -366,8 +389,8 @@ module.exports = class bitz extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'now'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'now'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -378,22 +401,22 @@ module.exports = class bitz extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': undefined, 'open': open, 'close': last, 'last': last, 'previousClose': undefined, 'change': change, - 'percentage': this.safeFloat (ticker, 'priceChange24h'), + 'percentage': this.safeNumber (ticker, 'priceChange24h'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -583,8 +606,8 @@ module.exports = class bitz extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const price = this.safeFloat (trade, 'p'); - const amount = this.safeFloat (trade, 'n'); + const price = this.safeNumber (trade, 'p'); + const amount = this.safeNumber (trade, 'n'); let cost = undefined; if (price !== undefined) { if (amount !== undefined) { @@ -652,11 +675,11 @@ module.exports = class bitz extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -754,22 +777,17 @@ module.exports = class bitz extends Exchange { if (side !== undefined) { side = (side === 'sale') ? 'sell' : 'buy'; } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'number'); - const remaining = this.safeFloat (order, 'numberOver'); - const filled = this.safeFloat (order, 'numberDeal'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'number'); + const remaining = this.safeNumber (order, 'numberOver'); + const filled = this.safeNumber (order, 'numberDeal'); let timestamp = this.safeInteger (order, 'timestamp'); if (timestamp === undefined) { timestamp = this.safeTimestamp (order, 'created'); } - let cost = this.safeFloat (order, 'orderTotalPrice'); - if (price !== undefined) { - if (filled !== undefined) { - cost = filled * price; - } - } + const cost = this.safeNumber (order, 'orderTotalPrice'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -791,7 +809,7 @@ module.exports = class bitz extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1118,7 +1136,7 @@ module.exports = class bitz extends Exchange { const type = this.safeStringLower (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'network_fee'); + const feeCost = this.safeNumber (transaction, 'network_fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1133,7 +1151,7 @@ module.exports = class bitz extends Exchange { 'address': this.safeString (transaction, 'wallet'), 'tag': this.safeString (transaction, 'memo'), 'type': type, - 'amount': this.safeFloat (transaction, 'number'), + 'amount': this.safeNumber (transaction, 'number'), 'currency': code, 'status': status, 'updated': timestamp, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bl3p.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bl3p.js index bb84442ec..832b5dc6f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bl3p.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bl3p.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -81,17 +82,19 @@ module.exports = class bl3p extends Exchange { const available = this.safeValue (wallet, 'available', {}); const balance = this.safeValue (wallet, 'balance', {}); const account = this.account (); - account['free'] = this.safeFloat (available, 'value'); - account['total'] = this.safeFloat (balance, 'value'); + account['free'] = this.safeString (available, 'value'); + account['total'] = this.safeString (balance, 'value'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { + const price = this.safeNumber (bidask, priceKey); + const size = this.safeNumber (bidask, amountKey); return [ - bidask[priceKey] / 100000.0, - bidask[amountKey] / 100000000.0, + price / 100000.0, + size / 100000000.0, ]; } @@ -111,16 +114,16 @@ module.exports = class bl3p extends Exchange { }; const ticker = await this.publicGetMarketTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -130,7 +133,7 @@ module.exports = class bl3p extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker['volume'], '24h'), + 'baseVolume': this.safeNumber (ticker['volume'], '24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -139,20 +142,13 @@ module.exports = class bl3p extends Exchange { parseTrade (trade, market = undefined) { const id = this.safeString (trade, 'trade_id'); const timestamp = this.safeInteger (trade, 'date'); - let price = this.safeFloat (trade, 'price_int'); - if (price !== undefined) { - price /= 100000.0; - } - let amount = this.safeFloat (trade, 'amount_int'); - if (amount !== undefined) { - amount /= 100000000.0; - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + let priceString = this.safeString (trade, 'price_int'); + priceString = Precise.stringDiv (priceString, '100000'); + let amountString = this.safeString (trade, 'amount_int'); + amountString = Precise.stringDiv (amountString, '100000000'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bleutrade.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bleutrade.js index 67262da33..01e7d30ce 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bleutrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bleutrade.js @@ -163,8 +163,8 @@ module.exports = class bleutrade extends Exchange { 'code': code, 'name': this.safeString (item, 'AssetLong'), 'active': this.safeValue (item, 'IsActive') && !this.safeValue (item, 'MaintenanceMode'), - 'fee': this.safeFloat (item, 'WithdrawTxFee'), - 'precision': this.safeFloat (item, 'DecimalPlaces'), + 'fee': this.safeNumber (item, 'WithdrawTxFee'), + 'precision': this.safeNumber (item, 'DecimalPlaces'), 'info': item, 'limits': this.limits, }; @@ -216,7 +216,7 @@ module.exports = class bleutrade extends Exchange { 'taker': this.fees['trading']['taker'], 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinTradeSize'), + 'min': this.safeNumber (market, 'MinTradeSize'), 'max': undefined, }, 'price': { @@ -292,8 +292,8 @@ module.exports = class bleutrade extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'TimeStamp')); const marketId = this.safeString (ticker, 'MarketName'); const symbol = this.safeSymbol (marketId, market, '_'); - const previous = this.safeFloat (ticker, 'PrevDay'); - const last = this.safeFloat (ticker, 'Last'); + const previous = this.safeNumber (ticker, 'PrevDay'); + const last = this.safeNumber (ticker, 'Last'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -308,11 +308,11 @@ module.exports = class bleutrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'High'), - 'low': this.safeFloat (ticker, 'Low'), - 'bid': this.safeFloat (ticker, 'Bid'), + 'high': this.safeNumber (ticker, 'High'), + 'low': this.safeNumber (ticker, 'Low'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': previous, @@ -322,8 +322,8 @@ module.exports = class bleutrade extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume'), - 'quoteVolume': this.safeFloat (ticker, 'BaseVolume'), + 'baseVolume': this.safeNumber (ticker, 'Volume'), + 'quoteVolume': this.safeNumber (ticker, 'BaseVolume'), 'info': ticker, }; } @@ -331,11 +331,11 @@ module.exports = class bleutrade extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (ohlcv['TimeStamp'] + '+00:00'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } @@ -411,11 +411,11 @@ module.exports = class bleutrade extends Exchange { const currencyId = this.safeString (item, 'Asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (item, 'Available'); - account['total'] = this.safeFloat (item, 'Balance'); + account['free'] = this.safeString (item, 'Available'); + account['total'] = this.safeString (item, 'Balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -558,7 +558,7 @@ module.exports = class bleutrade extends Exchange { // } const timestamp = this.parse8601 (this.safeString (item, 'TimeStamp')); - let amount = this.safeFloat (item, 'Amount'); + let amount = this.safeNumber (item, 'Amount'); let direction = undefined; if (amount !== undefined) { direction = 'in'; @@ -632,27 +632,12 @@ module.exports = class bleutrade extends Exchange { if ('Created' in order) { timestamp = this.parse8601 (order['Created'] + '+00:00'); } - let price = this.safeFloat (order, 'Price'); - let cost = undefined; - const amount = this.safeFloat (order, 'Quantity'); - const remaining = this.safeFloat (order, 'QuantityRemaining'); - let filled = undefined; - if (amount !== undefined && remaining !== undefined) { - filled = amount - remaining; - } - if (!cost) { - if (price && filled) { - cost = price * filled; - } - } - if (!price) { - if (cost && filled) { - price = cost / filled; - } - } - const average = this.safeFloat (order, 'PricePerUnit'); + const price = this.safeNumber (order, 'Price'); + const amount = this.safeNumber (order, 'Quantity'); + const remaining = this.safeNumber (order, 'QuantityRemaining'); + const average = this.safeNumber (order, 'PricePerUnit'); const id = this.safeString (order, 'OrderID'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -666,15 +651,15 @@ module.exports = class bleutrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -711,7 +696,7 @@ module.exports = class bleutrade extends Exchange { // Symbol: 'BTC' } // const id = this.safeString (transaction, 'ID'); - let amount = this.safeFloat (transaction, 'Amount'); + let amount = this.safeNumber (transaction, 'Amount'); let type = 'deposit'; if (amount < 0) { amount = Math.abs (amount); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/braziliex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/braziliex.js index 0c54e4840..31a519468 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/braziliex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/braziliex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -184,11 +185,11 @@ module.exports = class braziliex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': this.safeFloat (currency, 'txWithdrawalFee'), + 'fee': this.safeNumber (currency, 'txWithdrawalFee'), }, 'deposit': { 'active': canDeposit, - 'fee': this.safeFloat (currency, 'txDepositFee'), + 'fee': this.safeNumber (currency, 'txDepositFee'), }, }, 'limits': { @@ -205,11 +206,11 @@ module.exports = class braziliex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'MinWithdrawal'), + 'min': this.safeNumber (currency, 'MinWithdrawal'), 'max': Math.pow (10, precision), }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, }, @@ -257,9 +258,9 @@ module.exports = class braziliex extends Exchange { const quoteIsFiat = this.safeInteger (quoteCurrency, 'is_fiat', 0); let minCost = undefined; if (quoteIsFiat) { - minCost = this.safeFloat (baseCurrency, 'minAmountTradeFIAT'); + minCost = this.safeNumber (baseCurrency, 'minAmountTradeFIAT'); } else { - minCost = this.safeFloat (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); + minCost = this.safeNumber (baseCurrency, 'minAmountTrade' + uppercaseQuoteId); } const isActive = this.safeInteger (market, 'active'); const active = (isActive === 1); @@ -302,27 +303,27 @@ module.exports = class braziliex extends Exchange { symbol = market['symbol']; } const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highestBid24'), - 'low': this.safeFloat (ticker, 'lowestAsk24'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'highestBid24'), + 'low': this.safeNumber (ticker, 'lowestAsk24'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'percentChange'), + 'change': this.safeNumber (ticker, 'percentChange'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume24'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume24'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24'), 'info': ticker, }; } @@ -362,13 +363,18 @@ module.exports = class braziliex extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString2 (trade, 'date_exec', 'date')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } - const cost = this.safeFloat (trade, 'total'); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_number'); const type = 'limit'; const side = this.safeString (trade, 'type'); @@ -410,11 +416,11 @@ module.exports = class braziliex extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -436,21 +442,16 @@ module.exports = class braziliex extends Exchange { if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'date')); } - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'total', 0.0); - const amount = this.safeFloat (order, 'amount'); - const filledPercentage = this.safeFloat (order, 'progress'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'total'); + const amount = this.safeNumber (order, 'amount'); + const filledPercentage = this.safeNumber (order, 'progress'); const filled = amount * filledPercentage; - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); - let info = order; - if ('info' in info) { - info = order['info']; - } const id = this.safeString (order, 'order_number'); const fee = this.safeValue (order, 'fee'); // propagated from createOrder const status = (filledPercentage === 1.0) ? 'closed' : 'open'; const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -467,12 +468,12 @@ module.exports = class braziliex extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, - 'info': info, + 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -524,7 +525,7 @@ module.exports = class braziliex extends Exchange { 'price': this.safeString (priceParts, 1), 'total': this.safeString (totalParts, 1), 'fee': { - 'cost': this.safeFloat (feeParts, 1), + 'cost': this.safeNumber (feeParts, 1), 'currency': this.safeString (feeParts, 2), }, 'progress': '0.0', diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcalpha.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcalpha.js index 820234604..f7a890dfb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcalpha.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcalpha.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -145,8 +146,8 @@ module.exports = class btcalpha extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_order_size'), - 'max': this.safeFloat (market, 'maximum_order_size'), + 'min': this.safeNumber (market, 'minimum_order_size'), + 'max': this.safeNumber (market, 'maximum_order_size'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -198,14 +199,11 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'id', 'tid'); const side = this.safeString2 (trade, 'my_side', 'side'); const orderId = this.safeString (trade, 'o_id'); @@ -254,11 +252,11 @@ module.exports = class btcalpha extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -295,11 +293,11 @@ module.exports = class btcalpha extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'reserve'); - account['total'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserve'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -320,8 +318,8 @@ module.exports = class btcalpha extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (order, 'date'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString2 (order, 'oid', 'id'); let trades = this.safeValue (order, 'trades', []); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcbox.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcbox.js index 1a5f82456..48a455625 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcbox.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcbox.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, InvalidOrder, AuthenticationError, PermissionDenied, InvalidNonce, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -88,12 +89,12 @@ module.exports = class btcbox extends Exchange { if (free in response) { const account = this.account (); const used = currencyId + '_lock'; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -114,16 +115,16 @@ module.exports = class btcbox extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -133,8 +134,8 @@ module.exports = class btcbox extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -158,14 +159,11 @@ module.exports = class btcbox extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeString (trade, 'type'); return { @@ -265,15 +263,15 @@ module.exports = class btcbox extends Exchange { if (datetimeString !== undefined) { timestamp = this.parse8601 (order['datetime'] + '+09:00'); // Tokyo time } - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let cost = undefined; if (price !== undefined) { if (filled !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcmarkets.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcmarkets.js index 2340d1960..44cdd0f78 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcmarkets.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcmarkets.js @@ -246,11 +246,11 @@ module.exports = class btcmarkets extends Exchange { const tagTo = tag; const addressFrom = undefined; const tagFrom = undefined; - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const currencyId = this.safeString (transaction, 'assetName'); const code = this.safeCurrencyCode (currencyId); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (fee) { amount -= fee; } @@ -303,10 +303,10 @@ module.exports = class btcmarkets extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const fees = this.safeValue (this.safeValue (this.options, 'fees', {}), quote, this.fees); - const pricePrecision = this.safeFloat (market, 'priceDecimals'); - const amountPrecision = this.safeFloat (market, 'amountDecimals'); - const minAmount = this.safeFloat (market, 'minOrderAmount'); - const maxAmount = this.safeFloat (market, 'maxOrderAmount'); + const pricePrecision = this.safeNumber (market, 'priceDecimals'); + const amountPrecision = this.safeNumber (market, 'amountDecimals'); + const minAmount = this.safeNumber (market, 'minOrderAmount'); + const maxAmount = this.safeNumber (market, 'maxOrderAmount'); let minPrice = undefined; if (quote === 'AUD') { minPrice = Math.pow (10, -pricePrecision); @@ -365,14 +365,12 @@ module.exports = class btcmarkets extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetName'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance, 'balance'); - const used = this.safeFloat (balance, 'locked'); const account = this.account (); - account['used'] = used; - account['total'] = total; + account['used'] = this.safeString (balance, 'locked'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -388,11 +386,11 @@ module.exports = class btcmarkets extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 0)), - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 2), // high - this.safeFloat (ohlcv, 3), // low - this.safeFloat (ohlcv, 4), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 2), // high + this.safeNumber (ohlcv, 3), // low + this.safeNumber (ohlcv, 4), // close + this.safeNumber (ohlcv, 5), // volume ]; } @@ -488,21 +486,21 @@ module.exports = class btcmarkets extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'lastPrice'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); - const quoteVolume = this.safeFloat (ticker, 'volumeQte24h'); + const last = this.safeNumber (ticker, 'lastPrice'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); + const quoteVolume = this.safeNumber (ticker, 'volumeQte24h'); const vwap = this.vwap (baseVolume, quoteVolume); - const change = this.safeFloat (ticker, 'price24h'); - const percentage = this.safeFloat (ticker, 'pricePct24h'); + const change = this.safeNumber (ticker, 'price24h'); + const percentage = this.safeNumber (ticker, 'pricePct24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bestBid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'bestAsk'), + 'ask': this.safeNumber (ticker, 'bestAsk'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -613,8 +611,8 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -623,7 +621,7 @@ module.exports = class btcmarkets extends Exchange { } const orderId = this.safeString (trade, 'orderId'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -714,7 +712,7 @@ module.exports = class btcmarkets extends Exchange { } } if (triggerPriceIsRequired) { - const triggerPrice = this.safeFloat (params, 'triggerPrice'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); params = this.omit (params, 'triggerPrice'); if (triggerPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a triggerPrice parameter for a ' + type + 'order'); @@ -847,9 +845,9 @@ module.exports = class btcmarkets extends Exchange { side = 'sell'; } const type = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'openAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'openAmount'); let filled = undefined; if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); @@ -864,7 +862,7 @@ module.exports = class btcmarkets extends Exchange { const id = this.safeString (order, 'orderId'); const clientOrderId = this.safeString (order, 'clientOrderId'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btctradeua.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btctradeua.js index 011bc33b6..32527f881 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btctradeua.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btctradeua.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -106,10 +107,10 @@ module.exports = class btctradeua extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -249,14 +250,11 @@ module.exports = class btctradeua extends Exchange { const id = this.safeString (trade, 'id'); const type = 'limit'; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amnt_trade'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amnt_trade'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -337,11 +335,11 @@ module.exports = class btctradeua extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeString (order, 'type'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'amount': this.safeFloat (order, 'amnt_trade'), + 'amount': this.safeNumber (order, 'amnt_trade'), 'filled': 0, - 'remaining': this.safeFloat (order, 'amnt_trade'), + 'remaining': this.safeNumber (order, 'amnt_trade'), 'trades': undefined, 'info': order, 'cost': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcturk.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcturk.js index 32ea74550..2ef97bc99 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcturk.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/btcturk.js @@ -125,13 +125,13 @@ module.exports = class btcturk extends Exchange { const used = currency['id'] + '_reserved'; if (free in response) { const account = this.account (); - account['free'] = this.safeFloat (response, free); - account['total'] = this.safeFloat (response, total); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['total'] = this.safeString (response, total); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -151,26 +151,26 @@ module.exports = class btcturk extends Exchange { symbol = market['symbol']; } const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'average'), - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'average': this.safeNumber (ticker, 'average'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -204,8 +204,8 @@ module.exports = class btcturk extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -247,11 +247,11 @@ module.exports = class btcturk extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.parse8601 (this.safeString (ohlcv, 'Time')), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/buda.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/buda.js index e78c228ea..ac71ec42b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/buda.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/buda.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { AddressPending, AuthenticationError, ExchangeError, NotSupported, PermissionDenied, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -220,7 +221,7 @@ module.exports = class buda extends Exchange { } const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); - const precision = this.safeFloat (currency, 'input_decimals'); + const precision = this.safeNumber (currency, 'input_decimals'); const minimum = Math.pow (10, -precision); result[code] = { 'id': id, @@ -381,24 +382,25 @@ module.exports = class buda extends Exchange { let timestamp = undefined; let side = undefined; const type = undefined; - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; const order = undefined; const fee = undefined; let symbol = undefined; - let cost = undefined; if (market) { symbol = market['symbol']; } if (Array.isArray (trade)) { - timestamp = parseInt (trade[0]); - price = parseFloat (trade[1]); - amount = parseFloat (trade[2]); - cost = price * amount; - side = trade[3]; - id = trade[4].toString (); + timestamp = this.safeInteger (trade, 0); + priceString = this.safeString (trade, 1); + amountString = this.safeString (trade, 2); + side = this.safeString (trade, 3); + id = this.safeString (trade, 4); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': order, @@ -453,11 +455,11 @@ module.exports = class buda extends Exchange { const currencyId = this.safeString (balance, 'id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = parseFloat (balance['available_amount'][0]); - account['total'] = parseFloat (balance['amount'][0]); + account['free'] = this.safeString (balance['available_amount'], 0); + account['total'] = this.safeString (balance['amount'], 0); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -565,15 +567,15 @@ module.exports = class buda extends Exchange { const side = this.safeStringLower (order, 'type'); const status = this.parseOrderStatus (this.safeString (order, 'state')); const originalAmount = this.safeValue (order, 'original_amount', []); - const amount = this.safeFloat (originalAmount, 0); + const amount = this.safeNumber (originalAmount, 0); const remainingAmount = this.safeValue (order, 'amount', []); - const remaining = this.safeFloat (remainingAmount, 0); + const remaining = this.safeNumber (remainingAmount, 0); const tradedAmount = this.safeValue (order, 'traded_amount', []); - const filled = this.safeFloat (tradedAmount, 0); + const filled = this.safeNumber (tradedAmount, 0); const totalExchanged = this.safeValue (order, 'totalExchanged', []); - const cost = this.safeFloat (totalExchanged, 0); + const cost = this.safeNumber (totalExchanged, 0); const limitPrice = this.safeValue (order, 'limit', []); - let price = this.safeFloat (limitPrice, 0); + let price = this.safeNumber (limitPrice, 0); if (price === undefined) { if (limitPrice !== undefined) { price = limitPrice; @@ -584,7 +586,7 @@ module.exports = class buda extends Exchange { average = this.priceToPrecision (symbol, cost / filled); } const paidFee = this.safeValue (order, 'paid_fee', []); - const feeCost = this.safeFloat (paidFee, 0); + const feeCost = this.safeNumber (paidFee, 0); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (paidFee, 1); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bw.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bw.js index 388946b39..4fb3b4192 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bw.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bw.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { RateLimitExceeded, BadSymbol, OrderNotFound, ExchangeError, AuthenticationError, ArgumentsRequired, ExchangeNotAvailable } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -185,7 +186,7 @@ module.exports = class bw extends Exchange { const symbol = base + '/' + quote; const state = this.safeInteger (market, 'state'); const active = (state === 1); - const fee = this.safeFloat (market, 'defaultFee'); + const fee = this.safeNumber (market, 'defaultFee'); result.push ({ 'id': id, 'active': active, @@ -206,7 +207,7 @@ module.exports = class bw extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -292,11 +293,11 @@ module.exports = class bw extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'drawFee'), + 'fee': this.safeNumber (currency, 'drawFee'), 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'limitAmount', 0), + 'min': this.safeNumber (currency, 'limitAmount', 0), 'max': undefined, }, 'price': { @@ -309,7 +310,7 @@ module.exports = class bw extends Exchange { }, 'withdraw': { 'min': undefined, - 'max': this.safeFloat (currency, 'onceDrawLimit'), + 'max': this.safeNumber (currency, 'onceDrawLimit'), }, }, }; @@ -346,9 +347,9 @@ module.exports = class bw extends Exchange { 'high': parseFloat (this.safeValue (ticker, 2)), 'low': parseFloat (this.safeValue (ticker, 3)), 'bid': parseFloat (this.safeValue (ticker, 7)), - 'bidVolume': this.safeFloat (bid, 'quantity'), + 'bidVolume': this.safeNumber (bid, 'quantity'), 'ask': parseFloat (this.safeValue (ticker, 8)), - 'askVolume': this.safeFloat (ask, 'quantity'), + 'askVolume': this.safeNumber (ask, 'quantity'), 'vwap': undefined, 'open': undefined, 'close': close, @@ -477,8 +478,11 @@ module.exports = class bw extends Exchange { // ... // const timestamp = this.safeTimestamp (trade, 2); - const price = this.safeFloat (trade, 5); - const amount = this.safeFloat (trade, 6); + const priceString = this.safeString (trade, 5); + const amountString = this.safeString (trade, 6); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 1); let symbol = undefined; if (marketId !== undefined) { @@ -495,12 +499,6 @@ module.exports = class bw extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const sideString = this.safeString (trade, 4); const side = (sideString === 'ask') ? 'sell' : 'buy'; return { @@ -514,7 +512,7 @@ module.exports = class bw extends Exchange { 'takerOrMaker': undefined, 'price': price, 'amount': amount, - 'cost': parseFloat (cost), + 'cost': cost, 'fee': undefined, 'info': trade, }; @@ -571,11 +569,11 @@ module.exports = class bw extends Exchange { // return [ this.safeTimestamp (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), - this.safeFloat (ohlcv, 6), - this.safeFloat (ohlcv, 7), - this.safeFloat (ohlcv, 8), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + this.safeNumber (ohlcv, 6), + this.safeNumber (ohlcv, 7), + this.safeNumber (ohlcv, 8), ]; } @@ -633,11 +631,11 @@ module.exports = class bw extends Exchange { const currencyId = this.safeString (balance, 'currencyTypeId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'amount'); - account['used'] = this.safeFloat (balance, 'freeze'); + account['free'] = this.safeString (balance, 'amount'); + account['used'] = this.safeString (balance, 'freeze'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -733,25 +731,13 @@ module.exports = class bw extends Exchange { } else if (side === '1') { side = 'buy'; } - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'completeAmount'); - let remaining = this.safeFloat2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available - let cost = this.safeFloat (order, 'totalMoney'); - if (filled !== undefined) { - if (amount !== undefined) { - if (remaining === undefined) { - remaining = amount - filled; - } - } - if (cost === undefined) { - if (price !== undefined) { - cost = filled * cost; - } - } - } + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'completeAmount'); + const remaining = this.safeNumber2 (order, 'availabelAmount', 'availableAmount'); // typo in the docs or in the API, availabel vs available + const cost = this.safeNumber (order, 'totalMoney'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'entrustId'), 'clientOrderId': undefined, @@ -773,7 +759,7 @@ module.exports = class bw extends Exchange { 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1069,12 +1055,12 @@ module.exports = class bw extends Exchange { code = currency['code']; } const type = ('depositId' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat2 (transaction, 'actuallyAmount', 'amount'); + const amount = this.safeNumber2 (transaction, 'actuallyAmount', 'amount'); const status = this.parseTransactionStatus (this.safeString2 (transaction, 'verifyStatus', 'state')); const timestamp = this.safeInteger (transaction, 'createTime'); const txid = this.safeString (transaction, 'txId'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bybit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bybit.js index f74d0db18..7f818c6e3 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bybit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bybit.js @@ -42,6 +42,7 @@ module.exports = class bybit extends Exchange { 'fetchTrades': true, 'fetchTransactions': false, 'fetchWithdrawals': true, + 'fetchPositions': true, }, 'timeframes': { '1m': '1', @@ -73,6 +74,34 @@ module.exports = class bybit extends Exchange { 'referral': 'https://www.bybit.com/app/register?ref=X7Prm', }, 'api': { + 'futures': { + 'private': { + 'get': [ + 'position/list', + 'order/list', + 'order', + 'stop-order/list', + 'stop-order', + 'execution/list', + 'trade/closed-pnl/list', + ], + 'post': [ + 'order/create', + 'order/cancel', + 'order/cancelAll', + 'order/replace', + 'stop-order/create', + 'stop-order/cancel', + 'stop-order/cancelAll', + 'stop-order/replace', + 'position/change-position-margin', + 'position/trading-stop', + 'position/leverage/save', + 'position/switch-mode', + 'position/switch-isolated', + ], + }, + }, 'v2': { 'public': { 'get': [ @@ -286,7 +315,11 @@ module.exports = class bybit extends Exchange { 'LTC/USDT': 'linear', 'XTZ/USDT': 'linear', 'LINK/USDT': 'linear', + 'ADA/USDT': 'linear', + 'DOT/USDT': 'linear', + 'UNI/USDT': 'linear', }, + 'defaultType': 'linear', // may also be inverse or inverseFuture 'code': 'BTC', 'cancelAllOrders': { // 'method': 'v2PrivatePostOrderCancelAll', // v2PrivatePostStopOrderCancelAll @@ -401,8 +434,8 @@ module.exports = class bybit extends Exchange { const lotSizeFilter = this.safeValue (market, 'lot_size_filter', {}); const priceFilter = this.safeValue (market, 'price_filter', {}); const precision = { - 'amount': this.safeFloat (lotSizeFilter, 'qty_step'), - 'price': this.safeFloat (priceFilter, 'tick_size'), + 'amount': this.safeNumber (lotSizeFilter, 'qty_step'), + 'price': this.safeNumber (priceFilter, 'tick_size'), }; const status = this.safeString (market, 'status'); let active = undefined; @@ -416,8 +449,8 @@ module.exports = class bybit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'type': 'future', 'spot': false, 'future': true, @@ -426,12 +459,12 @@ module.exports = class bybit extends Exchange { 'inverse': inverse, 'limits': { 'amount': { - 'min': this.safeFloat (lotSizeFilter, 'min_trading_qty'), - 'max': this.safeFloat (lotSizeFilter, 'max_trading_qty'), + 'min': this.safeNumber (lotSizeFilter, 'min_trading_qty'), + 'max': this.safeNumber (lotSizeFilter, 'max_trading_qty'), }, 'price': { - 'min': this.safeFloat (priceFilter, 'min_price'), - 'max': this.safeFloat (priceFilter, 'max_price'), + 'min': this.safeNumber (priceFilter, 'min_price'), + 'max': this.safeNumber (priceFilter, 'max_price'), }, 'cost': { 'min': undefined, @@ -477,9 +510,9 @@ module.exports = class bybit extends Exchange { const timestamp = undefined; const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const open = this.safeFloat (ticker, 'prev_price_24h'); - let percentage = this.safeFloat (ticker, 'price_24h_pcnt'); + const last = this.safeNumber (ticker, 'last_price'); + const open = this.safeNumber (ticker, 'prev_price_24h'); + let percentage = this.safeNumber (ticker, 'price_24h_pcnt'); if (percentage !== undefined) { percentage *= 100; } @@ -489,18 +522,18 @@ module.exports = class bybit extends Exchange { change = last - open; average = this.sum (open, last) / 2; } - const baseVolume = this.safeFloat (ticker, 'turnover_24h'); - const quoteVolume = this.safeFloat (ticker, 'volume_24h'); + const baseVolume = this.safeNumber (ticker, 'turnover_24h'); + const quoteVolume = this.safeNumber (ticker, 'volume_24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price_24h'), - 'low': this.safeFloat (ticker, 'low_price_24h'), - 'bid': this.safeFloat (ticker, 'bid_price'), + 'high': this.safeNumber (ticker, 'high_price_24h'), + 'low': this.safeNumber (ticker, 'low_price_24h'), + 'bid': this.safeNumber (ticker, 'bid_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask_price'), + 'ask': this.safeNumber (ticker, 'ask_price'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -649,11 +682,11 @@ module.exports = class bybit extends Exchange { // return [ this.safeTimestamp2 (ohlcv, 'open_time', 'start_at'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat2 (ohlcv, 'turnover', 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber2 (ohlcv, 'turnover', 'volume'), ]; } @@ -779,9 +812,9 @@ module.exports = class bybit extends Exchange { const marketId = this.safeString (trade, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat2 (trade, 'qty', 'exec_qty'); - let cost = this.safeFloat (trade, 'exec_value'); - const price = this.safeFloat2 (trade, 'exec_price', 'price'); + const amount = this.safeNumber2 (trade, 'qty', 'exec_qty'); + let cost = this.safeNumber (trade, 'exec_value'); + const price = this.safeNumber2 (trade, 'exec_price', 'price'); if (cost === undefined) { if (amount !== undefined) { if (price !== undefined) { @@ -796,14 +829,14 @@ module.exports = class bybit extends Exchange { const side = this.safeStringLower (trade, 'side'); const lastLiquidityInd = this.safeString (trade, 'last_liquidity_ind'); const takerOrMaker = (lastLiquidityInd === 'AddedLiquidity') ? 'maker' : 'taker'; - const feeCost = this.safeFloat (trade, 'exec_fee'); + const feeCost = this.safeNumber (trade, 'exec_fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyCode = market['inverse'] ? market['base'] : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'fee_rate'), + 'rate': this.safeNumber (trade, 'fee_rate'), }; } return { @@ -963,12 +996,12 @@ module.exports = class bybit extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['used'] = this.safeFloat (balance, 'used_margin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'used_margin'); + account['total'] = this.safeString (balance, 'equity'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -1095,56 +1128,42 @@ module.exports = class bybit extends Exchange { // const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); - let symbol = undefined; - let base = undefined; + const symbol = market['symbol']; + let feeCurrency = undefined; const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const id = this.safeString2 (order, 'order_id', 'stop_order_id'); const type = this.safeStringLower (order, 'order_type'); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - let average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'qty'); - let cost = this.safeFloat (order, 'cum_exec_value'); - let filled = this.safeFloat (order, 'cum_exec_qty'); - let remaining = this.safeFloat (order, 'leaves_qty'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'qty'); + const cost = this.safeNumber (order, 'cum_exec_value'); + const filled = this.safeNumber (order, 'cum_exec_qty'); + const remaining = this.safeNumber (order, 'leaves_qty'); + const marketTypes = this.safeValue (this.options, 'marketTypes', {}); + const marketType = this.safeString (marketTypes, symbol); if (market !== undefined) { - symbol = market['symbol']; - base = market['base']; + if (marketType === 'linear') { + feeCurrency = market['quote']; + } else { + feeCurrency = market['base']; + } } let lastTradeTimestamp = this.safeTimestamp (order, 'last_exec_time'); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = amount - remaining; - } - if (filled !== undefined) { - if ((remaining === undefined) && (amount !== undefined)) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if ((type === 'market') && (cost !== undefined) && (cost > 0)) { - price = undefined; - if (average === undefined) { - average = filled / cost; - } - } - } const status = this.parseOrderStatus (this.safeString2 (order, 'order_status', 'stop_order_status')); const side = this.safeStringLower (order, 'side'); - let feeCost = this.safeFloat (order, 'cum_exec_fee'); + let feeCost = this.safeNumber (order, 'cum_exec_fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); fee = { 'cost': feeCost, - 'currency': base, + 'currency': feeCurrency, }; } let clientOrderId = this.safeString (order, 'order_link_id'); @@ -1152,9 +1171,9 @@ module.exports = class bybit extends Exchange { clientOrderId = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); - const stopPrice = this.safeFloat (order, 'stop_px'); + const stopPrice = this.safeNumber (order, 'stop_px'); const postOnly = (timeInForce === 'PO'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1176,7 +1195,7 @@ module.exports = class bybit extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -2027,7 +2046,8 @@ module.exports = class bybit extends Exchange { const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); + const type = this.safeStringLower (transaction, 'type'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -2047,8 +2067,8 @@ module.exports = class bybit extends Exchange { 'tag': undefined, 'tagTo': undefined, 'tagFrom': undefined, - 'type': 'withdrawal', - 'amount': this.safeFloat (transaction, 'amount'), + 'type': type, + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -2131,8 +2151,8 @@ module.exports = class bybit extends Exchange { // const currencyId = this.safeString (item, 'coin'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'wallet_balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'wallet_balance'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -2198,7 +2218,8 @@ module.exports = class bybit extends Exchange { 'recv_window': this.options['recvWindow'], 'timestamp': timestamp, }); - const auth = this.rawencode (this.keysort (query)); + const sortedQuery = this.keysort (query); + const auth = this.rawencode (sortedQuery); const signature = this.hmac (this.encode (auth), this.encode (this.secret)); if (method === 'POST') { body = this.json (this.extend (query, { @@ -2208,7 +2229,7 @@ module.exports = class bybit extends Exchange { 'Content-Type': 'application/json', }; } else { - request += '?' + auth + '&sign=' + signature; + request += '?' + this.urlencode (sortedQuery) + '&sign=' + signature; } } url += request; @@ -2231,12 +2252,43 @@ module.exports = class bybit extends Exchange { // time_now: '1583934106.590436' // } // - const errorCode = this.safeValue (response, 'ret_code'); - if (errorCode !== 0) { + const errorCode = this.safeString (response, 'ret_code'); + if (errorCode !== '0') { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback); this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback); throw new ExchangeError (feedback); // unknown message } } + + async fetchPositions (symbols = undefined, params = {}) { + await this.loadMarkets (); + const request = {}; + if (Array.isArray (symbols)) { + const length = symbols.length; + if (length !== 1) { + throw new ArgumentsRequired (this.id + ' fetchPositions takes exactly one symbol'); + } + request['symbol'] = this.marketId (symbols[0]); + } + const defaultType = this.safeString (this.options, 'defaultType', 'linear'); + const type = this.safeString (params, 'type', defaultType); + params = this.omit (params, 'type'); + let response = undefined; + if (type === 'linear') { + response = await this.privateLinearGetPositionList (this.extend (request, params)); + } else if (type === 'inverse') { + response = await this.v2PrivateGetPositionList (this.extend (request, params)); + } else if (type === 'inverseFuture') { + response = await this.futuresPrivateGetPositionList (this.extend (request, params)); + } + // { + // ret_code: 0, + // ret_msg: 'OK', + // ext_code: '', + // ext_info: '', + // result: [] or {} depending on the request + // } + return this.safeValue (response, 'result'); + } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bytetrade.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bytetrade.js index 25953b6f7..ad0c929d8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bytetrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/bytetrade.js @@ -186,12 +186,12 @@ module.exports = class bytetrade extends Exchange { const limits = this.safeValue (currency, 'limits'); const deposit = this.safeValue (limits, 'deposit'); const amountPrecision = this.safeInteger (currency, 'basePrecision'); - let maxDeposit = this.safeFloat (deposit, 'max'); + let maxDeposit = this.safeNumber (deposit, 'max'); if (maxDeposit === -1.0) { maxDeposit = undefined; } const withdraw = this.safeValue (limits, 'withdraw'); - let maxWithdraw = this.safeFloat (withdraw, 'max'); + let maxWithdraw = this.safeNumber (withdraw, 'max'); if (maxWithdraw === -1.0) { maxWithdraw = undefined; } @@ -207,11 +207,11 @@ module.exports = class bytetrade extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (deposit, 'min'), + 'min': this.safeNumber (deposit, 'min'), 'max': maxDeposit, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'min'), + 'min': this.safeNumber (withdraw, 'min'), 'max': maxWithdraw, }, }, @@ -265,12 +265,12 @@ module.exports = class bytetrade extends Exchange { 'normalSymbol': normalSymbol, 'limits': { 'amount': { - 'min': this.safeFloat (amount, 'min'), - 'max': this.safeFloat (amount, 'max'), + 'min': this.safeNumber (amount, 'min'), + 'max': this.safeNumber (amount, 'max'), }, 'price': { - 'min': this.safeFloat (price, 'min'), - 'max': this.safeFloat (price, 'max'), + 'min': this.safeNumber (price, 'min'), + 'max': this.safeNumber (price, 'max'), }, 'cost': { 'min': undefined, @@ -298,11 +298,11 @@ module.exports = class bytetrade extends Exchange { const currencyId = this.safeString (balance, 'code'); const code = this.safeCurrencyCode (currencyId, undefined); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'used'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'used'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -363,22 +363,22 @@ module.exports = class bytetrade extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), - 'open': this.safeFloat (ticker, 'open'), - 'close': this.safeFloat (ticker, 'close'), - 'last': this.safeFloat (ticker, 'last'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), + 'open': this.safeNumber (ticker, 'open'), + 'close': this.safeNumber (ticker, 'close'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, // previous day close - 'change': this.safeFloat (ticker, 'change'), - 'percentage': this.safeFloat (ticker, 'percentage'), + 'change': this.safeNumber (ticker, 'change'), + 'percentage': this.safeNumber (ticker, 'percentage'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -421,24 +421,16 @@ module.exports = class bytetrade extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidsAsks (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetDepth (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetDepth (params); + return this.parseTickers (response, symbols); } async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const rawTickers = await this.marketGetTickers (params); - return this.parseTickers (rawTickers, symbols); + const response = await this.marketGetTickers (params); + return this.parseTickers (response, symbols); } parseOHLCV (ohlcv, market = undefined) { @@ -454,11 +446,11 @@ module.exports = class bytetrade extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -488,9 +480,9 @@ module.exports = class bytetrade extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeInteger (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - const cost = this.safeFloat (trade, 'cost'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); + const cost = this.safeNumber (trade, 'cost'); const id = this.safeString (trade, 'id'); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'takerOrMaker'); @@ -560,12 +552,12 @@ module.exports = class bytetrade extends Exchange { const timestamp = this.safeInteger (order, 'timestamp'); const datetime = this.safeString (order, 'datetime'); const lastTradeTimestamp = this.safeInteger (order, 'lastTradeTimestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled'); - const remaining = this.safeFloat (order, 'remaining'); - const cost = this.safeFloat (order, 'cost'); - const average = this.safeFloat (order, 'average'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled'); + const remaining = this.safeNumber (order, 'remaining'); + const cost = this.safeNumber (order, 'cost'); + const average = this.safeNumber (order, 'average'); const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); @@ -958,7 +950,7 @@ module.exports = class bytetrade extends Exchange { }; } - async transfer (code, amount, address, message = '', params = {}) { + async transfer (code, amount, fromAccount, toAccount, params = {}) { this.checkRequiredDependencies (); if (this.apiKey === undefined) { throw new ArgumentsRequired ('transfer() requires this.apiKey'); @@ -976,6 +968,7 @@ module.exports = class bytetrade extends Exchange { expirationDatetime = expirationDatetime.split ('.')[0]; const feeAmount = '300000000000000'; const defaultDappId = 'Sagittarius'; + const message = this.safeString (params, 'message', ''); const dappId = this.safeString (params, 'dappId', defaultDappId); const eightBytes = this.integerPow ('2', '64'); const byteStringArray = [ @@ -989,8 +982,8 @@ module.exports = class bytetrade extends Exchange { this.numberToLE (feeAmount, 8), // string for 32 bit php this.numberToLE (this.apiKey.length, 1), this.stringToBinary (this.encode (this.apiKey)), - this.numberToLE (address.length, 1), - this.stringToBinary (this.encode (address)), + this.numberToLE (toAccount.length, 1), + this.stringToBinary (this.encode (toAccount)), this.numberToLE (assetType, 4), this.numberToLE (this.integerDivide (amountChain, eightBytes), 8), this.numberToLE (this.integerModulo (amountChain, eightBytes), 8), @@ -1011,7 +1004,7 @@ module.exports = class bytetrade extends Exchange { const operation = { 'fee': '300000000000000', 'from': this.apiKey, - 'to': address, + 'to': toAccount, 'asset_type': parseInt (currency['id']), 'amount': amountChain.toString (), 'message': message, @@ -1165,9 +1158,9 @@ module.exports = class bytetrade extends Exchange { const datetime = this.safeString (transaction, 'datetime'); const type = this.safeString (transaction, 'type'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const feeInfo = this.safeValue (transaction, 'fee'); - const feeCost = this.safeFloat (feeInfo, 'cost'); + const feeCost = this.safeNumber (feeInfo, 'cost'); const feeCurrencyId = this.safeString (feeInfo, 'code'); const feeCode = this.safeCurrencyCode (feeCurrencyId, currency); const fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/cex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/cex.js index 77473d391..876830762 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/cex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/cex.js @@ -256,7 +256,7 @@ module.exports = class cex extends Exchange { 'fee': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimumCurrencyAmount'), + 'min': this.safeNumber (currency, 'minimumCurrencyAmount'), 'max': undefined, }, 'price': { @@ -268,7 +268,7 @@ module.exports = class cex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimalWithdrawalAmount'), + 'min': this.safeNumber (currency, 'minimalWithdrawalAmount'), 'max': undefined, }, }, @@ -351,15 +351,15 @@ module.exports = class cex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minLotSize'), - 'max': this.safeFloat (market, 'maxLotSize'), + 'min': this.safeNumber (market, 'minLotSize'), + 'max': this.safeNumber (market, 'maxLotSize'), }, 'price': { - 'min': this.safeFloat (market, 'minPrice'), - 'max': this.safeFloat (market, 'maxPrice'), + 'min': this.safeNumber (market, 'minPrice'), + 'max': this.safeNumber (market, 'maxPrice'), }, 'cost': { - 'min': this.safeFloat (market, 'minLotSizeS2'), + 'min': this.safeNumber (market, 'minLotSizeS2'), 'max': undefined, }, }, @@ -380,13 +380,13 @@ module.exports = class cex extends Exchange { const currencyId = currencyIds[i]; const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); + account['free'] = this.safeString (balance, 'available'); // https://github.com/ccxt/ccxt/issues/5484 - account['used'] = this.safeFloat (balance, 'orders', 0.0); + account['used'] = this.safeString (balance, 'orders', '0'); const code = this.safeCurrencyCode (currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -415,11 +415,11 @@ module.exports = class cex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -461,12 +461,12 @@ module.exports = class cex extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const volume = this.safeFloat (ticker, 'volume'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'last'); + const volume = this.safeNumber (ticker, 'volume'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'last'); let symbol = undefined; if (market) { symbol = market['symbol']; @@ -528,8 +528,8 @@ module.exports = class cex extends Exchange { const id = this.safeString (trade, 'tid'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let cost = undefined; if (amount !== undefined) { if (price !== undefined) { @@ -601,8 +601,8 @@ module.exports = class cex extends Exchange { // "complete": false // } // - const placedAmount = this.safeFloat (response, 'amount'); - const remaining = this.safeFloat (response, 'pending'); + const placedAmount = this.safeNumber (response, 'amount'); + const remaining = this.safeNumber (response, 'pending'); const timestamp = this.safeValue (response, 'time'); const complete = this.safeValue (response, 'complete'); const status = complete ? 'closed' : 'open'; @@ -621,7 +621,7 @@ module.exports = class cex extends Exchange { 'side': this.safeString (response, 'type'), 'symbol': symbol, 'status': status, - 'price': this.safeFloat (response, 'price'), + 'price': this.safeNumber (response, 'price'), 'amount': placedAmount, 'cost': undefined, 'average': undefined, @@ -663,42 +663,42 @@ module.exports = class cex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - let amount = this.safeFloat (order, 'amount'); + const price = this.safeNumber (order, 'price'); + let amount = this.safeNumber (order, 'amount'); // sell orders can have a negative amount // https://github.com/ccxt/ccxt/issues/5338 if (amount !== undefined) { amount = Math.abs (amount); } - const remaining = this.safeFloat2 (order, 'pending', 'remains'); + const remaining = this.safeNumber2 (order, 'pending', 'remains'); const filled = amount - remaining; let fee = undefined; let cost = undefined; if (market !== undefined) { symbol = market['symbol']; - const taCost = this.safeFloat (order, 'ta:' + market['quote']); - const ttaCost = this.safeFloat (order, 'tta:' + market['quote']); + const taCost = this.safeNumber (order, 'ta:' + market['quote']); + const ttaCost = this.safeNumber (order, 'tta:' + market['quote']); cost = this.sum (taCost, ttaCost); const baseFee = 'fa:' + market['base']; const baseTakerFee = 'tfa:' + market['base']; const quoteFee = 'fa:' + market['quote']; const quoteTakerFee = 'tfa:' + market['quote']; - let feeRate = this.safeFloat (order, 'tradingFeeMaker'); + let feeRate = this.safeNumber (order, 'tradingFeeMaker'); if (!feeRate) { - feeRate = this.safeFloat (order, 'tradingFeeTaker', feeRate); + feeRate = this.safeNumber (order, 'tradingFeeTaker', feeRate); } if (feeRate) { feeRate /= 100.0; // convert to mathematically-correct percentage coefficients: 1.0 = 100% } if ((baseFee in order) || (baseTakerFee in order)) { - const baseFeeCost = this.safeFloat2 (order, baseFee, baseTakerFee); + const baseFeeCost = this.safeNumber2 (order, baseFee, baseTakerFee); fee = { 'currency': market['base'], 'rate': feeRate, 'cost': baseFeeCost, }; } else if ((quoteFee in order) || (quoteTakerFee in order)) { - const quoteFeeCost = this.safeFloat2 (order, quoteFee, quoteTakerFee); + const quoteFeeCost = this.safeNumber2 (order, quoteFee, quoteTakerFee); fee = { 'currency': market['quote'], 'rate': feeRate, @@ -738,7 +738,7 @@ module.exports = class cex extends Exchange { // ds: 0 } continue; } - const tradePrice = this.safeFloat (item, 'price'); + const tradePrice = this.safeNumber (item, 'price'); if (tradePrice === undefined) { // this represents the order // { @@ -842,8 +842,8 @@ module.exports = class cex extends Exchange { // "fee_amount": "0.03" // } const tradeTimestamp = this.parse8601 (this.safeString (item, 'time')); - const tradeAmount = this.safeFloat (item, 'amount'); - const feeCost = this.safeFloat (item, 'fee_amount'); + const tradeAmount = this.safeNumber (item, 'amount'); + const feeCost = this.safeNumber (item, 'fee_amount'); let absTradeAmount = (tradeAmount < 0) ? -tradeAmount : tradeAmount; let tradeCost = undefined; if (tradeSide === 'sell') { @@ -1188,12 +1188,12 @@ module.exports = class cex extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const side = this.safeString (order, 'type'); - const baseAmount = this.safeFloat (order, 'a:' + baseId + ':cds'); - const quoteAmount = this.safeFloat (order, 'a:' + quoteId + ':cds'); - const fee = this.safeFloat (order, 'f:' + quoteId + ':cds'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const remaining = this.safeFloat (order, 'remains'); + const baseAmount = this.safeNumber (order, 'a:' + baseId + ':cds'); + const quoteAmount = this.safeNumber (order, 'a:' + quoteId + ':cds'); + const fee = this.safeNumber (order, 'f:' + quoteId + ':cds'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const remaining = this.safeNumber (order, 'remains'); const filled = amount - remaining; let orderAmount = undefined; let cost = undefined; @@ -1205,10 +1205,10 @@ module.exports = class cex extends Exchange { cost = quoteAmount; average = orderAmount / cost; } else { - const ta = this.safeFloat (order, 'ta:' + quoteId, 0); - const tta = this.safeFloat (order, 'tta:' + quoteId, 0); - const fa = this.safeFloat (order, 'fa:' + quoteId, 0); - const tfa = this.safeFloat (order, 'tfa:' + quoteId, 0); + const ta = this.safeNumber (order, 'ta:' + quoteId, 0); + const tta = this.safeNumber (order, 'tta:' + quoteId, 0); + const fa = this.safeNumber (order, 'fa:' + quoteId, 0); + const tfa = this.safeNumber (order, 'tfa:' + quoteId, 0); if (side === 'sell') { cost = this.sum (this.sum (ta, tta), this.sum (fa, tfa)); } else { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/chilebit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/chilebit.js deleted file mode 100644 index 4aeeb9ec3..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/chilebit.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const foxbit = require ('./foxbit.js'); - -// --------------------------------------------------------------------------- - -module.exports = class chilebit extends foxbit { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'chilebit', - 'name': 'ChileBit', - 'countries': [ 'CL' ], - 'has': { - 'CORS': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27991414-1298f0d8-647f-11e7-9c40-d56409266336.jpg', - 'api': { - 'public': 'https://api.blinktrade.com/api', - 'private': 'https://api.blinktrade.com/tapi', - }, - 'www': 'https://chilebit.net', - 'doc': 'https://blinktrade.com/docs', - }, - 'options': { - 'brokerId': '9', // https://blinktrade.com/docs/#brokers - }, - }); - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbase.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbase.js index cfceba2a4..1413a7064 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbase.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbase.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError, RateLimitExceeded, InvalidNonce } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -411,10 +412,10 @@ module.exports = class coinbase extends Exchange { const timestamp = this.parse8601 (this.safeValue (transaction, 'created_at')); const updated = this.parse8601 (this.safeValue (transaction, 'updated_at')); const type = this.safeString (transaction, 'resource'); - const amount = this.safeFloat (subtotalObject, 'amount'); + const amount = this.safeNumber (subtotalObject, 'amount'); const currencyId = this.safeString (subtotalObject, 'currency'); const currency = this.safeCurrencyCode (currencyId); - const feeCost = this.safeFloat (feeObject, 'amount'); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -490,15 +491,12 @@ module.exports = class coinbase extends Exchange { const orderId = undefined; const side = this.safeString (trade, 'resource'); const type = undefined; - const cost = this.safeFloat (subtotalObject, 'amount'); - const amount = this.safeFloat (amountObject, 'amount'); - let price = undefined; - if (cost !== undefined) { - if ((amount !== undefined) && (amount > 0)) { - price = cost / amount; - } - } - const feeCost = this.safeFloat (feeObject, 'amount'); + const costString = this.safeString (subtotalObject, 'amount'); + const amountString = this.safeString (amountObject, 'amount'); + const cost = this.parseNumber (costString); + const amount = this.parseNumber (amountString); + const price = this.parseNumber (Precise.stringDiv (costString, amountString)); + const feeCost = this.safeNumber (feeObject, 'amount'); const feeCurrencyId = this.safeString (feeObject, 'currency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); const fee = { @@ -566,7 +564,7 @@ module.exports = class coinbase extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (quoteCurrency, 'min_size'), + 'min': this.safeNumber (quoteCurrency, 'min_size'), 'max': undefined, }, }, @@ -648,7 +646,7 @@ module.exports = class coinbase extends Exchange { 'precision': undefined, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min_size'), + 'min': this.safeNumber (currency, 'min_size'), 'max': undefined, }, 'price': { @@ -679,9 +677,9 @@ module.exports = class coinbase extends Exchange { const buy = await this.publicGetPricesSymbolBuy (request); const sell = await this.publicGetPricesSymbolSell (request); const spot = await this.publicGetPricesSymbolSpot (request); - const ask = this.safeFloat (buy['data'], 'amount'); - const bid = this.safeFloat (sell['data'], 'amount'); - const last = this.safeFloat (spot['data'], 'amount'); + const ask = this.safeNumber (buy['data'], 'amount'); + const bid = this.safeNumber (sell['data'], 'amount'); + const last = this.safeNumber (spot['data'], 'amount'); return { 'symbol': symbol, 'timestamp': timestamp, @@ -724,7 +722,7 @@ module.exports = class coinbase extends Exchange { if (this.inArray (balance['type'], accounts)) { const currencyId = this.safeString (balance['balance'], 'currency'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (balance['balance'], 'amount'); + const total = this.safeNumber (balance['balance'], 'amount'); const free = total; const used = undefined; if (code in result) { @@ -1025,7 +1023,7 @@ module.exports = class coinbase extends Exchange { // } // const amountInfo = this.safeValue (item, 'amount', {}); - let amount = this.safeFloat (amountInfo, 'amount'); + let amount = this.safeNumber (amountInfo, 'amount'); let direction = undefined; if (amount < 0) { direction = 'out'; @@ -1051,7 +1049,7 @@ module.exports = class coinbase extends Exchange { if (feeInfo !== undefined) { const feeCurrencyId = this.safeString (feeInfo, 'currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId, currency); - const feeAmount = this.safeFloat (feeInfo, 'amount'); + const feeAmount = this.safeNumber (feeInfo, 'amount'); fee = { 'cost': feeAmount, 'currency': feeCurrencyCode, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbasepro.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbasepro.js index 582c03a61..6d8c48454 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbasepro.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinbasepro.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ArgumentsRequired, ExchangeError, InvalidOrder, InvalidAddress, AuthenticationError, NotSupported, OrderNotFound, OnMaintenance, PermissionDenied, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -239,7 +240,7 @@ module.exports = class coinbasepro extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const details = this.safeValue (currency, 'details', {}); - const precision = this.safeFloat (currency, 'max_precision'); + const precision = this.safeNumber (currency, 'max_precision'); const status = this.safeString (currency, 'status'); const active = (status === 'online'); result[code] = { @@ -253,7 +254,7 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (details, 'min_size'), + 'min': this.safeNumber (details, 'min_size'), 'max': undefined, }, 'price': { @@ -265,7 +266,7 @@ module.exports = class coinbasepro extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (details, 'min_withdrawal_amount'), + 'min': this.safeNumber (details, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -309,12 +310,12 @@ module.exports = class coinbasepro extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const priceLimits = { - 'min': this.safeFloat (market, 'quote_increment'), + 'min': this.safeNumber (market, 'quote_increment'), 'max': undefined, }; const precision = { - 'amount': this.safeFloat (market, 'base_increment'), - 'price': this.safeFloat (market, 'quote_increment'), + 'amount': this.safeNumber (market, 'base_increment'), + 'price': this.safeNumber (market, 'quote_increment'), }; const status = this.safeString (market, 'status'); const active = (status === 'online'); @@ -328,13 +329,13 @@ module.exports = class coinbasepro extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'base_min_size'), - 'max': this.safeFloat (market, 'base_max_size'), + 'min': this.safeNumber (market, 'base_min_size'), + 'max': this.safeNumber (market, 'base_max_size'), }, 'price': priceLimits, 'cost': { - 'min': this.safeFloat (market, 'min_market_funds'), - 'max': this.safeFloat (market, 'max_market_funds'), + 'min': this.safeNumber (market, 'min_market_funds'), + 'max': this.safeNumber (market, 'max_market_funds'), }, }, 'active': active, @@ -391,14 +392,13 @@ module.exports = class coinbasepro extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'hold'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'hold'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -455,29 +455,29 @@ module.exports = class coinbasepro extends Exchange { // } // const timestamp = this.parse8601 (this.safeValue (ticker, 'time')); - const bid = this.safeFloat (ticker, 'bid'); - const ask = this.safeFloat (ticker, 'ask'); - const last = this.safeFloat (ticker, 'price'); + const bid = this.safeNumber (ticker, 'bid'); + const ask = this.safeNumber (ticker, 'ask'); + const last = this.safeNumber (ticker, 'price'); const symbol = (market === undefined) ? undefined : market['symbol']; return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': undefined, 'ask': ask, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -550,7 +550,7 @@ module.exports = class coinbasepro extends Exchange { if (market !== undefined) { const feeCurrencyId = this.safeStringLower (market, 'quoteId'); const costField = feeCurrencyId + '_value'; - cost = this.safeFloat (trade, costField); + cost = this.safeNumber (trade, costField); feeCurrency = market['quote']; const liquidity = this.safeString (trade, 'liquidity'); if (liquidity !== undefined) { @@ -558,7 +558,7 @@ module.exports = class coinbasepro extends Exchange { feeRate = market[takerOrMaker]; } } - const feeCost = this.safeFloat2 (trade, 'fill_fees', 'fee'); + const feeCost = this.safeNumber2 (trade, 'fill_fees', 'fee'); const fee = { 'cost': feeCost, 'currency': feeCurrency, @@ -572,10 +572,12 @@ module.exports = class coinbasepro extends Exchange { if (orderId !== undefined) { side = (trade['side'] === 'buy') ? 'buy' : 'sell'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - cost = amount * price; + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -637,11 +639,11 @@ module.exports = class coinbasepro extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -721,17 +723,11 @@ module.exports = class coinbasepro extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'filled_size'); - const amount = this.safeFloat (order, 'size', filled); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'executed_value'); - const feeCost = this.safeFloat (order, 'fill_fees'); + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'filled_size'); + const amount = this.safeNumber (order, 'size', filled); + const cost = this.safeNumber (order, 'executed_value'); + const feeCost = this.safeNumber (order, 'fill_fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrencyCode = undefined; @@ -749,9 +745,9 @@ module.exports = class coinbasepro extends Exchange { const side = this.safeString (order, 'side'); const timeInForce = this.safeString (order, 'time_in_force'); const postOnly = this.safeValue (order, 'post_only'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); const clientOrderId = this.safeString (order, 'client_oid'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -769,11 +765,11 @@ module.exports = class coinbasepro extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -863,7 +859,7 @@ module.exports = class coinbasepro extends Exchange { request['client_oid'] = clientOrderId; params = this.omit (params, [ 'clientOrderId', 'client_oid' ]); } - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop_price'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stop_price'); if (stopPrice !== undefined) { request['stop_price'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, [ 'stopPrice', 'stop_price' ]); @@ -877,7 +873,7 @@ module.exports = class coinbasepro extends Exchange { request['price'] = this.priceToPrecision (symbol, price); request['size'] = this.amountToPrecision (symbol, amount); } else if (type === 'market') { - let cost = this.safeFloat2 (params, 'cost', 'funds'); + let cost = this.safeNumber2 (params, 'cost', 'funds'); if (cost === undefined) { if (price !== undefined) { cost = amount * price; @@ -948,19 +944,6 @@ module.exports = class coinbasepro extends Exchange { return await this.privateDeleteOrders (this.extend (request, params)); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - const cost = amount * price; - const currency = market['quote']; - return { - 'type': takerOrMaker, - 'currency': currency, - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (currency, rate * cost)), - }; - } - async fetchPaymentMethods (params = {}) { return await this.privateGetPaymentMethods (params); } @@ -1099,7 +1082,7 @@ module.exports = class coinbasepro extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (transaction); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let type = this.safeString (transaction, 'type'); let address = this.safeString (details, 'crypto_address'); const tag = this.safeString (details, 'destination_tag'); @@ -1108,7 +1091,7 @@ module.exports = class coinbasepro extends Exchange { if (type === 'withdraw') { type = 'withdrawal'; address = this.safeString (details, 'sent_to_address', address); - const feeCost = this.safeFloat (details, 'fee'); + const feeCost = this.safeNumber (details, 'fee'); if (feeCost !== undefined) { if (amount !== undefined) { amount -= feeCost; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coincheck.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coincheck.js index 807882d02..e7a3db265 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coincheck.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coincheck.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -127,12 +128,12 @@ module.exports = class coincheck extends Exchange { if (currencyId in balances) { const account = this.account (); const reserved = currencyId + '_reserved'; - account['free'] = this.safeFloat (balances, currencyId); - account['used'] = this.safeFloat (balances, reserved); + account['free'] = this.safeString (balances, currencyId); + account['used'] = this.safeString (balances, reserved); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -170,23 +171,13 @@ module.exports = class coincheck extends Exchange { const id = this.safeString (order, 'id'); const side = this.safeString (order, 'order_type'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const amount = this.safeFloat (order, 'pending_amount'); - const remaining = this.safeFloat (order, 'pending_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = Math.max (amount - remaining, 0); - if (price !== undefined) { - cost = filled * price; - } - } - } + const amount = this.safeNumber (order, 'pending_amount'); + const remaining = this.safeNumber (order, 'pending_amount'); + const price = this.safeNumber (order, 'rate'); const status = undefined; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -194,7 +185,7 @@ module.exports = class coincheck extends Exchange { 'lastTradeTimestamp': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'side': side, 'type': undefined, 'timeInForce': undefined, @@ -203,12 +194,12 @@ module.exports = class coincheck extends Exchange { 'symbol': symbol, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'info': order, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -232,16 +223,16 @@ module.exports = class coincheck extends Exchange { }; const ticker = await this.publicGetTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -251,7 +242,7 @@ module.exports = class coincheck extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -260,7 +251,7 @@ module.exports = class coincheck extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'rate'); + const priceString = this.safeString (trade, 'rate'); const marketId = this.safeString (trade, 'pair'); market = this.safeValue (this.markets_by_id, marketId, market); let symbol = undefined; @@ -287,7 +278,7 @@ module.exports = class coincheck extends Exchange { } } let takerOrMaker = undefined; - let amount = undefined; + let amountString = undefined; let cost = undefined; let side = undefined; let fee = undefined; @@ -299,24 +290,22 @@ module.exports = class coincheck extends Exchange { takerOrMaker = 'maker'; } const funds = this.safeValue (trade, 'funds', {}); - amount = this.safeFloat (funds, baseId); - cost = this.safeFloat (funds, quoteId); + amountString = this.safeString (funds, baseId); + cost = this.safeNumber (funds, quoteId); fee = { 'currency': this.safeString (trade, 'fee_currency'), - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), }; side = this.safeString (trade, 'side'); orderId = this.safeString (trade, 'order_id'); } else { - amount = this.safeFloat (trade, 'amount'); + amountString = this.safeString (trade, 'amount'); side = this.safeString (trade, 'order_type'); } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'id': id, @@ -387,6 +376,10 @@ module.exports = class coincheck extends Exchange { return await this.privateDeleteExchangeOrdersId (this.extend (request, params)); } + nonce () { + return this.milliseconds (); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { let url = this.urls['api'] + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinegg.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinegg.js index e270e3bf7..0b2e2ef89 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinegg.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinegg.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -214,8 +215,8 @@ module.exports = class coinegg extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; let change = undefined; let average = undefined; @@ -229,11 +230,11 @@ module.exports = class coinegg extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -243,8 +244,8 @@ module.exports = class coinegg extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVol'), 'info': ticker, }; } @@ -273,15 +274,12 @@ module.exports = class coinegg extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = this.costToPrecision (symbol, price * amount); - } - } const type = 'limit'; const side = this.safeString (trade, 'type'); const id = this.safeString (trade, 'tid'); @@ -328,9 +326,9 @@ module.exports = class coinegg extends Exchange { result[code] = this.account (); } const type = (accountType === 'lock') ? 'used' : 'free'; - result[code][type] = this.safeFloat (balances, key); + result[code][type] = this.safeString (balances, key); } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -339,15 +337,9 @@ module.exports = class coinegg extends Exchange { symbol = market['symbol']; } const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount_original'); - const remaining = this.safeFloat (order, 'amount_outstanding'); - let filled = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount_original'); + const remaining = this.safeNumber (order, 'amount_outstanding'); let status = this.safeString (order, 'status'); if (status === 'cancelled') { status = 'canceled'; @@ -358,7 +350,7 @@ module.exports = class coinegg extends Exchange { const type = 'limit'; const side = this.safeString (order, 'type'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -374,13 +366,13 @@ module.exports = class coinegg extends Exchange { 'stopPrice': undefined, 'cost': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'trades': undefined, 'fee': undefined, 'info': info, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinex.js index cc344ee72..575d0f239 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -196,13 +197,13 @@ module.exports = class coinex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': this.safeFloat (market, 'taker_fee_rate'), - 'maker': this.safeFloat (market, 'maker_fee_rate'), + 'taker': this.safeNumber (market, 'taker_fee_rate'), + 'maker': this.safeNumber (market, 'maker_fee_rate'), 'info': market, 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -222,16 +223,16 @@ module.exports = class coinex extends Exchange { symbol = market['symbol']; } ticker = this.safeValue (ticker, 'ticker', {}); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -241,7 +242,7 @@ module.exports = class coinex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat2 (ticker, 'vol', 'volume'), + 'baseVolume': this.safeNumber2 (ticker, 'vol', 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -301,16 +302,18 @@ module.exports = class coinex extends Exchange { } const tradeId = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market); - let cost = this.safeFloat (trade, 'deal_money'); - if (!cost) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); + let cost = this.safeNumber (trade, 'deal_money'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_asset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -363,11 +366,11 @@ module.exports = class coinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -428,11 +431,11 @@ module.exports = class coinex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -471,11 +474,11 @@ module.exports = class coinex extends Exchange { // } // const timestamp = this.safeTimestamp (order, 'create_time'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'deal_money'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'deal_amount'); - const average = this.safeFloat (order, 'avg_price'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'deal_money'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'deal_amount'); + const average = this.safeNumber (order, 'avg_price'); let symbol = undefined; const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); @@ -487,11 +490,11 @@ module.exports = class coinex extends Exchange { feeCurrency = market['quote']; } } - const remaining = this.safeFloat (order, 'left'); + const remaining = this.safeNumber (order, 'left'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -513,10 +516,10 @@ module.exports = class coinex extends Exchange { 'trades': undefined, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'deal_fee'), + 'cost': this.safeNumber (order, 'deal_fee'), }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -762,8 +765,8 @@ module.exports = class coinex extends Exchange { const timestamp = this.safeTimestamp (transaction, 'create_time'); const type = ('coin_withdraw_id' in transaction) ? 'withdraw' : 'deposit'; const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); - let feeCost = this.safeFloat (transaction, 'tx_fee'); + let amount = this.safeNumber (transaction, 'amount'); + let feeCost = this.safeNumber (transaction, 'tx_fee'); if (type === 'deposit') { feeCost = 0; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfalcon.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfalcon.js index 6c264b4ec..8d3077293 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfalcon.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfalcon.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, RateLimitExceeded, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -136,11 +137,11 @@ module.exports = class coinfalcon extends Exchange { 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'change_in_24h'), + 'change': this.safeNumber (ticker, 'change_in_24h'), 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -177,20 +178,17 @@ module.exports = class coinfalcon extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const symbol = market['symbol']; - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } const tradeId = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'order_id'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = this.safeString (trade, 'fee_currency_code'); fee = { @@ -258,14 +256,13 @@ module.exports = class coinfalcon extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'currency_code'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available_balance'), - 'used': this.safeFloat (balance, 'hold_balance'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available_balance'); + account['used'] = this.safeString (balance, 'hold_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -300,19 +297,9 @@ module.exports = class coinfalcon extends Exchange { const marketId = this.safeString (order, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'created_at')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'size_filled'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (price !== undefined) { - cost = filled * price; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'size_filled'); const status = this.parseOrderStatus (this.safeString (order, 'status')); let type = this.safeString (order, 'operation_type'); if (type !== undefined) { @@ -321,7 +308,7 @@ module.exports = class coinfalcon extends Exchange { } const side = this.safeString (order, 'order_type'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -334,16 +321,16 @@ module.exports = class coinfalcon extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'lastTradeTimestamp': undefined, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfloor.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfloor.js index 7fff650de..790ac8c50 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfloor.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinfloor.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { InsufficientFunds, ExchangeError, InvalidNonce, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -105,14 +106,14 @@ module.exports = class coinfloor extends Exchange { const baseIdLower = this.safeStringLower (market, 'baseId'); const quoteIdLower = this.safeStringLower (market, 'quoteId'); result[base] = { - 'free': this.safeFloat (response, baseIdLower + '_available'), - 'used': this.safeFloat (response, baseIdLower + '_reserved'), - 'total': this.safeFloat (response, baseIdLower + '_balance'), + 'free': this.safeNumber (response, baseIdLower + '_available'), + 'used': this.safeNumber (response, baseIdLower + '_reserved'), + 'total': this.safeNumber (response, baseIdLower + '_balance'), }; result[quote] = { - 'free': this.safeFloat (response, quoteIdLower + '_available'), - 'used': this.safeFloat (response, quoteIdLower + '_reserved'), - 'total': this.safeFloat (response, quoteIdLower + '_balance'), + 'free': this.safeNumber (response, quoteIdLower + '_available'), + 'used': this.safeNumber (response, quoteIdLower + '_reserved'), + 'total': this.safeNumber (response, quoteIdLower + '_balance'), }; return this.parseBalance (result); } @@ -133,22 +134,22 @@ module.exports = class coinfloor extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -177,14 +178,11 @@ module.exports = class coinfloor extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -302,8 +300,8 @@ module.exports = class coinfloor extends Exchange { const parts = key.split ('_'); const numParts = parts.length; if (numParts === 2) { - const tmpBaseAmount = this.safeFloat (item, parts[0]); - const tmpQuoteAmount = this.safeFloat (item, parts[1]); + const tmpBaseAmount = this.safeNumber (item, parts[0]); + const tmpQuoteAmount = this.safeNumber (item, parts[1]); if (tmpBaseAmount !== undefined && tmpQuoteAmount !== undefined) { baseId = parts[0]; quoteId = parts[1]; @@ -319,7 +317,7 @@ module.exports = class coinfloor extends Exchange { const referenceId = this.safeString (item, 'id'); const timestamp = this.parse8601 (this.safeString (item, 'datetime')); let fee = undefined; - const feeCost = this.safeFloat (item, 'fee'); + const feeCost = this.safeNumber (item, 'fee'); const result = { 'id': undefined, 'timestamp': timestamp, @@ -423,8 +421,8 @@ module.exports = class coinfloor extends Exchange { 'datetime': this.iso8601 (timestamp), 'timestamp': timestamp, 'type': type, - 'price': this.safeFloat (response, 'price'), - 'remaining': this.safeFloat (response, 'amount'), + 'price': this.safeNumber (response, 'price'), + 'remaining': this.safeNumber (response, 'amount'), 'info': response, }; } @@ -449,19 +447,14 @@ module.exports = class coinfloor extends Exchange { parseOrder (order, market = undefined) { const timestamp = this.parse8601 (this.safeString (order, 'datetime')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); let side = undefined; const status = this.safeString (order, 'status'); - if (order['type'] === 0) { + const rawType = this.safeString (order, 'type'); + if (rawType === '0') { side = 'buy'; - } else if (order['type'] === 1) { + } else if (rawType === '1') { side = 'sell'; } let symbol = undefined; @@ -469,7 +462,7 @@ module.exports = class coinfloor extends Exchange { symbol = market['symbol']; } const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -487,11 +480,11 @@ module.exports = class coinfloor extends Exchange { 'amount': undefined, 'filled': undefined, 'remaining': amount, - 'cost': cost, + 'cost': undefined, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coingi.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coingi.js index 650d80885..931325ea6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coingi.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coingi.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -165,14 +166,14 @@ module.exports = class coingi extends Exchange { const currencyId = this.safeString (balance['currency'], 'name'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - const blocked = this.safeFloat (balance, 'blocked'); - const inOrders = this.safeFloat (balance, 'inOrders'); - const withdrawing = this.safeFloat (balance, 'withdrawing'); - account['used'] = this.sum (blocked, inOrders, withdrawing); + account['free'] = this.safeString (balance, 'available'); + const blocked = this.safeString (balance, 'blocked'); + const inOrders = this.safeString (balance, 'inOrders'); + const withdrawing = this.safeString (balance, 'withdrawing'); + account['used'] = Precise.stringAdd (Precise.stringAdd (blocked, inOrders), withdrawing); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = 512, params = {}) { @@ -198,11 +199,11 @@ module.exports = class coingi extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -212,8 +213,8 @@ module.exports = class coingi extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'counterVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'counterVolume'), 'info': ticker, }; } @@ -246,14 +247,11 @@ module.exports = class coingi extends Exchange { } parseTrade (trade, market = undefined) { - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const timestamp = this.safeInteger (trade, 'timestamp'); const id = this.safeString (trade, 'id'); const marketId = this.safeString (trade, 'currencyPair'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmarketcap.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmarketcap.js index 171a65889..85edd4882 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmarketcap.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmarketcap.js @@ -208,16 +208,16 @@ module.exports = class coinmarketcap extends Exchange { if (timestamp === undefined) { timestamp = this.milliseconds (); } - const change = this.safeFloat (ticker, 'percent_change_24h'); + const change = this.safeNumber (ticker, 'percent_change_24h'); let last = undefined; let symbol = undefined; let volume = undefined; if (market !== undefined) { symbol = market['symbol']; const priceKey = 'price_' + market['quoteId']; - last = this.safeFloat (ticker, priceKey); + last = this.safeNumber (ticker, priceKey); const volumeKey = '24h_volume_' + market['quoteId']; - volume = this.safeFloat (ticker, volumeKey); + volume = this.safeNumber (ticker, volumeKey); } return { 'symbol': symbol, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmate.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmate.js index b03ce8783..821e5d7e8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmate.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinmate.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder, OrderNotFound, RateLimitExceeded, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -230,7 +231,7 @@ module.exports = class coinmate extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -258,12 +259,12 @@ module.exports = class coinmate extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -286,16 +287,16 @@ module.exports = class coinmate extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'data'); const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'vwap': undefined, 'askVolume': undefined, 'open': undefined, @@ -305,7 +306,7 @@ module.exports = class coinmate extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'amount'), + 'baseVolume': this.safeNumber (ticker, 'amount'), 'quoteVolume': undefined, 'info': ticker, }; @@ -374,8 +375,8 @@ module.exports = class coinmate extends Exchange { // } // const timestamp = this.safeInteger (item, 'timestamp'); - const amount = this.safeFloat (item, 'amount'); - const fee = this.safeFloat (item, 'fee'); + const amount = this.safeNumber (item, 'amount'); + const fee = this.safeNumber (item, 'fee'); const txid = this.safeString (item, 'txid'); const address = this.safeString (item, 'destination'); const tag = this.safeString (item, 'destinationTag'); @@ -453,21 +454,18 @@ module.exports = class coinmate extends Exchange { // const marketId = this.safeString (trade, 'currencyPair'); market = this.safeMarket (marketId, market, '_'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeStringLower2 (trade, 'type', 'tradeType'); const type = this.safeStringLower (trade, 'orderType'); const orderId = this.safeString (trade, 'orderId'); const id = this.safeString (trade, 'transactionId'); const timestamp = this.safeInteger2 (trade, 'timestamp', 'createdTimestamp'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -608,11 +606,11 @@ module.exports = class coinmate extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.safeInteger (order, 'timestamp'); const side = this.safeStringLower (order, 'type'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'originalAmount'); - let remaining = this.safeFloat (order, 'remainingAmount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'originalAmount'); + let remaining = this.safeNumber (order, 'remainingAmount'); if (remaining === undefined) { - remaining = this.safeFloat (order, 'amount'); + remaining = this.safeNumber (order, 'amount'); } let status = this.parseOrderStatus (this.safeString (order, 'status')); const type = this.parseOrderType (this.safeString (order, 'orderTradeType')); @@ -627,11 +625,11 @@ module.exports = class coinmate extends Exchange { cost = filled * price; } } - const average = this.safeFloat (order, 'avgPrice'); + const average = this.safeNumber (order, 'avgPrice'); const marketId = this.safeString (order, 'currencyPair'); const symbol = this.safeSymbol (marketId, market, '_'); const clientOrderId = this.safeString (order, 'clientOrderId'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); return { 'id': id, 'clientOrderId': clientOrderId, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinone.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinone.js index 0c86365b6..cd0f3585c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinone.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinone.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, BadRequest, ExchangeError, ArgumentsRequired, OrderNotFound, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -142,11 +143,11 @@ module.exports = class coinone extends Exchange { const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'avail'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -199,13 +200,13 @@ module.exports = class coinone extends Exchange { parseTicker (ticker, market = undefined) { const timestamp = this.safeTimestamp (ticker, 'timestamp'); - const first = this.safeFloat (ticker, 'first'); - const last = this.safeFloat (ticker, 'last'); + const first = this.safeNumber (ticker, 'first'); + const last = this.safeNumber (ticker, 'last'); let average = undefined; if (first !== undefined && last !== undefined) { average = this.sum (first, last) / 2; } - const previousClose = this.safeFloat (ticker, 'yesterday_last'); + const previousClose = this.safeNumber (ticker, 'yesterday_last'); let change = undefined; let percentage = undefined; if (last !== undefined && previousClose !== undefined) { @@ -219,8 +220,8 @@ module.exports = class coinone extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -233,7 +234,7 @@ module.exports = class coinone extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -279,20 +280,17 @@ module.exports = class coinone extends Exchange { side = 'buy'; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'fee'); + let feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); - let feeRate = this.safeFloat (trade, 'feeRate'); + let feeRate = this.safeNumber (trade, 'feeRate'); feeRate = Math.abs (feeRate); let feeCurrencyCode = undefined; if (market !== undefined) { @@ -452,7 +450,7 @@ module.exports = class coinone extends Exchange { // } // const id = this.safeString (order, 'orderId'); - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); const timestamp = this.safeTimestamp (order, 'timestamp'); let side = this.safeString (order, 'type'); if (side === 'ask') { @@ -460,9 +458,8 @@ module.exports = class coinone extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const remaining = this.safeFloat (order, 'remainQty'); - let filled = undefined; - const amount = this.safeFloat (order, 'qty'); + const remaining = this.safeNumber (order, 'remainQty'); + const amount = this.safeNumber (order, 'qty'); let status = this.safeString (order, 'status'); // https://github.com/ccxt/ccxt/pull/7067 if (status === 'live') { @@ -472,14 +469,7 @@ module.exports = class coinone extends Exchange { } } } - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (amount - remaining); - } status = this.parseOrderStatus (status); - let cost = undefined; - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } let symbol = undefined; let base = undefined; let quote = undefined; @@ -499,16 +489,16 @@ module.exports = class coinone extends Exchange { quote = market['quote']; } let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = (side === 'sell') ? quote : base; fee = { 'cost': feeCost, - 'rate': this.safeFloat (order, 'feeRate'), + 'rate': this.safeNumber (order, 'feeRate'), 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -522,15 +512,15 @@ module.exports = class coinone extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': amount, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -605,8 +595,8 @@ module.exports = class coinone extends Exchange { // eslint-disable-next-line quotes throw new ArgumentsRequired (this.id + " cancelOrder() requires a symbol argument. To cancel the order, pass a symbol argument and {'price': 12345, 'qty': 1.2345, 'is_ask': 0} in the params argument of cancelOrder."); } - const price = this.safeFloat (params, 'price'); - const qty = this.safeFloat (params, 'qty'); + const price = this.safeNumber (params, 'price'); + const qty = this.safeNumber (params, 'qty'); const isAsk = this.safeInteger (params, 'is_ask'); if ((price === undefined) || (qty === undefined) || (isAsk === undefined)) { // eslint-disable-next-line quotes diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinspot.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinspot.js index e04c42b5d..63c9b3fd2 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinspot.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/coinspot.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -123,7 +124,7 @@ module.exports = class coinspot extends Exchange { const balance = currencies[currencyId]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } } @@ -133,11 +134,11 @@ module.exports = class coinspot extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -157,16 +158,16 @@ module.exports = class coinspot extends Exchange { id = id.toLowerCase (); const ticker = response['prices'][id]; const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -214,11 +215,13 @@ module.exports = class coinspot extends Exchange { // "market":"BTC/AUD" // } // - const price = this.safeFloat (trade, 'rate'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'total'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger (trade, 'solddate'); const marketId = this.safeString (trade, 'market'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/crex24.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/crex24.js index 7c1298090..5c3a3ccde 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/crex24.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/crex24.js @@ -4,6 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, InvalidNonce, RequestTimeout, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, AuthenticationError, BadSymbol } = require ('./base/errors'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -110,6 +112,7 @@ module.exports = class crex24 extends Exchange { ], }, }, + 'precisionMode': TICK_SIZE, 'fees': { 'trading': { 'tierBased': true, @@ -130,6 +133,7 @@ module.exports = class crex24 extends Exchange { 'BIT': 'BitMoney', 'BULL': 'BuySell', 'CREDIT': 'TerraCredit', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'GHOST': 'GHOSTPRISM', 'IQ': 'IQ.Cash', 'PUT': 'PutinCoin', @@ -163,6 +167,7 @@ module.exports = class crex24 extends Exchange { 'API Key': AuthenticationError, // "API Key '9edc48de-d5b0-4248-8e7e-f59ffcd1c7f1' doesn't exist." 'Insufficient funds': InsufficientFunds, // "Insufficient funds: new order requires 10 ETH which is more than the available balance." 'has been delisted.': BadSymbol, // {"errorDescription":"Instrument '$PAC-BTC' has been delisted."} + 'is currently suspended.': BadSymbol, // {"errorDescription":"Trading in BITG-BTC is currently suspended."} 'Mandatory parameter': BadRequest, // {"errorDescription":"Mandatory parameter 'feeCurrency' is missing."} }, }, @@ -204,12 +209,12 @@ module.exports = class crex24 extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const tickSize = this.safeValue (market, 'tickSize'); - const minPrice = this.safeValue (market, 'minPrice'); - const minAmount = this.safeFloat (market, 'minVolume'); + const tickSize = this.safeNumber (market, 'tickSize'); + const minPrice = this.safeNumber (market, 'minPrice'); + const minAmount = this.safeNumber (market, 'minVolume'); const precision = { - 'amount': this.precisionFromString (this.numberToString (minAmount)), - 'price': this.precisionFromString (this.numberToString (tickSize)), + 'amount': minAmount, + 'price': tickSize, }; const active = (market['state'] === 'active'); result.push ({ @@ -274,7 +279,8 @@ module.exports = class crex24 extends Exchange { const currency = response[i]; const id = this.safeString (currency, 'symbol'); const code = this.safeCurrencyCode (id); - const precision = this.safeInteger (currency, 'withdrawalPrecision'); + const withdrawalPrecision = this.safeInteger (currency, 'withdrawalPrecision'); + const precision = Math.pow (10, -withdrawalPrecision); const address = this.safeValue (currency, 'BaseAddress'); const active = (currency['depositsAllowed'] && currency['withdrawalsAllowed'] && !currency['isDelisted']); const type = currency['isFiat'] ? 'fiat' : 'crypto'; @@ -286,7 +292,7 @@ module.exports = class crex24 extends Exchange { 'type': type, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'flatWithdrawalFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'flatWithdrawalFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -302,12 +308,12 @@ module.exports = class crex24 extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'minDeposit'), + 'min': this.safeNumber (currency, 'minDeposit'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -337,11 +343,11 @@ module.exports = class crex24 extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -393,16 +399,16 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); const marketId = this.safeString (ticker, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -410,10 +416,10 @@ module.exports = class crex24 extends Exchange { 'last': last, 'previousClose': undefined, // previous day close 'change': undefined, - 'percentage': this.safeFloat (ticker, 'percentChange'), + 'percentage': this.safeNumber (ticker, 'percentChange'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'baseVolume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'baseVolume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -483,14 +489,6 @@ module.exports = class crex24 extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - parseTrade (trade, market = undefined) { // // public fetchTrades @@ -515,14 +513,11 @@ module.exports = class crex24 extends Exchange { // } // const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeString (trade, 'side'); const orderId = this.safeString (trade, 'orderId'); @@ -531,7 +526,7 @@ module.exports = class crex24 extends Exchange { let fee = undefined; const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCode = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -592,11 +587,11 @@ module.exports = class crex24 extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -665,50 +660,19 @@ module.exports = class crex24 extends Exchange { const marketId = this.safeString (order, 'instrument'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'timestamp')); - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remainingVolume'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remainingVolume'); const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'lastUpdate')); - let cost = undefined; - if (remaining !== undefined) { - if (amount !== undefined) { - filled = amount - remaining; - if (this.options['parseOrderToPrecision']) { - filled = parseFloat (this.amountToPrecision (symbol, filled)); - } - filled = Math.max (filled, 0.0); - if (price !== undefined) { - cost = price * filled; - } - } - } const id = this.safeString (order, 'id'); const type = this.safeString (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeString (order, 'side'); const fee = undefined; const trades = undefined; - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } - } + const average = undefined; const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -722,14 +686,14 @@ module.exports = class crex24 extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -764,7 +728,7 @@ module.exports = class crex24 extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order'); } else { @@ -1183,8 +1147,8 @@ module.exports = class crex24 extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'createdAt')); const updated = this.parse8601 (this.safeString (transaction, 'processedAt')); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); const fee = { 'cost': feeCost, 'currency': code, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/currencycom.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/currencycom.js index c8570f1d4..17aa6bfa5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/currencycom.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/currencycom.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, BadRequest } = require ('./base/errors'); -const { ROUND, TICK_SIZE } = require ('./base/functions/number'); +const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -92,6 +93,7 @@ module.exports = class currencycom extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.002, @@ -250,7 +252,7 @@ module.exports = class currencycom extends Exchange { const filtersByType = this.indexBy (filters, 'filterType'); const precision = { 'amount': 1 / Math.pow (1, this.safeInteger (market, 'baseAssetPrecision')), - 'price': this.safeFloat (market, 'tickSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const status = this.safeString (market, 'status'); const active = (status === 'TRADING'); @@ -283,14 +285,14 @@ module.exports = class currencycom extends Exchange { 'max': undefined, }, 'cost': { - 'min': -1 * Math.log10 (precision['amount']), + 'min': -Math.log10 (precision['amount']), 'max': undefined, }, }, }; - const exchangeFee = this.safeFloat2 (market, 'exchangeFee', 'tradingFee'); - const makerFee = this.safeFloat (market, 'makerFee', exchangeFee); - const takerFee = this.safeFloat (market, 'takerFee', exchangeFee); + const exchangeFee = this.safeNumber2 (market, 'exchangeFee', 'tradingFee'); + const makerFee = this.safeNumber (market, 'makerFee', exchangeFee); + const takerFee = this.safeNumber (market, 'takerFee', exchangeFee); if (makerFee !== undefined) { entry['maker'] = makerFee / 100; } @@ -299,65 +301,44 @@ module.exports = class currencycom extends Exchange { } if ('PRICE_FILTER' in filtersByType) { const filter = this.safeValue (filtersByType, 'PRICE_FILTER', {}); - entry['precision']['price'] = this.safeFloat (filter, 'tickSize'); + entry['precision']['price'] = this.safeNumber (filter, 'tickSize'); // PRICE_FILTER reports zero values for maxPrice // since they updated filter types in November 2018 // https://github.com/ccxt/ccxt/issues/4286 // therefore limits['price']['max'] doesn't have any meaningful value except undefined entry['limits']['price'] = { - 'min': this.safeFloat (filter, 'minPrice'), + 'min': this.safeNumber (filter, 'minPrice'), 'max': undefined, }; - const maxPrice = this.safeFloat (filter, 'maxPrice'); + const maxPrice = this.safeNumber (filter, 'maxPrice'); if ((maxPrice !== undefined) && (maxPrice > 0)) { entry['limits']['price']['max'] = maxPrice; } } if ('LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'LOT_SIZE', {}); - entry['precision']['amount'] = this.safeFloat (filter, 'stepSize'); + entry['precision']['amount'] = this.safeNumber (filter, 'stepSize'); entry['limits']['amount'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MARKET_LOT_SIZE' in filtersByType) { const filter = this.safeValue (filtersByType, 'MARKET_LOT_SIZE', {}); entry['limits']['market'] = { - 'min': this.safeFloat (filter, 'minQty'), - 'max': this.safeFloat (filter, 'maxQty'), + 'min': this.safeNumber (filter, 'minQty'), + 'max': this.safeNumber (filter, 'maxQty'), }; } if ('MIN_NOTIONAL' in filtersByType) { const filter = this.safeValue (filtersByType, 'MIN_NOTIONAL', {}); - entry['limits']['cost']['min'] = this.safeFloat (filter, 'minNotional'); + entry['limits']['cost']['min'] = this.safeNumber (filter, 'minNotional'); } result.push (entry); } return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchAccounts (params = {}) { const response = await this.privateGetAccount (params); // @@ -404,8 +385,8 @@ module.exports = class currencycom extends Exchange { const response = await this.privateGetAccount (params); return { 'info': response, - 'maker': this.safeFloat (response, 'makerCommission'), - 'taker': this.safeFloat (response, 'takerCommission'), + 'maker': this.safeNumber (response, 'makerCommission'), + 'taker': this.safeNumber (response, 'takerCommission'), }; } @@ -439,11 +420,11 @@ module.exports = class currencycom extends Exchange { const currencyId = this.safeString (balance, 'asset'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -542,8 +523,8 @@ module.exports = class currencycom extends Exchange { const timestamp = this.safeInteger (ticker, 'closeTime'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPrice'); - const open = this.safeFloat (ticker, 'openPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); let average = undefined; if ((open !== undefined) && (last !== undefined)) { average = this.sum (open, last) / 2; @@ -552,22 +533,22 @@ module.exports = class currencycom extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat (ticker, 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat (ticker, 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), - 'vwap': this.safeFloat (ticker, 'weightedAvgPrice'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber (ticker, 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber (ticker, 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), + 'vwap': this.safeNumber (ticker, 'weightedAvgPrice'), 'open': open, 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'prevClosePrice'), // previous day close - 'change': this.safeFloat (ticker, 'priceChange'), - 'percentage': this.safeFloat (ticker, 'priceChangePercent'), + 'previousClose': this.safeNumber (ticker, 'prevClosePrice'), // previous day close + 'change': this.safeNumber (ticker, 'priceChange'), + 'percentage': this.safeNumber (ticker, 'priceChangePercent'), 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume'), 'info': ticker, }; } @@ -602,14 +583,6 @@ module.exports = class currencycom extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker24hr (params); @@ -642,11 +615,11 @@ module.exports = class currencycom extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -712,8 +685,11 @@ module.exports = class currencycom extends Exchange { // } // const timestamp = this.safeInteger2 (trade, 'T', 'time'); - const price = this.safeFloat2 (trade, 'p', 'price'); - const amount = this.safeFloat2 (trade, 'q', 'qty'); + const priceString = this.safeString2 (trade, 'p', 'price'); + const amountString = this.safeString2 (trade, 'q', 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString2 (trade, 'a', 'id'); let side = undefined; const orderId = this.safeString (trade, 'orderId'); @@ -729,7 +705,7 @@ module.exports = class currencycom extends Exchange { let fee = undefined; if ('commission' in trade) { fee = { - 'cost': this.safeFloat (trade, 'commission'), + 'cost': this.safeNumber (trade, 'commission'), 'currency': this.safeCurrencyCode (this.safeString (trade, 'commissionAsset')), }; } @@ -751,7 +727,7 @@ module.exports = class currencycom extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': price * amount, + 'cost': cost, 'fee': fee, }; } @@ -827,66 +803,21 @@ module.exports = class currencycom extends Exchange { } else if ('transactTime' in order) { timestamp = this.safeInteger (order, 'transactTime'); } - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'origQty'); - const filled = this.safeFloat (order, 'executedQty'); - let remaining = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - if (this.options['parseOrderToPrecision']) { - remaining = parseFloat (this.amountToPrecision (symbol, remaining)); - } - remaining = Math.max (remaining, 0.0); - } - if (price !== undefined) { - if (cost === undefined) { - cost = price * filled; - } - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'origQty'); + const filled = this.safeNumber (order, 'executedQty'); + const remaining = undefined; + const cost = this.safeNumber (order, 'cummulativeQuoteQty'); const id = this.safeString (order, 'orderId'); const type = this.safeStringLower (order, 'type'); - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const side = this.safeStringLower (order, 'side'); - let fee = undefined; let trades = undefined; const fills = this.safeValue (order, 'fills'); if (fills !== undefined) { trades = this.parseTrades (fills, market); - const numTrades = trades.length; - if (numTrades > 0) { - cost = trades[0]['cost']; - fee = { - 'cost': trades[0]['fee']['cost'], - 'currency': trades[0]['fee']['currency'], - }; - for (let i = 1; i < trades.length; i++) { - cost = this.sum (cost, trades[i]['cost']); - fee['cost'] = this.sum (fee['cost'], trades[i]['fee']['cost']); - } - } - } - let average = undefined; - if (cost !== undefined) { - if (filled) { - average = cost / filled; - } - if (this.options['parseOrderToPrecision']) { - cost = parseFloat (this.costToPrecision (symbol, cost)); - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'timestamp': timestamp, @@ -900,13 +831,13 @@ module.exports = class currencycom extends Exchange { 'stopPrice': undefined, 'amount': amount, 'cost': cost, - 'average': average, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/delta.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/delta.js index 9b3c559bf..028cdf3ac 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/delta.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/delta.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, BadRequest, BadSymbol, InvalidOrder, AuthenticationError, ArgumentsRequired, OrderNotFound, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -258,14 +259,14 @@ module.exports = class delta extends Exchange { 'name': this.safeString (currency, 'name'), 'info': currency, // the original payload 'active': active, - 'fee': this.safeFloat (currency, 'base_withdrawal_fee'), + 'fee': this.safeNumber (currency, 'base_withdrawal_fee'), 'precision': 1 / Math.pow (10, precision), 'limits': { 'amount': { 'min': undefined, 'max': undefined }, 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal_amount'), + 'min': this.safeNumber (currency, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -399,26 +400,26 @@ module.exports = class delta extends Exchange { } const precision = { 'amount': 1.0, // number of contracts - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; const limits = { 'amount': { 'min': 1.0, - 'max': this.safeFloat (market, 'position_size_limit'), + 'max': this.safeNumber (market, 'position_size_limit'), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_size'), + 'min': this.safeNumber (market, 'min_size'), 'max': undefined, }, }; const state = this.safeString (market, 'state'); const active = (state === 'live'); - const maker = this.safeFloat (market, 'maker_commission_rate'); - const taker = this.safeFloat (market, 'taker_commission_rate'); + const maker = this.safeNumber (market, 'maker_commission_rate'); + const taker = this.safeNumber (market, 'taker_commission_rate'); result.push ({ 'id': id, 'numericId': numericId, @@ -466,8 +467,8 @@ module.exports = class delta extends Exchange { const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.001); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'close'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; let percentage = undefined; @@ -478,15 +479,15 @@ module.exports = class delta extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'turnover'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'turnover'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -656,12 +657,11 @@ module.exports = class delta extends Exchange { const orderId = this.safeString (trade, 'order_id'); let timestamp = this.parse8601 (this.safeString (trade, 'created_at')); timestamp = this.safeIntegerProduct (trade, 'timestamp', 0.001, timestamp); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const product = this.safeValue (trade, 'product', {}); const marketId = this.safeString (product, 'symbol'); const symbol = this.safeSymbol (marketId, market); @@ -680,7 +680,7 @@ module.exports = class delta extends Exchange { if (type !== undefined) { type = type.replace ('_order', ''); } - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { const settlingAsset = this.safeValue (product, 'settling_asset', {}); @@ -747,11 +747,11 @@ module.exports = class delta extends Exchange { // return [ this.safeTimestamp (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -821,11 +821,11 @@ module.exports = class delta extends Exchange { const currency = this.safeValue (currenciesByNumericId, currencyId); const code = (currency === undefined) ? currencyId : currency['code']; const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchPosition (symbol, params = undefined) { @@ -849,7 +849,7 @@ module.exports = class delta extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetPositionsMargined (params); // @@ -930,20 +930,12 @@ module.exports = class delta extends Exchange { const side = this.safeString (order, 'side'); let type = this.safeString (order, 'order_type'); type = type.replace ('_order', ''); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'size'); - const remaining = this.safeFloat (order, 'unfilled_size'); - let filled = undefined; - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let cost = undefined; - const average = this.safeFloat (order, 'average_fill_price'); - if ((average !== undefined) && filled) { - cost = average * filled; - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'size'); + const remaining = this.safeNumber (order, 'unfilled_size'); + const average = this.safeNumber (order, 'average_fill_price'); let fee = undefined; - const feeCost = this.safeFloat (order, 'paid_commission'); + const feeCost = this.safeNumber (order, 'paid_commission'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -956,7 +948,7 @@ module.exports = class delta extends Exchange { 'currency': feeCurrencyCode, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -968,14 +960,14 @@ module.exports = class delta extends Exchange { 'side': side, 'price': price, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1374,9 +1366,9 @@ module.exports = class delta extends Exchange { const currenciesByNumericId = this.safeValue (this.options, 'currenciesByNumericId'); currency = this.safeValue (currenciesByNumericId, currencyId, currency); const code = (currency === undefined) ? undefined : currency['code']; - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'created_at')); - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const before = Math.max (0, after - amount); const status = 'ok'; return { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/deribit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/deribit.js index f277c3975..1a7c91bec 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/deribit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/deribit.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); const { AuthenticationError, ExchangeError, ArgumentsRequired, PermissionDenied, InvalidOrder, OrderNotFound, DDoSProtection, NotSupported, ExchangeNotAvailable, InsufficientFunds, BadRequest, InvalidAddress, OnMaintenance } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -435,8 +436,8 @@ module.exports = class deribit extends Exchange { const future = (type === 'future'); const option = (type === 'option'); const active = this.safeValue (market, 'is_active'); - const minTradeAmount = this.safeFloat (market, 'min_trade_amount'); - const tickSize = this.safeFloat (market, 'tick_size'); + const minTradeAmount = this.safeNumber (market, 'min_trade_amount'); + const tickSize = this.safeNumber (market, 'tick_size'); const precision = { 'amount': minTradeAmount, 'price': tickSize, @@ -448,8 +449,8 @@ module.exports = class deribit extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_commission'), - 'maker': this.safeFloat (market, 'maker_commission'), + 'taker': this.safeNumber (market, 'taker_commission'), + 'maker': this.safeNumber (market, 'maker_commission'), 'limits': { 'amount': { 'min': minTradeAmount, @@ -532,11 +533,11 @@ module.exports = class deribit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const currencyCode = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableFunds'); - account['used'] = this.safeFloat (balance, 'maintenanceMargin'); - account['total'] = this.safeFloat (balance, 'equity'); + account['free'] = this.safeString (balance, 'availableFunds'); + account['used'] = this.safeString (balance, 'maintenanceMargin'); + account['total'] = this.safeString (balance, 'equity'); result[currencyCode] = account; - return this.parseBalance (result); + return this.parseBalance (result, false); } async createDepositAddress (code, params = {}) { @@ -654,18 +655,18 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger2 (ticker, 'timestamp', 'creation_timestamp'); const marketId = this.safeString (ticker, 'instrument_name'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat2 (ticker, 'last_price', 'last'); + const last = this.safeNumber2 (ticker, 'last_price', 'last'); const stats = this.safeValue (ticker, 'stats', ticker); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (stats, 'high', 'max_price'), - 'low': this.safeFloat2 (stats, 'low', 'min_price'), - 'bid': this.safeFloat2 (ticker, 'best_bid_price', 'bid_price'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_amount'), - 'ask': this.safeFloat2 (ticker, 'best_ask_price', 'ask_price'), - 'askVolume': this.safeFloat (ticker, 'best_ask_amount'), + 'high': this.safeNumber2 (stats, 'high', 'max_price'), + 'low': this.safeNumber2 (stats, 'low', 'min_price'), + 'bid': this.safeNumber2 (ticker, 'best_bid_price', 'bid_price'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_amount'), + 'ask': this.safeNumber2 (ticker, 'best_ask_price', 'ask_price'), + 'askVolume': this.safeNumber (ticker, 'best_ask_amount'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -675,7 +676,7 @@ module.exports = class deribit extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (stats, 'volume'), + 'quoteVolume': this.safeNumber (stats, 'volume'), 'info': ticker, }; } @@ -862,21 +863,18 @@ module.exports = class deribit extends Exchange { const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeString (trade, 'direction'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const liquidity = this.safeString (trade, 'liquidity'); let takerOrMaker = undefined; if (liquidity !== undefined) { // M = maker, T = taker, MT = both takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker'; } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -1056,31 +1054,21 @@ module.exports = class deribit extends Exchange { const timestamp = this.safeInteger (order, 'creation_timestamp'); const lastUpdate = this.safeInteger (order, 'last_update_timestamp'); const id = this.safeString (order, 'order_id'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'average_price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'average_price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); let lastTradeTimestamp = undefined; if (filled !== undefined) { if (filled > 0) { lastTradeTimestamp = lastUpdate; } } - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = price * filled; - } - } const status = this.parseOrderStatus (this.safeString (order, 'order_state')); const marketId = this.safeString (order, 'instrument_name'); market = this.safeMarket (marketId, market); const side = this.safeStringLower (order, 'direction'); - let feeCost = this.safeFloat (order, 'commission'); + let feeCost = this.safeNumber (order, 'commission'); let fee = undefined; if (feeCost !== undefined) { feeCost = Math.abs (feeCost); @@ -1098,7 +1086,7 @@ module.exports = class deribit extends Exchange { const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force')); const stopPrice = this.safeValue (order, 'stop_price'); const postOnly = this.safeValue (order, 'post_only'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1113,14 +1101,14 @@ module.exports = class deribit extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1197,7 +1185,7 @@ module.exports = class deribit extends Exchange { } } if (stopPriceIsRequired) { - const stopPrice = this.safeFloat2 (params, 'stop_price', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice'); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price or stopPrice param for a ' + type + ' order'); } else { @@ -1596,7 +1584,7 @@ module.exports = class deribit extends Exchange { const updated = this.safeInteger (transaction, 'updated_timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const address = this.safeString (transaction, 'address'); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let type = 'deposit'; let fee = undefined; if (feeCost !== undefined) { @@ -1619,7 +1607,7 @@ module.exports = class deribit extends Exchange { 'tagTo': undefined, 'tagFrom': undefined, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, @@ -1665,7 +1653,7 @@ module.exports = class deribit extends Exchange { return result; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.codeFromOptions ('fetchPositions'); const currency = this.currency (code); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/digifinex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/digifinex.js index 6584b919c..528126688 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/digifinex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/digifinex.js @@ -3,7 +3,8 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); -const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ArgumentsRequired, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const { AccountSuspended, BadRequest, BadResponse, NetworkError, DDoSProtection, AuthenticationError, PermissionDenied, ExchangeError, InsufficientFunds, InvalidOrder, InvalidNonce, OrderNotFound, InvalidAddress, RateLimitExceeded, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -61,11 +62,6 @@ module.exports = class digifinex extends Exchange { 'referral': 'https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp', }, 'api': { - 'v2': { - 'get': [ - 'ticker', - ], - }, 'public': { 'get': [ '{market}/symbols', @@ -191,6 +187,7 @@ module.exports = class digifinex extends Exchange { }, 'commonCurrencies': { 'BHT': 'Black House Test', + 'EPS': 'Epanus', 'MBN': 'Mobilian Coin', 'TEL': 'TEL666', }, @@ -245,7 +242,7 @@ module.exports = class digifinex extends Exchange { const depositStatus = this.safeValue (currency, 'deposit_status', 1); const withdrawStatus = this.safeValue (currency, 'withdraw_status', 1); const active = depositStatus && withdrawStatus; - const fee = this.safeFloat (currency, 'withdraw_fee_rate'); + const fee = this.safeNumber (currency, 'withdraw_fee_rate'); if (code in result) { if (Array.isArray (result[code]['info'])) { result[code]['info'].push (currency); @@ -276,7 +273,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw_amount'), + 'min': this.safeNumber (currency, 'min_withdraw_amount'), 'max': undefined, }, }, @@ -330,7 +327,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minimum_amount'), + 'min': this.safeNumber (market, 'minimum_amount'), 'max': undefined, }, 'price': { @@ -338,7 +335,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minimum_value'), + 'min': this.safeNumber (market, 'minimum_value'), 'max': undefined, }, }; @@ -352,7 +349,7 @@ module.exports = class digifinex extends Exchange { // const status = this.safeString (market, 'status'); // const active = (status === 'TRADING'); // - const isAllowed = this.safeValue (market, 'is_allow', 1); + const isAllowed = this.safeInteger (market, 'is_allow', 1); const active = isAllowed ? true : false; const type = 'spot'; const spot = (type === 'spot'); @@ -408,7 +405,7 @@ module.exports = class digifinex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), + 'min': this.safeNumber (market, 'min_volume'), 'max': undefined, }, 'price': { @@ -416,7 +413,7 @@ module.exports = class digifinex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, }; @@ -461,12 +458,12 @@ module.exports = class digifinex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['used'] = this.safeFloat (balance, 'frozen'); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['used'] = this.safeString (balance, 'frozen'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -500,87 +497,67 @@ module.exports = class digifinex extends Exchange { } async fetchTickers (symbols = undefined, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTickers() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); - const request = { - 'apiKey': apiKey, - }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (params); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const result = {}; - const tickers = this.safeValue (response, 'ticker', {}); + const tickers = this.safeValue (response, 'ticker', []); const date = this.safeInteger (response, 'date'); - const reversedMarketIds = Object.keys (tickers); - for (let i = 0; i < reversedMarketIds.length; i++) { - const reversedMarketId = reversedMarketIds[i]; - const ticker = this.extend ({ + for (let i = 0; i < tickers.length; i++) { + const rawTicker = this.extend ({ 'date': date, - }, tickers[reversedMarketId]); - const [ quoteId, baseId ] = reversedMarketId.split ('_'); - const marketId = baseId.toUpperCase () + '_' + quoteId.toUpperCase (); - const market = this.safeMarket (marketId, undefined, '_'); - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); + }, tickers[i]); + const ticker = this.parseTicker (rawTicker); + const symbol = ticker['symbol']; + result[symbol] = ticker; } return this.filterByArray (result, 'symbol', symbols); } async fetchTicker (symbol, params = {}) { - const apiKey = this.safeValue (params, 'apiKey', this.apiKey); - if (!apiKey) { - throw new ArgumentsRequired (this.id + ' fetchTicker() is a private v2 endpoint that requires an `exchange.apiKey` credential or an `apiKey` extra parameter'); - } await this.loadMarkets (); const market = this.market (symbol); - // reversed base/quote in v2 - const marketId = market['quoteId'].toLowerCase () + '_' + market['baseId'].toLowerCase (); const request = { - 'symbol': marketId, - 'apiKey': apiKey, + 'symbol': market['id'], }; - const response = await this.v2GetTicker (this.extend (request, params)); + const response = await this.publicGetTicker (this.extend (request, params)); // - // { - // "ticker":{ - // "btc_eth":{ - // "last":0.021957, - // "base_vol":2249.3521732227, - // "change":-0.6, - // "vol":102443.5111, - // "sell":0.021978, - // "low":0.021791, - // "buy":0.021946, - // "high":0.022266 - // } - // }, - // "date":1564518452, - // "code":0 - // } + // { + // "ticker": [{ + // "vol": 40717.4461, + // "change": -1.91, + // "base_vol": 392447999.65374, + // "sell": 9592.23, + // "last": 9592.22, + // "symbol": "btc_usdt", + // "low": 9476.24, + // "buy": 9592.03, + // "high": 9793.87 + // }], + // "date": 1589874294, + // "code": 0 + // } // const date = this.safeInteger (response, 'date'); - const ticker = this.safeValue (response, 'ticker', {}); - let result = this.safeValue (ticker, marketId, {}); - result = this.extend ({ 'date': date }, result); + const tickers = this.safeValue (response, 'ticker', []); + const firstTicker = this.safeValue (tickers, 0, {}); + const result = this.extend ({ 'date': date }, firstTicker); return this.parseTicker (result, market); } @@ -590,6 +567,7 @@ module.exports = class digifinex extends Exchange { // // { // "last":0.021957, + // "symbol": "btc_usdt", // "base_vol":2249.3521732227, // "change":-0.6, // "vol":102443.5111, @@ -600,22 +578,20 @@ module.exports = class digifinex extends Exchange { // "date"1564518452, // injected from fetchTicker/fetchTickers // } // - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeStringUpper (ticker, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -625,8 +601,8 @@ module.exports = class digifinex extends Exchange { 'change': undefined, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'base_vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'base_vol'), 'info': ticker, }; } @@ -662,18 +638,15 @@ module.exports = class digifinex extends Exchange { const orderId = this.safeString (trade, 'order_id'); const timestamp = this.safeTimestamp2 (trade, 'date', 'timestamp'); const side = this.safeString2 (trade, 'type', 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); const takerOrMaker = this.safeValue (trade, 'is_maker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency'); @@ -775,11 +748,11 @@ module.exports = class digifinex extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 5), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 1), // volume + this.safeNumber (ohlcv, 5), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 1), // volume ]; } @@ -970,21 +943,11 @@ module.exports = class digifinex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executed_amount'); - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_price'); - let remaining = undefined; - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - return { + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executed_amount'); + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1000,13 +963,13 @@ module.exports = class digifinex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'average': average, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1200,7 +1163,7 @@ module.exports = class digifinex extends Exchange { const code = this.safeCurrencyCode (this.safeString (item, 'currency_mark'), currency); const timestamp = this.safeTimestamp (item, 'time'); const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -1263,16 +1226,6 @@ module.exports = class digifinex extends Exchange { return this.parseLedger (items, currency, since, limit); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -1425,8 +1378,8 @@ module.exports = class digifinex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_date')); const updated = this.parse8601 (this.safeString (transaction, 'finished_date')); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'amount'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; @@ -1476,7 +1429,7 @@ module.exports = class digifinex extends Exchange { } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const version = (api === 'v2') ? api : this.version; + const version = this.version; let url = this.urls['api'] + '/' + version + '/' + this.implodeParams (path, params); const query = this.omit (params, this.extractParams (path)); const urlencoded = this.urlencode (this.keysort (query)); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/dsx.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/dsx.js deleted file mode 100644 index 349fc2489..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/dsx.js +++ /dev/null @@ -1,1274 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, BadRequest, InsufficientFunds, PermissionDenied, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class dsx extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'dsx', - 'name': 'DSX', - 'countries': [ 'UK' ], - 'rateLimit': 1500, - 'version': 'v3', - 'has': { - 'cancelOrder': true, - 'CORS': false, - 'createDepositAddress': true, - 'createMarketOrder': false, - 'createOrder': true, - 'fetchBalance': true, - 'fetchClosedOrders': false, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOHLCV': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchOrderBooks': true, - 'fetchOrders': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTransactions': true, - 'fetchTrades': true, - 'withdraw': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/76909626-cb2bb100-68bc-11ea-99e0-28ba54f04792.jpg', - 'api': { - 'public': 'https://dsxglobal.com/mapi', // market data - 'private': 'https://dsxglobal.com/tapi', // trading - 'dwapi': 'https://dsxglobal.com/dwapi', // deposit/withdraw - }, - 'www': 'https://dsxglobal.com', - 'doc': [ - 'https://dsxglobal.com/developers/publicApi', - ], - }, - 'fees': { - 'trading': { - 'tierBased': true, - 'percentage': true, - 'maker': 0.15 / 100, - 'taker': 0.25 / 100, - }, - }, - 'timeframes': { - '1m': 'm', - '1h': 'h', - '1d': 'd', - }, - 'api': { - // market data (public) - 'public': { - 'get': [ - 'barsFromMoment/{pair}/{period}/{start}', - 'depth/{pair}', - 'info', - 'lastBars/{pair}/{period}/{amount}', // period is 'm', 'h' or 'd' - 'periodBars/{pair}/{period}/{start}/{end}', - 'ticker/{pair}', - 'trades/{pair}', - ], - }, - // trading (private) - 'private': { - 'post': [ - 'info/account', - 'history/transactions', - 'history/trades', - 'history/orders', - 'orders', - 'order/cancel', - // 'order/cancel/all', - 'order/status', - 'order/new', - 'volume', - 'fees', // trading fee schedule - ], - }, - // deposit / withdraw (private) - 'dwapi': { - 'post': [ - 'deposit/cryptoaddress', - 'withdraw/crypto', - 'withdraw/fiat', - 'withdraw/submit', - // 'withdraw/cancel', - 'transaction/status', // see 'history/transactions' in private tapi above - ], - }, - }, - 'exceptions': { - 'exact': { - 'Sign is invalid': AuthenticationError, // {"success":0,"error":"Sign is invalid"} - 'Order was rejected. Incorrect price.': InvalidOrder, // {"success":0,"error":"Order was rejected. Incorrect price."} - "Order was rejected. You don't have enough money.": InsufficientFunds, // {"success":0,"error":"Order was rejected. You don't have enough money."} - 'This method is blocked for your pair of keys': PermissionDenied, // {"success":0,"error":"This method is blocked for your pair of keys"} - }, - 'broad': { - 'INVALID_PARAMETER': BadRequest, - 'Invalid pair name': ExchangeError, // {"success":0,"error":"Invalid pair name: btc_eth"} - 'invalid api key': AuthenticationError, - 'invalid sign': AuthenticationError, - 'api key dont have trade permission': AuthenticationError, - 'invalid parameter': InvalidOrder, - 'invalid order': InvalidOrder, - 'Requests too often': DDoSProtection, - 'not available': ExchangeNotAvailable, - 'data unavailable': ExchangeNotAvailable, - 'external service unavailable': ExchangeNotAvailable, - 'nonce is invalid': InvalidNonce, // {"success":0,"error":"Parameter: nonce is invalid"} - 'Incorrect volume': InvalidOrder, // {"success": 0,"error":"Order was rejected. Incorrect volume."} - }, - }, - 'options': { - 'fetchTickersMaxLength': 250, - }, - 'commonCurrencies': { - 'DSH': 'DASH', - }, - }); - } - - async fetchMarkets (params = {}) { - const response = await this.publicGetInfo (params); - // - // { - // "server_time": 1522057909, - // "pairs": { - // "ethusd": { - // "decimal_places": 5, - // "min_price": 100, - // "max_price": 1500, - // "min_amount": 0.01, - // "hidden": 0, - // "fee": 0, - // "amount_decimal_places": 4, - // "quoted_currency": "USD", - // "base_currency": "ETH" - // } - // } - // } - // - const markets = this.safeValue (response, 'pairs'); - const keys = Object.keys (markets); - const result = []; - for (let i = 0; i < keys.length; i++) { - const id = keys[i]; - const market = markets[id]; - const baseId = this.safeString (market, 'base_currency'); - const quoteId = this.safeString (market, 'quoted_currency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const precision = { - 'amount': this.safeInteger (market, 'decimal_places'), - 'price': this.safeInteger (market, 'decimal_places'), - }; - const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), - }; - const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), - }; - const costLimits = { - 'min': this.safeFloat (market, 'min_total'), - }; - const limits = { - 'amount': amountLimits, - 'price': priceLimits, - 'cost': costLimits, - }; - const hidden = this.safeInteger (market, 'hidden'); - const active = (hidden === 0); - // see parseMarket below - // https://github.com/ccxt/ccxt/pull/5786 - const otherId = base.toLowerCase () + quote.toLowerCase (); - result.push ({ - 'id': id, - 'otherId': otherId, // https://github.com/ccxt/ccxt/pull/5786 - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': active, - 'precision': precision, - 'limits': limits, - 'info': market, - }); - } - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostInfoAccount (); - // - // { - // "success" : 1, - // "return" : { - // "funds" : { - // "BTC" : { - // "total" : 0, - // "available" : 0 - // }, - // "USD" : { - // "total" : 0, - // "available" : 0 - // }, - // "USDT" : { - // "total" : 0, - // "available" : 0 - // } - // }, - // "rights" : { - // "info" : 1, - // "trade" : 1 - // }, - // "transactionCount" : 0, - // "openOrders" : 0, - // "serverTime" : 1537451465 - // } - // } - // - const balances = this.safeValue (response, 'return'); - const result = { 'info': response }; - const funds = this.safeValue (balances, 'funds'); - const currencyIds = Object.keys (funds); - for (let i = 0; i < currencyIds.length; i++) { - const currencyId = currencyIds[i]; - const code = this.safeCurrencyCode (currencyId); - const balance = this.safeValue (funds, currencyId, {}); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseTicker (ticker, market = undefined) { - // - // { high: 0.03492, - // low: 0.03245, - // avg: 29.46133, - // vol: 500.8661, - // vol_cur: 17.000797104, - // last: 0.03364, - // buy: 0.03362, - // sell: 0.03381, - // updated: 1537521993, - // pair: "ethbtc" } - // - const timestamp = this.safeTimestamp (ticker, 'updated'); - let symbol = undefined; - const marketId = this.safeString (ticker, 'pair'); - market = this.parseMarket (marketId); - if (market !== undefined) { - symbol = market['symbol']; - } - // dsx average is inverted, liqui average is not - let average = this.safeFloat (ticker, 'avg'); - if (average !== undefined) { - if (average > 0) { - average = 1 / average; - } - } - const last = this.safeFloat (ticker, 'last'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_cur'), - 'info': ticker, - }; - } - - parseTrade (trade, market = undefined) { - // - // fetchTrades (public) - // - // { - // "amount" : 0.0128, - // "price" : 6483.99000, - // "timestamp" : 1540334614, - // "tid" : 35684364, - // "type" : "ask" - // } - // - // fetchMyTrades (private) - // - // { - // "number": "36635882", // <-- this is present if the trade has come from the '/order/status' call - // "id": "36635882", // <-- this may have been artifically added by the parseTrades method - // "pair": "btcusd", - // "type": "buy", - // "volume": 0.0595, - // "rate": 9750, - // "orderId": 77149299, - // "timestamp": 1519612317, - // "commission": 0.00020825, - // "commissionCurrency": "btc" - // } - // - const timestamp = this.safeTimestamp (trade, 'timestamp'); - let side = this.safeString (trade, 'type'); - if (side === 'ask') { - side = 'sell'; - } else if (side === 'bid') { - side = 'buy'; - } - const price = this.safeFloat2 (trade, 'rate', 'price'); - const id = this.safeString2 (trade, 'number', 'id'); - const orderId = this.safeString (trade, 'orderId'); - const marketId = this.safeString (trade, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const amount = this.safeFloat2 (trade, 'amount', 'volume'); - const type = 'limit'; // all trades are still limit trades - let takerOrMaker = undefined; - let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); - if (feeCost !== undefined) { - const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); - const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - fee = { - 'cost': feeCost, - 'currency': feeCurrencyCode, - }; - } - const isYourOrder = this.safeValue (trade, 'is_your_order'); - if (isYourOrder !== undefined) { - takerOrMaker = 'taker'; - if (isYourOrder) { - takerOrMaker = 'maker'; - } - if (fee === undefined) { - fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); - } - } - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - return { - 'id': id, - 'order': orderId, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'type': type, - 'side': side, - 'takerOrMaker': takerOrMaker, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - 'info': trade, - }; - } - - parseTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) { - let result = []; - if (Array.isArray (trades)) { - for (let i = 0; i < trades.length; i++) { - result.push (this.parseTrade (trades[i], market)); - } - } else { - const ids = Object.keys (trades); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const trade = this.parseTrade (trades[id], market); - result.push (this.extend (trade, { 'id': id }, params)); - } - } - result = this.sortBy (result, 'timestamp'); - const symbol = (market !== undefined) ? market['symbol'] : undefined; - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const market_id_in_reponse = (market['id'] in response); - if (!market_id_in_reponse) { - throw new ExchangeError (this.id + ' ' + market['symbol'] + ' order book is empty or not available'); - } - const orderbook = response[market['id']]; - return this.parseOrderBook (orderbook); - } - - async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let ids = undefined; - if (symbols === undefined) { - ids = this.ids.join ('-'); - // max URL length is 2083 symbols, including http schema, hostname, tld, etc... - if (ids.length > 2048) { - const numIds = this.ids.length; - throw new ExchangeError (this.id + ' has ' + numIds.toString () + ' symbols exceeding max URL length, you are required to specify a list of symbols in the first argument to fetchOrderBooks'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - if (limit !== undefined) { - request['limit'] = limit; // default = 150, max = 2000 - } - const response = await this.publicGetDepthPair (this.extend (request, params)); - const result = {}; - ids = Object.keys (response); - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - let symbol = id; - if (id in this.markets_by_id) { - const market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseOrderBook (response[id]); - } - return result; - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - let ids = this.ids; - if (symbols === undefined) { - const numIds = ids.length; - ids = ids.join ('-'); - const maxLength = this.safeInteger (this.options, 'fetchTickersMaxLength', 2048); - // max URL length is 2048 symbols, including http schema, hostname, tld, etc... - if (ids.length > this.options['fetchTickersMaxLength']) { - throw new ArgumentsRequired (this.id + ' has ' + numIds.toString () + ' markets exceeding max URL length for this endpoint (' + maxLength.toString () + ' characters), please, specify a list of symbols of interest in the first argument to fetchTickers'); - } - } else { - ids = this.marketIds (symbols); - ids = ids.join ('-'); - } - const request = { - 'pair': ids, - }; - const tickers = await this.publicGetTickerPair (this.extend (request, params)); - // - // { - // "bchbtc" : { - // "high" : 0.02989, - // "low" : 0.02736, - // "avg" : 33.90585, - // "vol" : 0.65982205, - // "vol_cur" : 0.0194604180960, - // "last" : 0.03000, - // "buy" : 0.02980, - // "sell" : 0.03001, - // "updated" : 1568104614, - // "pair" : "bchbtc" - // }, - // "ethbtc" : { - // "high" : 0.01772, - // "low" : 0.01742, - // "avg" : 56.89082, - // "vol" : 229.247115044, - // "vol_cur" : 4.02959737298943, - // "last" : 0.01769, - // "buy" : 0.01768, - // "sell" : 0.01776, - // "updated" : 1568104614, - // "pair" : "ethbtc" - // } - // } - // - const result = {}; - const keys = Object.keys (tickers); - for (let k = 0; k < keys.length; k++) { - const id = keys[k]; - const ticker = tickers[id]; - let symbol = id; - let market = undefined; - if (id in this.markets_by_id) { - market = this.markets_by_id[id]; - symbol = market['symbol']; - } - result[symbol] = this.parseTicker (ticker, market); - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchTicker (symbol, params = {}) { - const tickers = await this.fetchTickers ([ symbol ], params); - return tickers[symbol]; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - }; - if (limit !== undefined) { - request['limit'] = limit; - } - const response = await this.publicGetTradesPair (this.extend (request, params)); - if (Array.isArray (response)) { - const numElements = response.length; - if (numElements === 0) { - return []; - } - } - return this.parseTrades (response[market['id']], market, since, limit); - } - - parseOHLCV (ohlcv, market = undefined) { - // - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // } - // - return [ - this.safeInteger (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), - ]; - } - - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair': market['id'], - 'period': this.timeframes[timeframe], - }; - let method = 'publicGetLastBarsPairPeriodAmount'; - if (since === undefined) { - if (limit === undefined) { - limit = 100; // required, max 2000 - } - request['amount'] = limit; - } else { - method = 'publicGetPeriodBarsPairPeriodStartEnd'; - // in their docs they expect milliseconds - // but it returns empty arrays with milliseconds - // however, it does work properly with seconds - request['start'] = parseInt (since / 1000); - if (limit === undefined) { - request['end'] = this.seconds (); - } else { - const duration = this.parseTimeframe (timeframe) * 1000; - const end = this.sum (since, duration * limit); - request['end'] = parseInt (end / 1000); - } - } - const response = await this[method] (this.extend (request, params)); - // - // { - // "ethbtc": [ - // { - // "high" : 0.01955, - // "open" : 0.01955, - // "low" : 0.01955, - // "close" : 0.01955, - // "amount" : 2.5, - // "timestamp" : 1565155740000 - // }, - // { - // "high" : 0.01967, - // "open" : 0.01967, - // "low" : 0.01967, - // "close" : 0.01967, - // "amount" : 0, - // "timestamp" : 1565155680000 - // } - // ] - // } - // - const candles = this.safeValue (response, market['id'], []); - return this.parseOHLCVs (candles, market, timeframe, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - if (type === 'market' && price === undefined) { - throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument even for market orders, that is the worst price that you agree to fill your order for'); - } - const request = { - 'pair': market['id'], - 'type': side, - 'volume': this.amountToPrecision (symbol, amount), - 'rate': this.priceToPrecision (symbol, price), - 'orderType': type, - }; - price = parseFloat (price); - amount = parseFloat (amount); - const response = await this.privatePostOrderNew (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "received": 0, - // "remains": 10, - // "funds": { - // "BTC": { - // "total": 100, - // "available": 95 - // }, - // "USD": { - // "total": 10000, - // "available": 9995 - // }, - // "EUR": { - // "total": 1000, - // "available": 995 - // }, - // "LTC": { - // "total": 1000, - // "available": 995 - // } - // }, - // "orderId": 0, // https://github.com/ccxt/ccxt/issues/3677 - // } - // } - // - let status = 'open'; - let filled = 0.0; - let remaining = amount; - const responseReturn = this.safeValue (response, 'return'); - let id = this.safeString2 (responseReturn, 'orderId', 'order_id'); - if (id === '0') { - id = this.safeString (responseReturn, 'initOrderId', 'init_order_id'); - status = 'closed'; - } - filled = this.safeFloat (responseReturn, 'received', 0.0); - remaining = this.safeFloat (responseReturn, 'remains', amount); - const timestamp = this.milliseconds (); - return { - 'info': response, - 'id': id, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': type, - 'side': side, - 'price': price, - 'cost': price * filled, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'fee': undefined, - // 'trades': this.parseTrades (order['trades'], market), - }; - } - - parseOrderStatus (status) { - const statuses = { - '0': 'open', // Active - '1': 'closed', // Filled - '2': 'canceled', // Killed - '3': 'canceling', // Killing - '7': 'canceled', // Rejected - }; - return this.safeString (statuses, status, status); - } - - parseMarket (id) { - if (id in this.markets_by_id) { - return this.markets_by_id[id]; - } else { - // the following is a fix for - // https://github.com/ccxt/ccxt/pull/5786 - // https://github.com/ccxt/ccxt/issues/5770 - let markets_by_other_id = this.safeValue (this.options, 'markets_by_other_id'); - if (markets_by_other_id === undefined) { - this.options['markets_by_other_id'] = this.indexBy (this.markets, 'otherId'); - markets_by_other_id = this.options['markets_by_other_id']; - } - if (id in markets_by_other_id) { - return markets_by_other_id[id]; - } - } - return undefined; - } - - parseOrder (order, market = undefined) { - // - // fetchOrder - // - // { - // "number": 36635882, - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // - const id = this.safeString (order, 'id'); - const status = this.parseOrderStatus (this.safeString (order, 'status')); - const timestamp = this.safeTimestamp (order, 'timestampCreated'); - const marketId = this.safeString (order, 'pair'); - market = this.parseMarket (marketId); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const remaining = this.safeFloat (order, 'remainingVolume'); - const amount = this.safeFloat (order, 'volume'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } - } - const orderType = this.safeString (order, 'orderType'); - const side = this.safeString (order, 'type'); - let fee = undefined; - const deals = this.safeValue (order, 'deals', []); - const numDeals = deals.length; - let trades = undefined; - let lastTradeTimestamp = undefined; - if (numDeals > 0) { - trades = this.parseTrades (deals); - let feeCost = undefined; - let feeCurrency = undefined; - for (let i = 0; i < trades.length; i++) { - const trade = trades[i]; - if (feeCost === undefined) { - feeCost = 0; - } - feeCost = this.sum (feeCost, trade['fee']['cost']); - feeCurrency = trade['fee']['currency']; - lastTradeTimestamp = trade['timestamp']; - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': feeCurrency, - }; - } - } - return { - 'info': order, - 'id': id, - 'clientOrderId': undefined, - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, - 'type': orderType, - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': side, - 'price': price, - 'stopPrice': undefined, - 'cost': cost, - 'amount': amount, - 'remaining': remaining, - 'filled': filled, - 'status': status, - 'fee': fee, - 'trades': trades, - }; - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': parseInt (id), - }; - const response = await this.privatePostOrderStatus (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit", - // "deals": [ - // { - // "pair": "btcusd", - // "type": "buy", - // "amount": 1, - // "rate": 1000.0, - // "orderId": 1, - // "timestamp": 1496672724, - // "commission": 0.001, - // "commissionCurrency": "btc" - // } - // ] - // } - // } - // - return this.parseOrder (this.extend ({ - 'id': id, - }, response['return'])); - } - - parseOrdersById (orders, symbol = undefined, since = undefined, limit = undefined) { - const ids = Object.keys (orders); - const result = []; - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.parseOrder (this.extend ({ - 'id': id.toString (), - }, orders[id])); - result.push (order); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - const response = await this.privatePostOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - // 'count': 10, // Decimal, The maximum number of orders to return - // 'fromId': 123, // Decimal, ID of the first order of the selection - // 'endId': 321, // Decimal, ID of the last order of the selection - // 'order': 'ASC', // String, Order in which orders shown. Possible values are "ASC" — from first to last, "DESC" — from last to first. - }; - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryOrders (this.extend (request, params)); - // - // { - // "success": 1, - // "return": { - // "0": { - // "pair": "btcusd", - // "type": "buy", - // "remainingVolume": 10, - // "volume": 10, - // "rate": 1000.0, - // "timestampCreated": 1496670, - // "status": 0, - // "orderType": "limit" - // } - // } - // } - // - return this.parseOrdersById (this.safeValue (response, 'return', {}), symbol, since, limit); - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'orderId': id, - }; - const response = await this.privatePostOrderCancel (this.extend (request, params)); - return response; - } - - parseOrders (orders, market = undefined, since = undefined, limit = undefined, params = {}) { - const result = []; - const ids = Object.keys (orders); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - for (let i = 0; i < ids.length; i++) { - const id = ids[i]; - const order = this.extend ({ 'id': id }, orders[id]); - result.push (this.extend (this.parseOrder (order, market), params)); - } - return this.filterBySymbolSinceLimit (result, symbol, since, limit); - } - - async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - const orders = await this.fetchOrders (symbol, since, limit, params); - return this.filterBy (orders, 'status', 'closed'); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let market = undefined; - // some derived classes use camelcase notation for request fields - const request = { - // 'from': 123456789, // trade ID, from which the display starts numerical 0 (test result: liqui ignores this field) - // 'count': 1000, // the number of trades for display numerical, default = 1000 - // 'from_id': trade ID, from which the display starts numerical 0 - // 'end_id': trade ID on which the display ends numerical ∞ - // 'order': 'ASC', // sorting, default = DESC (test result: liqui ignores this field, most recent trade always goes last) - // 'since': 1234567890, // UTC start time, default = 0 (test result: liqui ignores this field) - // 'end': 1234567890, // UTC end time, default = ∞ (test result: liqui ignores this field) - // 'pair': 'eth_btc', // default = all markets - }; - if (symbol !== undefined) { - market = this.market (symbol); - request['pair'] = market['id']; - } - if (limit !== undefined) { - request['count'] = parseInt (limit); - } - if (since !== undefined) { - request['since'] = parseInt (since / 1000); - } - const response = await this.privatePostHistoryTrades (this.extend (request, params)); - let trades = []; - if ('return' in response) { - trades = response['return']; - } - return this.parseTrades (trades, market, since, limit); - } - - async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - let currency = undefined; - const request = {}; - if (code !== undefined) { - currency = this.currency (code); - request['currency'] = currency['id']; - } - if (since !== undefined) { - request['since'] = since; - } - if (limit !== undefined) { - request['count'] = limit; - } - const response = await this.privatePostHistoryTransactions (this.extend (request, params)); - // - // { - // "success": 1, - // "return": [ - // { - // "id": 1, - // "timestamp": 11, - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // ] - // } - // - const transactions = this.safeValue (response, 'return', []); - return this.parseTransactions (transactions, currency, since, limit); - } - - parseTransactionStatus (status) { - const statuses = { - '1': 'failed', - '2': 'ok', - '3': 'pending', - '4': 'failed', - }; - return this.safeString (statuses, status, status); - } - - parseTransaction (transaction, currency = undefined) { - // - // { - // "id": 1, - // "timestamp": 11, // 11 in their docs ( - // "type": "Withdraw", - // "amount": 1, - // "currency": "btc", - // "confirmationsCount": 6, - // "address": "address", - // "status": 2, - // "commission": 0.0001 - // } - // - const timestamp = this.safeTimestamp (transaction, 'timestamp'); - let type = this.safeString (transaction, 'type'); - if (type !== undefined) { - if (type === 'Incoming') { - type = 'deposit'; - } else if (type === 'Withdraw') { - type = 'withdrawal'; - } - } - const currencyId = this.safeString (transaction, 'currency'); - const code = this.safeCurrencyCode (currencyId, currency); - const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - return { - 'id': this.safeString (transaction, 'id'), - 'txid': this.safeString (transaction, 'txid'), - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'address': this.safeString (transaction, 'address'), - 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), - 'currency': code, - 'status': status, - 'fee': { - 'currency': code, - 'cost': this.safeFloat (transaction, 'commission'), - 'rate': undefined, - }, - 'info': transaction, - }; - } - - async createDepositAddress (code, params = {}) { - const request = { - 'new': 1, - }; - const response = await this.fetchDepositAddress (code, this.extend (request, params)); - return response; - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency': currency['id'], - }; - const response = await this.dwapiPostDepositCryptoaddress (this.extend (request, params)); - const result = this.safeValue (response, 'return', {}); - const address = this.safeString (result, 'address'); - this.checkAddress (address); - return { - 'currency': code, - 'address': address, - 'tag': undefined, // not documented in DSX API - 'info': response, - }; - } - - async withdraw (code, amount, address, tag = undefined, params = {}) { - this.checkAddress (address); - await this.loadMarkets (); - const currency = this.currency (code); - const commission = this.safeValue (params, 'commission'); - if (commission === undefined) { - throw new ArgumentsRequired (this.id + ' withdraw() requires a `commission` (withdrawal fee) parameter (string)'); - } - params = this.omit (params, commission); - const request = { - 'currency': currency['id'], - 'amount': parseFloat (amount), - 'address': address, - 'commission': commission, - }; - if (tag !== undefined) { - request['address'] += ':' + tag; - } - const response = await this.dwapiPostWithdrawCrypto (this.extend (request, params)); - // - // [ - // { - // "success": 1, - // "return": { - // "transactionId": 2863073 - // } - // } - // ] - // - const data = this.safeValue (response, 'return', {}); - const id = this.safeString (data, 'transactionId'); - return { - 'info': response, - 'id': id, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'][api]; - const query = this.omit (params, this.extractParams (path)); - if (api === 'private' || api === 'dwapi') { - url += '/' + this.version + '/' + this.implodeParams (path, params); - this.checkRequiredCredentials (); - const nonce = this.nonce (); - body = this.urlencode (this.extend ({ - 'nonce': nonce, - }, query)); - const signature = this.hmac (this.encode (body), this.encode (this.secret), 'sha512', 'base64'); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': signature, - }; - } else if (api === 'public') { - url += '/' + this.implodeParams (path, params); - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - url += '/' + this.implodeParams (path, params); - if (method === 'GET') { - if (Object.keys (query).length) { - url += '?' + this.urlencode (query); - } - } else { - if (Object.keys (query).length) { - body = this.json (query); - headers = { - 'Content-Type': 'application/json', - }; - } - } - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) { - if (response === undefined) { - return; // fallback to default error handler - } - if ('success' in response) { - // - // 1 - Liqui only returns the integer 'success' key from their private API - // - // { "success": 1, ... } httpCode === 200 - // { "success": 0, ... } httpCode === 200 - // - // 2 - However, exchanges derived from Liqui, can return non-integers - // - // It can be a numeric string - // { "sucesss": "1", ... } - // { "sucesss": "0", ... }, httpCode >= 200 (can be 403, 502, etc) - // - // Or just a string - // { "success": "true", ... } - // { "success": "false", ... }, httpCode >= 200 - // - // Or a boolean - // { "success": true, ... } - // { "success": false, ... }, httpCode >= 200 - // - // 3 - Oversimplified, Python PEP8 forbids comparison operator (===) of different types - // - // 4 - We do not want to copy-paste and duplicate the code of this handler to other exchanges derived from Liqui - // - // To cover points 1, 2, 3 and 4 combined this handler should work like this: - // - let success = this.safeValue (response, 'success', false); - if (typeof success === 'string') { - if ((success === 'true') || (success === '1')) { - success = true; - } else { - success = false; - } - } - if (!success) { - const code = this.safeString (response, 'code'); - const message = this.safeString (response, 'error'); - const feedback = this.id + ' ' + body; - this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback); - this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback); - throw new ExchangeError (feedback); // unknown message - } - } - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/equos.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/equos.js index 5dc44a2ac..0b90d79ed 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/equos.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/equos.js @@ -221,7 +221,7 @@ module.exports = class equos extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minTradeVol'), + 'min': this.safeNumber (market, 'minTradeVol'), 'max': undefined, }, 'price': { @@ -287,7 +287,7 @@ module.exports = class equos extends Exchange { const name = this.safeString (currency, 6); const status = this.safeInteger (currency, 4); const active = (status === 1); - const fee = this.safeFloat (currency, 5); // withdraw_fee + const fee = this.safeNumber (currency, 5); // withdraw_fee return { 'id': id, 'info': currency, @@ -379,8 +379,8 @@ module.exports = class equos extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); return [ this.convertFromScale (price, market['precision']['price']), this.convertFromScale (amount, market['precision']['amount']), @@ -526,9 +526,9 @@ module.exports = class equos extends Exchange { orderId = this.safeString (trade, 'orderId'); side = this.safeStringLower (trade, 'side'); type = this.parseOrderType (this.safeString (trade, 'ordType')); - price = this.safeFloat (trade, 'lastPx'); - amount = this.safeFloat (trade, 'quoteQty'); - let feeCost = this.safeFloat (trade, 'commission'); + price = this.safeNumber (trade, 'lastPx'); + amount = this.safeNumber (trade, 'quoteQty'); + let feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { feeCost = -feeCost; const feeCurrencyId = this.safeString (trade, 'commCurrency'); @@ -599,8 +599,8 @@ module.exports = class equos extends Exchange { if (assetType === 'ASSET') { const currencyId = this.safeString (position, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const quantity = this.safeFloat (position, 'quantity'); - const availableQuantity = this.safeFloat (position, 'availableQuantity'); + const quantity = this.safeNumber (position, 'quantity'); + const availableQuantity = this.safeNumber (position, 'availableQuantity'); const scale = this.safeInteger (position, 'quantity_scale'); const account = this.account (); account['free'] = this.convertFromScale (availableQuantity, scale); @@ -646,7 +646,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -743,7 +743,7 @@ module.exports = class equos extends Exchange { request['ordType'] = 2; request['price'] = this.convertToScale (price, this.getScale (price)); } else { - const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stopPx'); + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'stopPx'); params = this.omit (params, [ 'stopPrice', 'stopPx' ]); if (stopPrice === undefined) { if (type === 'stop') { @@ -1116,7 +1116,7 @@ module.exports = class equos extends Exchange { address = undefined; } const type = this.safeString (transaction, 'type'); - let amount = this.safeFloat (transaction, 'balance_change'); + let amount = this.safeNumber (transaction, 'balance_change'); if (amount === undefined) { amount = this.safeInteger (transaction, 'quantity'); const amountScale = this.safeInteger (transaction, 'quantity_scale'); @@ -1199,8 +1199,8 @@ module.exports = class equos extends Exchange { for (let i = 0; i < tradingFees.length; i++) { const tradingFee = tradingFees[i]; if (this.safeString (tradingFee, 'tier') !== undefined) { - taker[tradingFee['tier']] = this.safeFloat (tradingFee, 'taker'); - maker[tradingFee['tier']] = this.safeFloat (tradingFee, 'maker'); + taker[tradingFee['tier']] = this.safeNumber (tradingFee, 'taker'); + maker[tradingFee['tier']] = this.safeNumber (tradingFee, 'maker'); } } return { @@ -1331,28 +1331,6 @@ module.exports = class equos extends Exchange { let remaining = this.safeInteger (order, 'leavesQty'); const remainingScale = this.safeInteger (order, 'leavesQty_scale'); remaining = this.convertFromScale (remaining, remainingScale); - if (remaining <= 0) { - if ((filled !== undefined) && (amount !== undefined) && (filled < amount)) { - remaining = undefined; - } - } - if ((remaining === undefined) && (amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0); - } - let average = this.safeInteger (order, 'price', 0); - if (average === 0) { - average = undefined; - } - const averageScale = this.safeInteger (order, 'price_scale'); - average = this.convertFromScale (average, averageScale); - let cost = undefined; - if (filled !== 0) { - if (average > 0) { - cost = average * filled; - } else if (price > 0) { - cost = price * filled; - } - } let fee = undefined; const currencyId = this.safeInteger (order, 'feeInstrumentId'); const feeCurrencyCode = this.safeCurrencyCode (currencyId); @@ -1375,7 +1353,7 @@ module.exports = class equos extends Exchange { } const stopPriceScale = this.safeInteger (order, 'stopPx_scale', 0); const stopPrice = this.convertFromScale (this.safeInteger (order, 'stopPx'), stopPriceScale); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, @@ -1390,14 +1368,14 @@ module.exports = class equos extends Exchange { 'price': price, 'stopPrice': stopPrice, 'amount': amount, - 'cost': cost, - 'average': average, + 'cost': undefined, + 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/eterbase.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/eterbase.js index 40d2893d3..531327d1d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/eterbase.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/eterbase.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, InvalidOrder, ExchangeError, BadRequest, BadSymbol } = require ('./base/errors'); const { TRUNCATE, SIGNIFICANT_DIGITS } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // ---------------------------------------------------------------------------- @@ -217,7 +218,7 @@ module.exports = class eterbase extends Exchange { const rule = rules[i]; const attribute = this.safeString (rule, 'attribute'); const condition = this.safeString (rule, 'condition'); - const value = this.safeFloat (rule, 'value'); + const value = this.safeNumber (rule, 'value'); if ((attribute === 'Qty') && (condition === 'Min')) { minAmount = value; } else if ((attribute === 'Qty') && (condition === 'Max')) { @@ -307,7 +308,7 @@ module.exports = class eterbase extends Exchange { 'type': type, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawalFee'), + 'fee': this.safeNumber (currency, 'withdrawalFee'), 'precision': precision, 'limits': { 'amount': { @@ -323,8 +324,8 @@ module.exports = class eterbase extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalMin'), - 'max': this.safeFloat (currency, 'withdrawalMax'), + 'min': this.safeNumber (currency, 'withdrawalMin'), + 'max': this.safeNumber (currency, 'withdrawalMax'), }, }, }; @@ -351,17 +352,17 @@ module.exports = class eterbase extends Exchange { const marketId = this.safeString (ticker, 'marketId'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const last = this.safeFloat (ticker, 'price'); - const baseVolume = this.safeFloat (ticker, 'volumeBase'); - const quoteVolume = this.safeFloat (ticker, 'volume'); + const last = this.safeNumber (ticker, 'price'); + const baseVolume = this.safeNumber (ticker, 'volumeBase'); + const quoteVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); - const percentage = this.safeFloat (ticker, 'change'); + const percentage = this.safeNumber (ticker, 'change'); const result = { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -403,14 +404,6 @@ module.exports = class eterbase extends Exchange { return this.parseTicker (response, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { @@ -465,10 +458,12 @@ module.exports = class eterbase extends Exchange { // "filledAt": 1556355722341 // } // - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -477,9 +472,9 @@ module.exports = class eterbase extends Exchange { 'currency': feeCurrencyCode, }; } - let cost = this.safeFloat (trade, 'qty'); - if ((cost === undefined) && (price !== undefined) && (amount !== undefined)) { - cost = price * amount; + let cost = this.safeNumber (trade, 'qty'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const timestamp = this.safeInteger2 (trade, 'executedAt', 'filledAt'); const tradeSide = this.safeString (trade, 'side'); @@ -577,11 +572,11 @@ module.exports = class eterbase extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -644,14 +639,13 @@ module.exports = class eterbase extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'assetId'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': this.safeFloat (balance, 'reserved'), - 'total': this.safeFloat (balance, 'balance'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -778,18 +772,18 @@ module.exports = class eterbase extends Exchange { } else { type = 'stoplimit'; } - let price = this.safeFloat (order, 'limitPrice'); - const amount = this.safeFloat (order, 'qty'); - let remaining = this.safeFloat (order, 'remainingQty'); + let price = this.safeNumber (order, 'limitPrice'); + const amount = this.safeNumber (order, 'qty'); + let remaining = this.safeNumber (order, 'remainingQty'); let filled = undefined; - const remainingCost = this.safeFloat (order, 'remainingCost'); + const remainingCost = this.safeNumber (order, 'remainingCost'); if ((remainingCost !== undefined) && (remainingCost === 0.0)) { remaining = 0; } if ((amount !== undefined) && (remaining !== undefined)) { filled = Math.max (0, amount - remaining); } - const cost = this.safeFloat (order, 'cost'); + const cost = this.safeNumber (order, 'cost'); if (type === 'market') { if (price === 0.0) { if ((cost !== undefined) && (filled !== undefined)) { @@ -806,7 +800,7 @@ module.exports = class eterbase extends Exchange { } } const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -979,7 +973,7 @@ module.exports = class eterbase extends Exchange { } if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) { // for market buy it requires the amount of quote currency to spend - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); if (this.options['createMarketBuyOrderRequiresPrice']) { if (cost === undefined) { if (price !== undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exmo.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exmo.js index c9e19479d..d79e42079 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exmo.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exmo.js @@ -112,6 +112,7 @@ module.exports = class exmo extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.2 / 100, @@ -581,18 +582,18 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = marketId.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const maxAmount = this.safeFloat (limit, 'max_q'); - const maxPrice = this.safeFloat (limit, 'max_p'); - const maxCost = this.safeFloat (limit, 'max_a'); - const minAmount = this.safeFloat (limit, 'min_q'); - const minPrice = this.safeFloat (limit, 'min_p'); - const minCost = this.safeFloat (limit, 'min_a'); - minAmounts[base] = Math.min (this.safeFloat (minAmounts, base, minAmount), minAmount); - maxAmounts[base] = Math.max (this.safeFloat (maxAmounts, base, maxAmount), maxAmount); - minPrices[quote] = Math.min (this.safeFloat (minPrices, quote, minPrice), minPrice); - minCosts[quote] = Math.min (this.safeFloat (minCosts, quote, minCost), minCost); - maxPrices[quote] = Math.max (this.safeFloat (maxPrices, quote, maxPrice), maxPrice); - maxCosts[quote] = Math.max (this.safeFloat (maxCosts, quote, maxCost), maxCost); + const maxAmount = this.safeNumber (limit, 'max_q'); + const maxPrice = this.safeNumber (limit, 'max_p'); + const maxCost = this.safeNumber (limit, 'max_a'); + const minAmount = this.safeNumber (limit, 'min_q'); + const minPrice = this.safeNumber (limit, 'min_p'); + const minCost = this.safeNumber (limit, 'min_a'); + minAmounts[base] = Math.min (this.safeNumber (minAmounts, base, minAmount), minAmount); + maxAmounts[base] = Math.max (this.safeNumber (maxAmounts, base, maxAmount), maxAmount); + minPrices[quote] = Math.min (this.safeNumber (minPrices, quote, minPrice), minPrice); + minCosts[quote] = Math.min (this.safeNumber (minCosts, quote, minCost), minCost); + maxPrices[quote] = Math.max (this.safeNumber (maxPrices, quote, maxPrice), maxPrice); + maxCosts[quote] = Math.max (this.safeNumber (maxCosts, quote, maxCost), maxCost); } const result = {}; for (let i = 0; i < ids.length; i++) { @@ -609,16 +610,16 @@ module.exports = class exmo extends Exchange { 'precision': 8, 'limits': { 'amount': { - 'min': this.safeFloat (minAmounts, code), - 'max': this.safeFloat (maxAmounts, code), + 'min': this.safeNumber (minAmounts, code), + 'max': this.safeNumber (maxAmounts, code), }, 'price': { - 'min': this.safeFloat (minPrices, code), - 'max': this.safeFloat (maxPrices, code), + 'min': this.safeNumber (minPrices, code), + 'max': this.safeNumber (maxPrices, code), }, 'cost': { - 'min': this.safeFloat (minCosts, code), - 'max': this.safeFloat (maxCosts, code), + 'min': this.safeNumber (minCosts, code), + 'max': this.safeNumber (maxCosts, code), }, }, 'info': id, @@ -653,8 +654,8 @@ module.exports = class exmo extends Exchange { const [ baseId, quoteId ] = symbol.split ('/'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); - const taker = this.safeFloat (market, 'commission_taker_percent'); - const maker = this.safeFloat (market, 'commission_maker_percent'); + const taker = this.safeNumber (market, 'commission_taker_percent'); + const maker = this.safeNumber (market, 'commission_maker_percent'); result.push ({ 'id': id, 'symbol': symbol, @@ -667,16 +668,16 @@ module.exports = class exmo extends Exchange { 'maker': maker / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, }, 'precision': { @@ -749,11 +750,11 @@ module.exports = class exmo extends Exchange { // return [ this.safeInteger (ohlcv, 't'), - this.safeFloat (ohlcv, 'o'), - this.safeFloat (ohlcv, 'h'), - this.safeFloat (ohlcv, 'l'), - this.safeFloat (ohlcv, 'c'), - this.safeFloat (ohlcv, 'v'), + this.safeNumber (ohlcv, 'o'), + this.safeNumber (ohlcv, 'h'), + this.safeNumber (ohlcv, 'l'), + this.safeNumber (ohlcv, 'c'), + this.safeNumber (ohlcv, 'v'), ]; } @@ -769,14 +770,14 @@ module.exports = class exmo extends Exchange { const currencyId = this.currencyId (code); const account = this.account (); if (currencyId in free) { - account['free'] = this.safeFloat (free, currencyId); + account['free'] = this.safeString (free, currencyId); } if (currencyId in used) { - account['used'] = this.safeFloat (used, currencyId); + account['used'] = this.safeString (used, currencyId); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -834,16 +835,16 @@ module.exports = class exmo extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy_price'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy_price'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell_price'), + 'ask': this.safeNumber (ticker, 'sell_price'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -852,9 +853,9 @@ module.exports = class exmo extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'vol_curr'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'vol_curr'), 'info': ticker, }; } @@ -915,9 +916,9 @@ module.exports = class exmo extends Exchange { let symbol = undefined; const id = this.safeString (trade, 'trade_id'); const orderId = this.safeString (trade, 'order_id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'quantity'); + const cost = this.safeNumber (trade, 'amount'); const side = this.safeString (trade, 'type'); const type = undefined; const marketId = this.safeString (trade, 'pair'); @@ -936,11 +937,11 @@ module.exports = class exmo extends Exchange { } const takerOrMaker = this.safeString (trade, 'exec_type'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission_amount'); + const feeCost = this.safeNumber (trade, 'commission_amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commission_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (trade, 'commission_percent'); + let feeRate = this.safeNumber (trade, 'commission_percent'); if (feeRate !== undefined) { feeRate /= 1000; } @@ -1239,13 +1240,13 @@ module.exports = class exmo extends Exchange { market = this.markets_by_id[marketId]; } } - let amount = this.safeFloat (order, 'quantity'); + let amount = this.safeNumber (order, 'quantity'); if (amount === undefined) { const amountField = (side === 'buy') ? 'in_amount' : 'out_amount'; - amount = this.safeFloat (order, amountField); + amount = this.safeNumber (order, amountField); } - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'amount'); + let price = this.safeNumber (order, 'price'); + let cost = this.safeNumber (order, 'amount'); let filled = 0.0; const trades = []; const transactions = this.safeValue (order, 'trades', []); @@ -1366,24 +1367,6 @@ module.exports = class exmo extends Exchange { return undefined; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { await this.loadMarkets (); const currency = this.currency (code); @@ -1428,7 +1411,7 @@ module.exports = class exmo extends Exchange { // } // const timestamp = this.safeTimestamp (transaction, 'dt'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -1458,7 +1441,7 @@ module.exports = class exmo extends Exchange { // fixed funding fees only (for now) if (!this.fees['funding']['percentage']) { const key = (type === 'withdrawal') ? 'withdraw' : 'deposit'; - let feeCost = this.safeFloat (this.options['fundingFees'][key], code); + let feeCost = this.safeNumber (this.options['fundingFees'][key], code); // users don't pay for cashbacks, no fees for that const provider = this.safeString (transaction, 'provider'); if (provider === 'cashback') { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exx.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exx.js index c4c12d03f..72b59ef1b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exx.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/exx.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ExchangeNotAvailable, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -148,26 +149,26 @@ module.exports = class exx extends Exchange { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); ticker = ticker['ticker']; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'riseRate'), + 'change': this.safeNumber (ticker, 'riseRate'), 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -217,14 +218,11 @@ module.exports = class exx extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -269,14 +267,13 @@ module.exports = class exx extends Exchange { const currencyId = currencies[i]; const balance = balances[currencyId]; const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'balance'), - 'used': this.safeFloat (balance, 'freeze'), - 'total': this.safeFloat (balance, 'total'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'freeze'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { @@ -296,11 +293,10 @@ module.exports = class exx extends Exchange { // const symbol = market['symbol']; const timestamp = parseInt (order['trade_date']); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'trade_money'); - const amount = this.safeFloat (order, 'total_amount'); - const filled = this.safeFloat (order, 'trade_amount', 0.0); - const remaining = parseFloat (this.amountToPrecision (symbol, amount - filled)); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'trade_money'); + const amount = this.safeNumber (order, 'total_amount'); + const filled = this.safeNumber (order, 'trade_amount', 0.0); let status = this.safeInteger (order, 'status'); if (status === 1) { status = 'canceled'; @@ -312,11 +308,11 @@ module.exports = class exx extends Exchange { let fee = undefined; if ('fees' in order) { fee = { - 'cost': this.safeFloat (order, 'fees'), + 'cost': this.safeNumber (order, 'fees'), 'currency': market['quote'], }; } - return { + return this.safeOrder ({ 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -333,12 +329,12 @@ module.exports = class exx extends Exchange { 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/fcoin.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/fcoin.js index 2d1c845ab..2d90e7cce 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/fcoin.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/fcoin.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeError, ExchangeNotAvailable, ArgumentsRequired, InsufficientFunds, InvalidOrder, RateLimitExceeded, InvalidNonce, AuthenticationError, NotSupported } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -223,8 +224,8 @@ module.exports = class fcoin extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'limit_amount_min'), - 'max': this.safeFloat (market, 'limit_amount_max'), + 'min': this.safeNumber (market, 'limit_amount_min'), + 'max': this.safeNumber (market, 'limit_amount_max'), }, 'price': { 'min': Math.pow (10, -precision['price']), @@ -319,12 +320,12 @@ module.exports = class fcoin extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseBidsAsks (orders, priceKey = 0, amountKey = 1) { @@ -337,8 +338,8 @@ module.exports = class fcoin extends Exchange { const priceField = this.sum (index, priceKey); const amountField = this.sum (index, amountKey); result.push ([ - this.safeFloat (orders, priceField), - this.safeFloat (orders, amountField), + this.safeNumber (orders, priceField), + this.safeNumber (orders, amountField), ]); } return result; @@ -386,17 +387,17 @@ module.exports = class fcoin extends Exchange { } } const values = ticker['ticker']; - const last = this.safeFloat (values, 0); + const last = this.safeNumber (values, 0); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (values, 7), - 'low': this.safeFloat (values, 8), - 'bid': this.safeFloat (values, 2), - 'bidVolume': this.safeFloat (values, 3), - 'ask': this.safeFloat (values, 4), - 'askVolume': this.safeFloat (values, 5), + 'high': this.safeNumber (values, 7), + 'low': this.safeNumber (values, 8), + 'bid': this.safeNumber (values, 2), + 'bidVolume': this.safeNumber (values, 3), + 'ask': this.safeNumber (values, 4), + 'askVolume': this.safeNumber (values, 5), 'vwap': undefined, 'open': undefined, 'close': last, @@ -405,8 +406,8 @@ module.exports = class fcoin extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (values, 9), - 'quoteVolume': this.safeFloat (values, 10), + 'baseVolume': this.safeNumber (values, 9), + 'quoteVolume': this.safeNumber (values, 10), 'info': ticker, }; } @@ -419,14 +420,11 @@ module.exports = class fcoin extends Exchange { const timestamp = this.safeInteger (trade, 'ts'); const side = this.safeStringLower (trade, 'side'); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = undefined; return { 'id': id, @@ -551,38 +549,25 @@ module.exports = class fcoin extends Exchange { const symbol = market['symbol']; const orderType = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'created_at'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'filled_amount'); - let remaining = undefined; - let price = this.safeFloat (order, 'price'); - let cost = this.safeFloat (order, 'executed_value'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } else if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'filled_amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'executed_value'); let feeCurrency = undefined; let feeCost = undefined; - const feeRebate = this.safeFloat (order, 'fees_income'); + const feeRebate = this.safeNumber (order, 'fees_income'); if ((feeRebate !== undefined) && (feeRebate > 0)) { if (market !== undefined) { feeCurrency = (side === 'buy') ? market['quote'] : market['base']; } feeCost = -feeRebate; } else { - feeCost = this.safeFloat (order, 'fill_fees'); + feeCost = this.safeNumber (order, 'fill_fees'); if (market !== undefined) { feeCurrency = (side === 'buy') ? market['base'] : market['quote']; } } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -598,7 +583,7 @@ module.exports = class fcoin extends Exchange { 'stopPrice': undefined, 'cost': cost, 'amount': amount, - 'remaining': remaining, + 'remaining': undefined, 'filled': filled, 'average': undefined, 'status': status, @@ -607,7 +592,7 @@ module.exports = class fcoin extends Exchange { 'currency': feeCurrency, }, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -649,11 +634,11 @@ module.exports = class fcoin extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_vol'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_vol'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/flowbtc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/flowbtc.js index 12646489b..45d80935d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/flowbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/flowbtc.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -131,11 +132,11 @@ module.exports = class flowbtc extends Exchange { const currencyId = balance['name']; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['total'] = this.safeFloat (balance, 'hold'); + account['free'] = this.safeString (balance, 'balance'); + account['total'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -156,16 +157,16 @@ module.exports = class flowbtc extends Exchange { }; const ticker = await this.publicPostGetTicker (this.extend (request, params)); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -175,8 +176,8 @@ module.exports = class flowbtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume24hr'), - 'quoteVolume': this.safeFloat (ticker, 'volume24hrProduct2'), + 'baseVolume': this.safeNumber (ticker, 'volume24hr'), + 'quoteVolume': this.safeNumber (ticker, 'volume24hrProduct2'), 'info': ticker, }; } @@ -185,14 +186,11 @@ module.exports = class flowbtc extends Exchange { const timestamp = this.safeTimestamp (trade, 'unixtime'); const side = (trade['incomingOrderSide'] === 0) ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'px'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'px'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'timestamp': timestamp, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/foxbit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/foxbit.js index 5830969a3..b1fb3032b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/foxbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/foxbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89,11 +90,11 @@ module.exports = class foxbit extends Exchange { // otherwise we will lose the info if the currency balance has been funded or traded or not if (currencyId in balances) { const account = this.account (); - let used = this.safeFloat (balances, currencyId + '_locked'); + let used = this.safeNumber (balances, currencyId + '_locked'); if (used !== undefined) { used *= 1e-8; } - let total = this.safeFloat (balances, currencyId); + let total = this.safeNumber (balances, currencyId); if (total !== undefined) { total *= 1e-8; } @@ -128,16 +129,16 @@ module.exports = class foxbit extends Exchange { const timestamp = this.milliseconds (); const lowercaseQuote = market['quote'].toLowerCase (); const quoteVolume = 'vol_' + lowercaseQuote; - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -147,8 +148,8 @@ module.exports = class foxbit extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -161,14 +162,11 @@ module.exports = class foxbit extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ftx.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ftx.js index 18b572cc6..a0e42e8e4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ftx.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ftx.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending } = require ('./base/errors'); +const { ExchangeError, InvalidOrder, BadRequest, InsufficientFunds, OrderNotFound, AuthenticationError, RateLimitExceeded, ExchangeNotAvailable, CancelPending, ArgumentsRequired, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -243,6 +244,7 @@ module.exports = class ftx extends Exchange { 'An unexpected error occurred': ExchangeNotAvailable, // {"error":"An unexpected error occurred, please try again later (58BC21C795).","success":false} 'Please retry request': ExchangeNotAvailable, // {"error":"Please retry request","success":false} 'Please try again': ExchangeNotAvailable, // {"error":"Please try again","success":false} + 'Only have permissions for subaccount': PermissionDenied, // {"success":false,"error":"Only have permissions for subaccount *sub_name*"} }, }, 'precisionMode': TICK_SIZE, @@ -366,8 +368,8 @@ module.exports = class ftx extends Exchange { // check if a market is a spot or future market const symbol = (type === 'future') ? this.safeString (market, 'name') : (base + '/' + quote); const active = this.safeValue (market, 'enabled'); - const sizeIncrement = this.safeFloat (market, 'sizeIncrement'); - const priceIncrement = this.safeFloat (market, 'priceIncrement'); + const sizeIncrement = this.safeNumber (market, 'sizeIncrement'); + const priceIncrement = this.safeNumber (market, 'priceIncrement'); const precision = { 'amount': sizeIncrement, 'price': priceIncrement, @@ -445,28 +447,28 @@ module.exports = class ftx extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); const timestamp = this.safeTimestamp (ticker, 'time', this.milliseconds ()); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidSize'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askSize'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidSize'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askSize'), 'vwap': undefined, 'open': undefined, 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'change24h'), + 'percentage': this.safeNumber (ticker, 'change24h'), 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'quoteVolume24h'), + 'quoteVolume': this.safeNumber (ticker, 'quoteVolume24h'), 'info': ticker, }; } @@ -506,14 +508,6 @@ module.exports = class ftx extends Exchange { return this.parseTicker (result, market); } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetMarkets (params); @@ -592,11 +586,11 @@ module.exports = class ftx extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -717,6 +711,45 @@ module.exports = class ftx extends Exchange { // "type": "otc" // } // + // with -ve fee + // { + // "id": 1171258927, + // "fee": -0.0000713875, + // "side": "sell", + // "size": 1, + // "time": "2021-03-11T13:34:35.523627+00:00", + // "type": "order", + // "price": 14.2775, + // "future": null, + // "market": "SOL/USD", + // "feeRate": -0.000005, + // "orderId": 33182929044, + // "tradeId": 582936801, + // "liquidity": "maker", + // "feeCurrency": "USD", + // "baseCurrency": "SOL", + // "quoteCurrency": "USD" + // } + // + // // from OTC order + // { + // "id": 1172129651, + // "fee": 0, + // "side": "sell", + // "size": 1.47568846, + // "time": "2021-03-11T15:04:46.893383+00:00", + // "type": "otc", + // "price": 14.60932598, + // "future": null, + // "market": null, + // "feeRate": 0, + // "orderId": null, + // "tradeId": null, + // "liquidity": "taker", + // "feeCurrency": "USD", + // "baseCurrency": "BCHA", + // "quoteCurrency": "USD" + // } const id = this.safeString (trade, 'id'); const takerOrMaker = this.safeString (trade, 'liquidity'); const marketId = this.safeString (trade, 'market'); @@ -734,25 +767,24 @@ module.exports = class ftx extends Exchange { } } const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (price !== undefined && amount !== undefined) { - cost = price * amount; - } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { 'cost': feeCost, 'currency': feeCurrencyCode, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } const orderId = this.safeString (trade, 'orderId'); @@ -858,8 +890,8 @@ module.exports = class ftx extends Exchange { const result = this.safeValue (response, 'result', {}); return { 'info': response, - 'maker': this.safeFloat (result, 'makerFee'), - 'taker': this.safeFloat (result, 'takerFee'), + 'maker': this.safeNumber (result, 'makerFee'), + 'taker': this.safeNumber (result, 'takerFee'), }; } @@ -886,11 +918,11 @@ module.exports = class ftx extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'coin')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'free'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -1013,9 +1045,9 @@ module.exports = class ftx extends Exchange { const id = this.safeString (order, 'id'); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); let status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filledSize'); - let remaining = this.safeFloat (order, 'remainingSize'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filledSize'); + let remaining = this.safeNumber (order, 'remainingSize'); if ((remaining === 0.0) && (amount !== undefined) && (filled !== undefined)) { remaining = Math.max (amount - filled, 0); if (remaining > 0) { @@ -1039,15 +1071,15 @@ module.exports = class ftx extends Exchange { } const side = this.safeString (order, 'side'); const type = this.safeString (order, 'type'); - const average = this.safeFloat (order, 'avgFillPrice'); - const price = this.safeFloat2 (order, 'price', 'triggerPrice', average); + const average = this.safeNumber (order, 'avgFillPrice'); + const price = this.safeNumber2 (order, 'price', 'triggerPrice', average); let cost = undefined; if (filled !== undefined && price !== undefined) { cost = filled * price; } const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'triggeredAt')); const clientOrderId = this.safeString (order, 'clientId'); - const stopPrice = this.safeFloat (order, 'triggerPrice'); + const stopPrice = this.safeNumber (order, 'triggerPrice'); const postOnly = this.safeValue (order, 'postOnly'); return { 'info': order, @@ -1093,22 +1125,28 @@ module.exports = class ftx extends Exchange { request['clientId'] = clientOrderId; params = this.omit (params, [ 'clientId', 'clientOrderId' ]); } - let priceToPrecision = undefined; - if (price !== undefined) { - priceToPrecision = parseFloat (this.priceToPrecision (symbol, price)); - } - let method = 'privatePostConditionalOrders'; + let method = undefined; if (type === 'limit') { method = 'privatePostOrders'; - request['price'] = priceToPrecision; + request['price'] = parseFloat (this.priceToPrecision (symbol, price)); } else if (type === 'market') { method = 'privatePostOrders'; request['price'] = null; } else if ((type === 'stop') || (type === 'takeProfit')) { - request['triggerPrice'] = priceToPrecision; - // request['orderPrice'] = number; // optional, order type is limit if this is specified, otherwise market + method = 'privatePostConditionalOrders'; + const stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerPrice'); + if (stopPrice === undefined) { + throw new ArgumentsRequired (this.id + ' createOrder () requires a stopPrice parameter or a triggerPrice parameter for ' + type + ' orders'); + } else { + params = this.omit (params, [ 'stopPrice', 'triggerPrice' ]); + request['triggerPrice'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + } + if (price !== undefined) { + request['orderPrice'] = parseFloat (this.priceToPrecision (symbol, price)); // optional, order type is limit if this is specified, otherwise market + } } else if (type === 'trailingStop') { - request['trailValue'] = priceToPrecision; // negative for "sell", positive for "buy" + method = 'privatePostConditionalOrders'; + request['trailValue'] = parseFloat (this.priceToPrecision (symbol, price)); // negative for "sell", positive for "buy" } else { throw new InvalidOrder (this.id + ' createOrder () does not support order type ' + type + ', only limit, market, stop, trailingStop, or takeProfit orders are supported'); } @@ -1174,9 +1212,9 @@ module.exports = class ftx extends Exchange { const request = {}; let method = undefined; const clientOrderId = this.safeString2 (params, 'client_order_id', 'clientOrderId'); - const triggerPrice = this.safeFloat (params, 'triggerPrice'); - const orderPrice = this.safeFloat (params, 'orderPrice'); - const trailValue = this.safeFloat (params, 'trailValue'); + const triggerPrice = this.safeNumber (params, 'triggerPrice'); + const orderPrice = this.safeNumber (params, 'orderPrice'); + const trailValue = this.safeNumber (params, 'trailValue'); params = this.omit (params, [ 'client_order_id', 'clientOrderId', 'triggerPrice', 'orderPrice', 'trailValue' ]); const triggerPriceIsDefined = (triggerPrice !== undefined); const orderPriceIsDefined = (orderPrice !== undefined); @@ -1539,7 +1577,7 @@ module.exports = class ftx extends Exchange { return this.parseTransaction (result, currency); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetAccount (params); // @@ -1672,7 +1710,7 @@ module.exports = class ftx extends Exchange { // const code = this.safeCurrencyCode (this.safeString (transaction, 'coin')); const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'size'); + const amount = this.safeNumber (transaction, 'size'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const timestamp = this.parse8601 (this.safeString (transaction, 'time')); const txid = this.safeString (transaction, 'txid'); @@ -1689,7 +1727,7 @@ module.exports = class ftx extends Exchange { address = notes.slice (12); } } - const fee = this.safeFloat (transaction, 'fee'); + const fee = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gateio.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gateio.js index f0835c774..eac7234c9 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gateio.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gateio.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, ArgumentsRequired, InvalidAddress, OrderNotFound, NotSupported, DDoSProtection, InsufficientFunds, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,9 +165,12 @@ module.exports = class gateio extends Exchange { }, }, 'commonCurrencies': { + '88MPH': 'MPH', + 'BIFI': 'Bitcoin File', 'BOX': 'DefiBox', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', + 'MPH': 'Morpher', // conflict with 88MPH 'SBTC': 'Super Bitcoin', 'TNC': 'Trinity Network Credit', }, @@ -213,9 +217,9 @@ module.exports = class gateio extends Exchange { const currency = coin[id]; const code = this.safeCurrencyCode (id); const delisted = this.safeValue (currency, 'delisted', 0); - const withdrawDisabled = this.safeValue (currency, 'withdraw_disabled', 0); - const depositDisabled = this.safeValue (currency, 'deposit_disabled', 0); - const tradeDisabled = this.safeValue (currency, 'trade_disabled', 0); + const withdrawDisabled = this.safeInteger2 (currency, 'withdraw_disabled', 0); + const depositDisabled = this.safeInteger2 (currency, 'deposit_disabled', 0); + const tradeDisabled = this.safeInteger2 (currency, 'trade_disabled', 0); const listed = (delisted === 0); const withdrawEnabled = (withdrawDisabled === 0); const depositEnabled = (depositDisabled === 0); @@ -304,7 +308,7 @@ module.exports = class gateio extends Exchange { 'price': this.safeInteger (details, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (details, 'min_amount'), + 'min': this.safeNumber (details, 'min_amount'), 'max': undefined, }; const priceLimits = { @@ -312,7 +316,7 @@ module.exports = class gateio extends Exchange { 'max': undefined, }; const defaultCost = amountLimits['min'] * priceLimits['min']; - const minCost = this.safeFloat (this.options['limits']['cost']['min'], quote, defaultCost); + const minCost = this.safeNumber (this.options['limits']['cost']['min'], quote, defaultCost); const costLimits = { 'min': minCost, 'max': undefined, @@ -322,10 +326,10 @@ module.exports = class gateio extends Exchange { 'price': priceLimits, 'cost': costLimits, }; - const disabled = this.safeValue (details, 'trade_disabled'); + const disabled = this.safeInteger (details, 'trade_disabled'); const active = !disabled; const uppercaseId = id.toUpperCase (); - const fee = this.safeFloat (details, 'fee'); + const fee = this.safeNumber (details, 'fee'); result.push ({ 'id': id, 'uppercaseId': uppercaseId, @@ -359,11 +363,11 @@ module.exports = class gateio extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (available, currencyId); - account['used'] = this.safeFloat (locked, currencyId); + account['free'] = this.safeString (available, currencyId); + account['used'] = this.safeString (locked, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -379,11 +383,11 @@ module.exports = class gateio extends Exchange { // they return [ Timestamp, Volume, Close, High, Low, Open ] return [ this.safeInteger (ohlcv, 0), // t - this.safeFloat (ohlcv, 5), // o - this.safeFloat (ohlcv, 3), // h - this.safeFloat (ohlcv, 4), // l - this.safeFloat (ohlcv, 2), // c - this.safeFloat (ohlcv, 1), // v + this.safeNumber (ohlcv, 5), // o + this.safeNumber (ohlcv, 3), // h + this.safeNumber (ohlcv, 4), // l + this.safeNumber (ohlcv, 2), // c + this.safeNumber (ohlcv, 1), // v ]; } @@ -395,11 +399,11 @@ module.exports = class gateio extends Exchange { 'group_sec': this.timeframes[timeframe], }; // max limit = 1001 - if (limit !== undefined) { - const periodDurationInSeconds = this.parseTimeframe (timeframe); - const hours = parseInt ((periodDurationInSeconds * limit) / 3600); - request['range_hour'] = Math.max (0, hours - 1); - } + // if (limit !== undefined) { + // const periodDurationInSeconds = this.parseTimeframe (timeframe); + // const hours = parseInt ((periodDurationInSeconds * limit) / 3600); + // request['range_hour'] = Math.max (1, hours - 1); + // } const response = await this.publicGetCandlestick2Id (this.extend (request, params)); // // { @@ -423,8 +427,8 @@ module.exports = class gateio extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'percentChange'); let open = undefined; let change = undefined; let average = undefined; @@ -434,17 +438,17 @@ module.exports = class gateio extends Exchange { change = last - open; average = this.sum (last, open) / 2; } - open = this.safeFloat (ticker, 'open', open); - change = this.safeFloat (ticker, 'change', change); + open = this.safeNumber (ticker, 'open', open); + change = this.safeNumber (ticker, 'change', change); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat2 (ticker, 'high24hr', 'high'), - 'low': this.safeFloat2 (ticker, 'low24hr', 'low'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber2 (ticker, 'high24hr', 'high'), + 'low': this.safeNumber2 (ticker, 'low24hr', 'low'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -454,8 +458,8 @@ module.exports = class gateio extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), // gateio has them reversed - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), // gateio has them reversed + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -501,27 +505,24 @@ module.exports = class gateio extends Exchange { const id = this.safeString2 (trade, 'tradeID', 'id'); // take either of orderid or orderId const orderId = this.safeString2 (trade, 'orderid', 'orderNumber'); - const price = this.safeFloat2 (trade, 'rate', 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString2 (trade, 'rate', 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = this.safeString (trade, 'type'); const takerOrMaker = this.safeString (trade, 'role'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } let fee = undefined; let feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee_coin')); - let feeCost = this.safeFloat (trade, 'point_fee'); + let feeCost = this.safeNumber (trade, 'point_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'gt_fee'); + feeCost = this.safeNumber (trade, 'gt_fee'); if ((feeCost === undefined) || (feeCost === 0)) { - feeCost = this.safeFloat (trade, 'fee'); + feeCost = this.safeNumber (trade, 'fee'); } else { feeCurrency = this.safeCurrencyCode ('GT'); } @@ -665,23 +666,20 @@ module.exports = class gateio extends Exchange { } else if (side === '2') { side = 'buy'; } - const price = this.safeFloat2 (order, 'initialRate', 'rate'); - const average = this.safeFloat (order, 'filledRate'); - const amount = this.safeFloat2 (order, 'initialAmount', 'amount'); - const filled = this.safeFloat (order, 'filledAmount'); + const price = this.safeNumber2 (order, 'initialRate', 'rate'); + const average = this.safeNumber (order, 'filledRate'); + const amount = this.safeNumber2 (order, 'initialAmount', 'amount'); + const filled = this.safeNumber (order, 'filledAmount'); // In the order status response, this field has a different name. - let remaining = this.safeFloat2 (order, 'leftAmount', 'left'); - if (remaining === undefined) { - remaining = amount - filled; - } - const feeCost = this.safeFloat (order, 'feeValue'); + const remaining = this.safeNumber2 (order, 'leftAmount', 'left'); + const feeCost = this.safeNumber (order, 'feeValue'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - let feeRate = this.safeFloat (order, 'feePercentage'); + let feeRate = this.safeNumber (order, 'feePercentage'); if (feeRate !== undefined) { feeRate = feeRate / 100; } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -707,7 +705,7 @@ module.exports = class gateio extends Exchange { 'rate': feeRate, }, 'info': order, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -898,7 +896,7 @@ module.exports = class gateio extends Exchange { const code = this.safeCurrencyCode (currencyId, currency); const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'txid'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); if (address === 'false') { address = undefined; @@ -906,7 +904,7 @@ module.exports = class gateio extends Exchange { const timestamp = this.safeTimestamp (transaction, 'timestamp'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.parseTransactionType (id[0]); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gemini.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gemini.js index 6f28ef220..36892fa47 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gemini.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gemini.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidOrder, InvalidNonce, InsufficientFunds, AuthenticationError, PermissionDenied, NotSupported, OnMaintenance, RateLimitExceeded, ExchangeNotAvailable } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -221,16 +222,16 @@ module.exports = class gemini extends Exchange { // const base = this.safeCurrencyCode (baseId); const minAmountString = cells[1].replace ('', ''); const minAmountParts = minAmountString.split (' '); - const minAmount = this.safeFloat (minAmountParts, 0); + const minAmount = this.safeNumber (minAmountParts, 0); const amountPrecisionString = cells[2].replace ('', ''); const amountPrecisionParts = amountPrecisionString.split (' '); - const amountPrecision = this.safeFloat (amountPrecisionParts, 0); + const amountPrecision = this.safeNumber (amountPrecisionParts, 0); const idLength = marketId.length - 0; const quoteId = marketId.slice (idLength - 3, idLength); const quote = this.safeCurrencyCode (quoteId); const pricePrecisionString = cells[3].replace ('', ''); const pricePrecisionParts = pricePrecisionString.split (' '); - const pricePrecision = this.safeFloat (pricePrecisionParts, 0); + const pricePrecision = this.safeNumber (pricePrecisionParts, 0); const baseId = marketId.replace (quoteId, ''); const base = this.safeCurrencyCode (baseId); const symbol = base + '/' + quote; @@ -458,11 +459,11 @@ module.exports = class gemini extends Exchange { base = market['base']; quote = market['quote']; } - const price = this.safeFloat (ticker, 'price'); - const last = this.safeFloat2 (ticker, 'last', 'close', price); - let percentage = this.safeFloat (ticker, 'percentChange24h'); + const price = this.safeNumber (ticker, 'price'); + const last = this.safeNumber2 (ticker, 'last', 'close', price); + let percentage = this.safeNumber (ticker, 'percentChange24h'); let change = undefined; - let open = this.safeFloat (ticker, 'open'); + let open = this.safeNumber (ticker, 'open'); let average = undefined; if (last !== undefined) { if (open !== undefined) { @@ -479,18 +480,18 @@ module.exports = class gemini extends Exchange { average = this.sum (last, open) / 2; } } - const baseVolume = this.safeFloat (volume, baseId); - const quoteVolume = this.safeFloat (volume, quoteId); + const baseVolume = this.safeNumber (volume, baseId); + const quoteVolume = this.safeNumber (volume, quoteId); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -506,14 +507,6 @@ module.exports = class gemini extends Exchange { }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetV1Pricefeed (params); @@ -554,17 +547,14 @@ module.exports = class gemini extends Exchange { const feeCurrencyId = this.safeString (trade, 'fee_currency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); const fee = { - 'cost': this.safeFloat (trade, 'fee_amount'), + 'cost': this.safeNumber (trade, 'fee_amount'), 'currency': feeCurrencyCode, }; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = undefined; const side = this.safeStringLower (trade, 'type'); const symbol = this.safeSymbol (undefined, market); @@ -617,18 +607,18 @@ module.exports = class gemini extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'amount'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrder (order, market = undefined) { const timestamp = this.safeInteger (order, 'timestampms'); - const amount = this.safeFloat (order, 'original_amount'); - const remaining = this.safeFloat (order, 'remaining_amount'); - const filled = this.safeFloat (order, 'executed_amount'); + const amount = this.safeNumber (order, 'original_amount'); + const remaining = this.safeNumber (order, 'remaining_amount'); + const filled = this.safeNumber (order, 'executed_amount'); let status = 'closed'; if (order['is_live']) { status = 'open'; @@ -636,14 +626,8 @@ module.exports = class gemini extends Exchange { if (order['is_cancelled']) { status = 'canceled'; } - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'avg_execution_price'); - let cost = undefined; - if (filled !== undefined) { - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'avg_execution_price'); let type = this.safeString (order, 'type'); if (type === 'exchange limit') { type = 'limit'; @@ -658,7 +642,7 @@ module.exports = class gemini extends Exchange { const id = this.safeString (order, 'order_id'); const side = this.safeStringLower (order, 'side'); const clientOrderId = this.safeString (order, 'client_order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -674,13 +658,13 @@ module.exports = class gemini extends Exchange { 'price': price, 'stopPrice': undefined, 'average': average, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'remaining': remaining, 'fee': fee, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -795,7 +779,7 @@ module.exports = class gemini extends Exchange { status = 'ok'; } let fee = undefined; - const feeAmount = this.safeFloat (transaction, 'feeAmount'); + const feeAmount = this.safeNumber (transaction, 'feeAmount'); if (feeAmount !== undefined) { fee = { 'cost': feeAmount, @@ -811,7 +795,7 @@ module.exports = class gemini extends Exchange { 'address': address, 'tag': undefined, // or is it defined? 'type': type, // direction of the transaction, ('deposit' | 'withdraw') - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gopax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gopax.js index e3150163a..b27308f19 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gopax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/gopax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound, InvalidAddress, BadRequest } = require ('./base/errors'); const { TRUNCATE, ROUND, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -218,8 +219,8 @@ module.exports = class gopax extends Exchange { const minimums = this.safeValue (market, 'restApiOrderAmountMin', {}); const marketAsk = this.safeValue (minimums, 'marketAsk', {}); const marketBid = this.safeValue (minimums, 'marketBid', {}); - const takerFeePercent = this.safeFloat (market, 'takerFeePercent'); - const makerFeePercent = this.safeFloat (market, 'makerFeePercent'); + const takerFeePercent = this.safeNumber (market, 'takerFeePercent'); + const makerFeePercent = this.safeNumber (market, 'makerFeePercent'); const taker = parseFloat (this.decimalToPrecision (takerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); const maker = parseFloat (this.decimalToPrecision (makerFeePercent / 100, ROUND, 0.00000001, TICK_SIZE)); result.push ({ @@ -237,15 +238,15 @@ module.exports = class gopax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (marketAsk, 'amount'), + 'min': this.safeNumber (marketAsk, 'amount'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'priceMin'), + 'min': this.safeNumber (market, 'priceMin'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (marketBid, 'amount'), + 'min': this.safeNumber (marketBid, 'amount'), 'max': undefined, }, }, @@ -280,8 +281,8 @@ module.exports = class gopax extends Exchange { const id = this.safeString (currency, 'id'); const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'name'); - const fee = this.safeFloat (currency, 'withdrawalFee'); - const precision = this.safeFloat (currency, 'scale'); + const fee = this.safeNumber (currency, 'withdrawalFee'); + const precision = this.safeNumber (currency, 'scale'); result[code] = { 'id': id, 'info': currency, @@ -304,7 +305,7 @@ module.exports = class gopax extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawalAmountMin'), + 'min': this.safeNumber (currency, 'withdrawalAmountMin'), 'max': undefined, }, }, @@ -372,8 +373,8 @@ module.exports = class gopax extends Exchange { const marketId = this.safeString (ticker, 'name'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (ticker, 'time')); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat2 (ticker, 'price', 'close'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber2 (ticker, 'price', 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -384,20 +385,20 @@ module.exports = class gopax extends Exchange { percentage = change / open * 100; } } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bidVolume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'askVolume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bidVolume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'askVolume'), 'vwap': vwap, 'open': open, 'close': last, @@ -433,14 +434,6 @@ module.exports = class gopax extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTradingPairsStats (params); @@ -462,8 +455,8 @@ module.exports = class gopax extends Exchange { parsePublicTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'time')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'amount'); let symbol = undefined; if ('symbol' in market) { symbol = this.safeString (market, 'symbol'); @@ -489,14 +482,14 @@ module.exports = class gopax extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const symbol = this.safeString (trade, 'tradingPairName').replace ('-', '/'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'baseAmount'); + const price = this.safeNumber (trade, 'price'); + const amount = this.safeNumber (trade, 'baseAmount'); let feeCurrency = symbol.slice (0, 3); if (side === 'sell') { feeCurrency = symbol.slice (4); } const fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': feeCurrency, 'rate': undefined, }; @@ -578,15 +571,15 @@ module.exports = class gopax extends Exchange { } else if (type === '2') { type = 'market'; } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'baseAmount'); - let cost = this.safeFloat (trade, 'quoteAmount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'baseAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteAmount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -653,11 +646,11 @@ module.exports = class gopax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -697,14 +690,14 @@ module.exports = class gopax extends Exchange { const balance = response[i]; const currencyId = this.safeString2 (balance, 'asset', 'isoAlpha3'); const code = this.safeCurrencyCode (currencyId); - const hold = this.safeFloat (balance, 'hold'); - const pendingWithdrawal = this.safeFloat (balance, 'pendingWithdrawal'); + const hold = this.safeString (balance, 'hold'); + const pendingWithdrawal = this.safeString (balance, 'pendingWithdrawal'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.sum (hold, pendingWithdrawal); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = Precise.stringAdd (hold, pendingWithdrawal); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchBalance (params = {}) { @@ -781,42 +774,36 @@ module.exports = class gopax extends Exchange { const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); const timeInForce = this.safeStringUpper (order, 'timeInForce'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const stopPrice = this.safeFloat (order, 'stopPrice'); - const remaining = this.safeFloat (order, 'remaining'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const stopPrice = this.safeNumber (order, 'stopPrice'); + const remaining = this.safeNumber (order, 'remaining'); const marketId = this.safeString (order, 'tradingPairName'); market = this.safeMarket (marketId, market, '-'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const balanceChange = this.safeValue (order, 'balanceChange', {}); - let filled = this.safeFloat (balanceChange, 'baseNet'); - let cost = this.safeFloat (balanceChange, 'quoteNet'); + const filled = this.safeNumber (balanceChange, 'baseNet'); + let cost = this.safeNumber (balanceChange, 'quoteNet'); if (cost !== undefined) { cost = Math.abs (cost); } let updated = undefined; - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } if ((filled !== undefined) && (filled > 0)) { updated = this.parse8601 (this.safeString (order, 'updatedAt')); } - if ((cost === undefined) && (price !== undefined) && (filled !== undefined)) { - cost = filled * price; - } let fee = undefined; if (side === 'buy') { const baseFee = this.safeValue (balanceChange, 'baseFee', {}); - const taking = this.safeFloat (baseFee, 'taking'); - const making = this.safeFloat (baseFee, 'making'); + const taking = this.safeNumber (baseFee, 'taking'); + const making = this.safeNumber (baseFee, 'making'); fee = { 'currency': market['base'], 'cost': this.sum (taking, making), }; } else { const quoteFee = this.safeValue (balanceChange, 'quoteFee', {}); - const taking = this.safeFloat (quoteFee, 'taking'); - const making = this.safeFloat (quoteFee, 'making'); + const taking = this.safeNumber (quoteFee, 'taking'); + const making = this.safeNumber (quoteFee, 'making'); fee = { 'currency': market['quote'], 'cost': this.sum (taking, making), @@ -826,7 +813,7 @@ module.exports = class gopax extends Exchange { if (timeInForce !== undefined) { postOnly = (timeInForce === 'PO'); } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'datetime': this.iso8601 (timestamp), @@ -848,7 +835,7 @@ module.exports = class gopax extends Exchange { 'trades': undefined, 'fee': fee, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -996,7 +983,7 @@ module.exports = class gopax extends Exchange { request['clientOrderId'] = clientOrderId; params = this.omit (params, 'clientOrderId'); } - const stopPrice = this.safeFloat (params, 'stopPrice'); + const stopPrice = this.safeNumber (params, 'stopPrice'); if (stopPrice !== undefined) { request['stopPrice'] = this.priceToPrecision (symbol, stopPrice); params = this.omit (params, 'stopPrice'); @@ -1125,18 +1112,6 @@ module.exports = class gopax extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetCryptoDepositAddresses (params); @@ -1201,8 +1176,8 @@ module.exports = class gopax extends Exchange { } else if ((type === 'crypto_deposit' || type === 'fiat_deposit')) { type = 'deposit'; } - const amount = this.safeFloat (transaction, 'netAmount'); - const feeCost = this.safeFloat (transaction, 'feeAmount'); + const amount = this.safeNumber (transaction, 'netAmount'); + const feeCost = this.safeNumber (transaction, 'feeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hbtc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hbtc.js index d819c3d77..5dfd98ec5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hbtc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, OrderNotFound, ArgumentsRequired, BadSymbol, BadRequest, NullResponse, InvalidOrder, BadResponse, NotSupported, ExchangeNotAvailable, RequestTimeout, RateLimitExceeded, PermissionDenied, InsufficientFunds, InvalidAddress } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -304,23 +305,23 @@ module.exports = class hbtc extends Exchange { const filter = filters[j]; const filterType = this.safeString (filter, 'filterType'); if (filterType === 'LOT_SIZE') { - amountMin = this.safeFloat (filter, 'minQty'); - amountMax = this.safeFloat (filter, 'maxQty'); + amountMin = this.safeNumber (filter, 'minQty'); + amountMax = this.safeNumber (filter, 'maxQty'); } if (filterType === 'PRICE_FILTER') { - priceMin = this.safeFloat (filter, 'minPrice'); - priceMax = this.safeFloat (filter, 'maxPrice'); + priceMin = this.safeNumber (filter, 'minPrice'); + priceMax = this.safeNumber (filter, 'maxPrice'); } if (filterType === 'MIN_NOTIONAL') { - costMin = this.safeFloat (filter, 'minNotional'); + costMin = this.safeNumber (filter, 'minNotional'); } } if ((costMin === undefined) && (amountMin !== undefined) && (priceMin !== undefined)) { costMin = amountMin * priceMin; } const precision = { - 'price': this.safeFloat2 (market, 'quotePrecision', 'quoteAssetPrecision'), - 'amount': this.safeFloat (market, 'baseAssetPrecision'), + 'price': this.safeNumber2 (market, 'quotePrecision', 'quoteAssetPrecision'), + 'amount': this.safeNumber (market, 'baseAssetPrecision'), }; const limits = { 'amount': { @@ -558,14 +559,6 @@ module.exports = class hbtc extends Exchange { return this.parseTicker (response, market); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchBidAsk (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -717,8 +710,8 @@ module.exports = class hbtc extends Exchange { const currencyId = this.safeString2 (balance, 'asset', 'tokenName'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'free'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'free'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } } else { @@ -728,12 +721,12 @@ module.exports = class hbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = response[currencyId]; const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableMargin'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'availableMargin'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTrades (symbol, since = undefined, limit = 50, params = {}) { @@ -774,11 +767,11 @@ module.exports = class hbtc extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -1464,8 +1457,8 @@ module.exports = class hbtc extends Exchange { // const currencyId = this.safeString (item, 'tokenId'); const code = this.safeCurrencyCode (currencyId, currency); - const amount = this.safeFloat (item, 'change'); - const after = this.safeFloat (item, 'total'); + const amount = this.safeNumber (item, 'change'); + const after = this.safeNumber (item, 'total'); const direction = (amount < 0) ? 'out' : 'in'; let before = undefined; if (after !== undefined && amount !== undefined) { @@ -1605,8 +1598,8 @@ module.exports = class hbtc extends Exchange { } else { type = 'withdrawal'; } - const amount = this.safeFloat (transaction, 'quantity'); - const feeCost = this.safeFloat (transaction, 'fee'); + const amount = this.safeNumber (transaction, 'quantity'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'feeTokenId'); @@ -1667,8 +1660,8 @@ module.exports = class hbtc extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'openPrice'); - const close = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'openPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); let change = undefined; let percentage = undefined; let average = undefined; @@ -1679,19 +1672,19 @@ module.exports = class hbtc extends Exchange { percentage = (change / open) * 100; } } - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPrice'), - 'low': this.safeFloat (ticker, 'lowPrice'), - 'bid': this.safeFloat2 (ticker, 'bestBidPrice', 'bidPrice'), - 'bidVolume': this.safeFloat (ticker, 'bidQty'), - 'ask': this.safeFloat2 (ticker, 'bestAskPrice', 'askPrice'), - 'askVolume': this.safeFloat (ticker, 'askQty'), + 'high': this.safeNumber (ticker, 'highPrice'), + 'low': this.safeNumber (ticker, 'lowPrice'), + 'bid': this.safeNumber2 (ticker, 'bestBidPrice', 'bidPrice'), + 'bidVolume': this.safeNumber (ticker, 'bidQty'), + 'ask': this.safeNumber2 (ticker, 'bestAskPrice', 'askPrice'), + 'askVolume': this.safeNumber (ticker, 'askQty'), 'vwap': vwap, 'open': open, 'close': close, @@ -1741,17 +1734,14 @@ module.exports = class hbtc extends Exchange { // } // const id = this.safeString (trade, 'id'); - const timestamp = this.safeFloat (trade, 'time'); + const timestamp = this.safeNumber (trade, 'time'); const type = undefined; const orderId = this.safeString (trade, 'orderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'qty'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'qty'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let side = undefined; let takerOrMaker = undefined; if ('isBuyerMaker' in trade) { @@ -1765,7 +1755,7 @@ module.exports = class hbtc extends Exchange { side = isBuyer ? 'buy' : 'sell'; } let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionAsset'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1871,30 +1861,30 @@ module.exports = class hbtc extends Exchange { const symbol = this.safeSymbol (marketId, market); let type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); - let price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'avgPrice'); + let price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'avgPrice'); let amount = undefined; - let cost = this.safeFloat (order, 'cummulativeQuoteQty'); + let cost = this.safeNumber (order, 'cummulativeQuoteQty'); let filled = undefined; let remaining = undefined; if (type === undefined) { type = this.safeStringLower (order, 'orderType'); if ((market !== undefined) && market['inverse']) { - cost = this.safeFloat (order, 'executedQty'); + cost = this.safeNumber (order, 'executedQty'); amount = undefined; } if (cost === 0.0) { filled = 0; } } else { - amount = this.safeFloat (order, 'origQty'); + amount = this.safeNumber (order, 'origQty'); if (type === 'market') { price = undefined; if (side === 'buy') { amount = undefined; } } - filled = this.safeFloat (order, 'executedQty'); + filled = this.safeNumber (order, 'executedQty'); if (filled !== undefined) { if (amount !== undefined) { remaining = amount - filled; @@ -1906,7 +1896,7 @@ module.exports = class hbtc extends Exchange { } const status = this.parseOrderStatus (this.safeString (order, 'status')); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const result = { 'info': order, 'id': id, @@ -1935,7 +1925,7 @@ module.exports = class hbtc extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'fee'); + const feeCost = this.safeNumber (fees[i], 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'feeToken'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hitbtc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hitbtc.js index b66392816..b7fd38b04 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hitbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hitbtc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, PermissionDenied, ExchangeError, ExchangeNotAvailable, OrderNotFound, InsufficientFunds, InvalidOrder, RequestTimeout, AuthenticationError } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -44,6 +45,7 @@ module.exports = class hitbtc extends Exchange { 'fetchTransactions': true, 'fetchWithdrawals': false, 'withdraw': true, + 'transfer': true, }, 'timeframes': { '1m': 'M1', @@ -81,10 +83,10 @@ module.exports = class hitbtc extends Exchange { 'api': { 'public': { 'get': [ - 'symbol', // Available Currency Symbols - 'symbol/{symbol}', // Get symbol info 'currency', // Available Currencies 'currency/{currency}', // Get currency info + 'symbol', // Available Currency Symbols + 'symbol/{symbol}', // Get symbol info 'ticker', // Ticker list for all symbols 'ticker/{symbol}', // Ticker for symbol 'trades', @@ -102,11 +104,20 @@ module.exports = class hitbtc extends Exchange { 'order/{clientOrderId}', // Get a single order by clientOrderId 'trading/fee/all', // Get trading fee rate 'trading/fee/{symbol}', // Get trading fee rate + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', 'history/order', // Get historical orders 'history/trades', // Get historical trades 'history/order/{orderId}/trades', // Get historical trades by specified order 'account/balance', // Get main acccount balance - 'account/crypto/address/{currency}', // Get deposit crypro address + 'account/crypto/address/{currency}', // Get current address + 'account/crypto/addresses/{currency}', // Get last 10 deposit addresses for currency + 'account/crypto/used-addresses/{currency}', // Get last 10 unique addresses used for withdraw by currency + 'account/crypto/estimate-withdraw', 'account/crypto/is-mine/{address}', 'account/transactions', // Get account transactions 'account/transactions/{id}', // Get account transaction by id @@ -117,23 +128,33 @@ module.exports = class hitbtc extends Exchange { ], 'post': [ 'order', // Create new order - 'account/crypto/address/{currency}', // Create new deposit crypro address - 'account/crypto/withdraw', // Withdraw crypro + 'margin/order', + 'account/crypto/address/{currency}', // Create new crypto deposit address + 'account/crypto/withdraw', // Withdraw crypto 'account/crypto/transfer-convert', - 'account/transfer', // Transfer amount to trading + 'account/transfer', // Transfer amount to trading account or to main account + 'account/transfer/internal', 'sub-acc/freeze', 'sub-acc/activate', 'sub-acc/transfer', ], 'put': [ 'order/{clientOrderId}', // Create new order - 'account/crypto/withdraw/{id}', // Commit withdraw crypro + 'margin/account/{symbol}', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Commit crypto withdrawal 'sub-acc/acl/{subAccountUserId}', ], 'delete': [ 'order', // Cancel all open orders 'order/{clientOrderId}', // Cancel order - 'account/crypto/withdraw/{id}', // Rollback withdraw crypro + 'margin/account', + 'margin/account/{symbol}', + 'margin/position', + 'margin/position/{symbol}', + 'margin/order', + 'margin/order/{clientOrderId}', + 'account/crypto/withdraw/{id}', // Rollback crypto withdrawal ], // outdated? 'patch': [ @@ -152,8 +173,20 @@ module.exports = class hitbtc extends Exchange { }, 'options': { 'defaultTimeInForce': 'FOK', + 'accountsByType': { + 'bank': 'bank', + 'exchange': 'exchange', + 'main': 'bank', // alias of the above + 'trading': 'exchange', + }, + 'fetchBalanceMethod': { + 'account': 'account', + 'main': 'account', + 'trading': 'trading', + }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BCC': 'BCC', // initial symbol for Bitcoin Cash, now inactive 'BET': 'DAO.Casino', 'BOX': 'BOX Token', @@ -180,7 +213,6 @@ module.exports = class hitbtc extends Exchange { '20002': OrderNotFound, // canceling non-existent order '20001': InsufficientFunds, // {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}} }, - 'orders': {}, // orders cache / emulation }); } @@ -217,14 +249,14 @@ module.exports = class hitbtc extends Exchange { if (id.indexOf ('_') >= 0) { symbol = id; } - const lot = this.safeFloat (market, 'quantityIncrement'); - const step = this.safeFloat (market, 'tickSize'); + const lot = this.safeNumber (market, 'quantityIncrement'); + const step = this.safeNumber (market, 'tickSize'); const precision = { 'price': step, 'amount': lot, }; - const taker = this.safeFloat (market, 'takeLiquidityRate'); - const maker = this.safeFloat (market, 'provideLiquidityRate'); + const taker = this.safeNumber (market, 'takeLiquidityRate'); + const maker = this.safeNumber (market, 'provideLiquidityRate'); const feeCurrencyId = this.safeString (market, 'feeCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); result.push (this.extend (this.fees['trading'], { @@ -259,6 +291,49 @@ module.exports = class hitbtc extends Exchange { return result; } + async transfer (code, amount, fromAccount, toAccount, params = {}) { + // account can be "exchange" or "bank", with aliases "main" or "trading" respectively + await this.loadMarkets (); + const currency = this.currency (code); + const requestAmount = this.currencyToPrecision (code, amount); + const request = { + 'currency': currency['id'], + 'amount': requestAmount, + }; + let type = this.safeString (params, 'type'); + if (type === undefined) { + const accountsByType = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsByType, fromAccount); + const toId = this.safeString (accountsByType, toAccount); + const keys = Object.keys (accountsByType); + if (fromId === undefined) { + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ') + ' instead of ' + fromId); + } + if (toId === undefined) { + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ') + ' instead of ' + toId); + } + if (fromId === toId) { + throw new ExchangeError (this.id + ' from and to cannot be the same account'); + } + type = fromId + 'To' + this.capitalize (toId); + } + request['type'] = type; + const response = await this.privatePostAccountTransfer (this.extend (request, params)); + // { id: '2db6ebab-fb26-4537-9ef8-1a689472d236' } + const id = this.safeString (response, 'id'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'amount': requestAmount, + 'currency': code, + 'fromAccount': fromAccount, + 'toAccount': toAccount, + 'status': undefined, + }; + } + async fetchCurrencies (params = {}) { const response = await this.publicGetCurrency (params); // @@ -314,7 +389,7 @@ module.exports = class hitbtc extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (currency, 'payoutFee'), // todo: redesign + 'fee': this.safeNumber (currency, 'payoutFee'), // todo: redesign 'precision': precision, 'limits': { 'amount': { @@ -354,15 +429,20 @@ module.exports = class hitbtc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } async fetchBalance (params = {}) { await this.loadMarkets (); const type = this.safeString (params, 'type', 'trading'); - const method = 'privateGet' + this.capitalize (type) + 'Balance'; + const fetchBalanceAccounts = this.safeValue (this.options, 'fetchBalanceMethod', {}); + const typeId = this.safeString (fetchBalanceAccounts, type); + if (typeId === undefined) { + throw new ExchangeError (this.id + ' fetchBalance account type must be either main or trading'); + } + const method = 'privateGet' + this.capitalize (typeId) + 'Balance'; const query = this.omit (params, 'type'); const response = await this[method] (query); const result = { 'info': response }; @@ -371,11 +451,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'reserved'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -392,11 +472,11 @@ module.exports = class hitbtc extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'max'), - this.safeFloat (ohlcv, 'min'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'max'), + this.safeNumber (ohlcv, 'min'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -442,10 +522,10 @@ module.exports = class hitbtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const baseVolume = this.safeFloat (ticker, 'volume'); - const quoteVolume = this.safeFloat (ticker, 'volumeQuote'); - const open = this.safeFloat (ticker, 'open'); - const last = this.safeFloat (ticker, 'last'); + const baseVolume = this.safeNumber (ticker, 'volume'); + const quoteVolume = this.safeNumber (ticker, 'volumeQuote'); + const open = this.safeNumber (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); let change = undefined; let percentage = undefined; let average = undefined; @@ -461,11 +541,11 @@ module.exports = class hitbtc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -541,7 +621,7 @@ module.exports = class hitbtc extends Exchange { market = this.safeMarket (marketId, market); const symbol = market['symbol']; let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyCode = market ? market['feeCurrency'] : undefined; fee = { @@ -553,9 +633,11 @@ module.exports = class hitbtc extends Exchange { // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const orderId = this.safeString (trade, 'clientOrderId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = price * amount; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); const id = this.safeString (trade, 'id'); return { @@ -654,11 +736,11 @@ module.exports = class hitbtc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const txid = this.safeString (transaction, 'hash'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -846,66 +928,25 @@ module.exports = class hitbtc extends Exchange { const marketId = this.safeString (order, 'symbol'); market = this.safeMarket (marketId, market); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'cumQuantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'cumQuantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); // we use clientOrderId as the order id with this exchange intentionally // because most of their endpoints will require clientOrderId // explained here: https://github.com/ccxt/ccxt/issues/5674 const id = this.safeString (order, 'clientOrderId'); const clientOrderId = id; - let price = this.safeFloat (order, 'price'); - let remaining = undefined; - let cost = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - if (price !== undefined) { - cost = filled * price; - } - } - } + const price = this.safeNumber (order, 'price'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); let trades = this.safeValue (order, 'tradesReport'); - let fee = undefined; - let average = this.safeValue (order, 'avgPrice'); + const fee = undefined; + const average = this.safeNumber (order, 'avgPrice'); if (trades !== undefined) { trades = this.parseTrades (trades, market); - let feeCost = undefined; - const numTrades = trades.length; - let tradesCost = 0; - for (let i = 0; i < numTrades; i++) { - if (feeCost === undefined) { - feeCost = 0; - } - tradesCost = this.sum (tradesCost, trades[i]['cost']); - const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); - if (tradeFeeCost !== undefined) { - feeCost = this.sum (feeCost, tradeFeeCost); - } - } - cost = tradesCost; - if ((filled !== undefined) && (filled > 0)) { - if (average === undefined) { - average = cost / filled; - } - if (type === 'market') { - if (price === undefined) { - price = average; - } - } - } - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } } const timeInForce = this.safeString (order, 'timeInForce'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, // https://github.com/ccxt/ccxt/issues/5674 'timestamp': created, @@ -920,13 +961,13 @@ module.exports = class hitbtc extends Exchange { 'stopPrice': undefined, 'average': average, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hollaex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hollaex.js index 52e81fec3..bde50ed15 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hollaex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/hollaex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadRequest, AuthenticationError, NetworkError, ArgumentsRequired, OrderNotFound, InsufficientFunds } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -15,7 +16,7 @@ module.exports = class hollaex extends Exchange { 'name': 'HollaEx', 'countries': [ 'KR' ], 'rateLimit': 333, - 'version': 'v1', + 'version': 'v2', 'has': { 'CORS': false, 'fetchMarkets': true, @@ -35,13 +36,13 @@ module.exports = class hollaex extends Exchange { 'cancelOrder': true, 'cancelAllOrders': true, 'fetchOpenOrders': true, - 'fetchClosedOrders': false, + 'fetchClosedOrders': true, 'fetchOpenOrder': true, 'fetchOrder': false, 'fetchDeposits': true, 'fetchWithdrawals': true, 'fetchTransactions': false, - 'fetchOrders': false, + 'fetchOrders': true, 'fetchMyTrades': true, 'withdraw': true, 'fetchDepositAddress': true, @@ -66,13 +67,17 @@ module.exports = class hollaex extends Exchange { 'public': { 'get': [ 'health', - 'constant', + 'constants', + 'kit', + 'tiers', 'ticker', - 'ticker/all', + 'tickers', + 'orderbook', 'orderbooks', 'trades', 'chart', - // TradingView data + 'charts', + // TradingView 'udf/config', 'udf/history', 'udf/symbols', @@ -82,20 +87,20 @@ module.exports = class hollaex extends Exchange { 'get': [ 'user', 'user/balance', - 'user/trades', - 'user/orders', - 'user/orders/{order_id}', 'user/deposits', 'user/withdrawals', - 'user/withdraw/{currency}/fee', + 'user/withdrawal/fee', + 'user/trades', + 'orders', + 'orders/{order_id}', ], 'post': [ 'user/request-withdrawal', 'order', ], 'delete': [ - 'user/orders', - 'user/orders/{order_id}', + 'order/all', + 'order', ], }, }, @@ -130,7 +135,7 @@ module.exports = class hollaex extends Exchange { } async fetchMarkets (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); // // { // coins: { @@ -197,17 +202,17 @@ module.exports = class hollaex extends Exchange { 'quoteId': quoteId, 'active': active, 'precision': { - 'price': this.safeFloat (market, 'increment_price'), - 'amount': this.safeFloat (market, 'increment_size'), + 'price': this.safeNumber (market, 'increment_price'), + 'amount': this.safeNumber (market, 'increment_size'), }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_size'), - 'max': this.safeFloat (market, 'max_size'), + 'min': this.safeNumber (market, 'min_size'), + 'max': this.safeNumber (market, 'max_size'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, 'max': undefined }, }, @@ -218,7 +223,7 @@ module.exports = class hollaex extends Exchange { } async fetchCurrencies (params = {}) { - const response = await this.publicGetConstant (params); + const response = await this.publicGetConstants (params); const coins = this.safeValue (response, 'coins', {}); const keys = Object.keys (coins); const result = {}; @@ -230,8 +235,8 @@ module.exports = class hollaex extends Exchange { const code = this.safeCurrencyCode (id); const name = this.safeString (currency, 'fullname'); const active = this.safeValue (currency, 'active'); - const fee = this.safeFloat (currency, 'withdrawal_fee'); - const precision = this.safeFloat (currency, 'increment_unit'); + const fee = this.safeNumber (currency, 'withdrawal_fee'); + const precision = this.safeNumber (currency, 'increment_unit'); const withdrawalLimits = this.safeValue (currency, 'withdrawal_limits', []); result[code] = { 'id': id, @@ -244,8 +249,8 @@ module.exports = class hollaex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'min'), - 'max': this.safeFloat (currency, 'max'), + 'min': this.safeNumber (currency, 'min'), + 'max': this.safeNumber (currency, 'max'), }, 'price': { 'min': undefined, @@ -334,7 +339,7 @@ module.exports = class hollaex extends Exchange { async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); - const response = await this.publicGetTickerAll (this.extend (params)); + const response = await this.publicGetTickers (this.extend (params)); // // { // "bch-usdt": { @@ -397,27 +402,27 @@ module.exports = class hollaex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString2 (ticker, 'time', 'timestamp')); - const close = this.safeFloat (ticker, 'close'); + const close = this.safeNumber (ticker, 'close'); const result = { 'symbol': symbol, 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': close, - 'last': this.safeFloat (ticker, 'last', close), + 'last': this.safeNumber (ticker, 'last', close), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, }; return result; @@ -475,15 +480,12 @@ module.exports = class hollaex extends Exchange { const datetime = this.safeString (trade, 'timestamp'); const timestamp = this.parse8601 (datetime); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'size'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'size'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const quote = market['quote']; @@ -568,11 +570,11 @@ module.exports = class hollaex extends Exchange { // return [ this.parse8601 (this.safeString (response, 'time')), - this.safeFloat (response, 'open'), - this.safeFloat (response, 'high'), - this.safeFloat (response, 'low'), - this.safeFloat (response, 'close'), - this.safeFloat (response, 'volume'), + this.safeNumber (response, 'open'), + this.safeNumber (response, 'high'), + this.safeNumber (response, 'low'), + this.safeNumber (response, 'close'), + this.safeNumber (response, 'volume'), ]; } @@ -597,11 +599,11 @@ module.exports = class hollaex extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (response, currencyId + '_available'); - account['total'] = this.safeFloat (response, currencyId + '_balance'); + account['free'] = this.safeString (response, currencyId + '_available'); + account['total'] = this.safeString (response, currencyId + '_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOpenOrder (id, symbol = undefined, params = {}) { @@ -609,67 +611,146 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateGetUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateGetOrdersOrderId (this.extend (request, params)); // // { - // "created_at": "2018-03-23T04:14:08.663Z", - // "title": "string", - // "side": "sell", - // "type": "limit", - // "price": 0, - // "size": 0, - // "symbol": "xht-usdt", // "id": "string", - // "created_by": 1, - // "filled": 0 + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } // } // return this.parseOrder (response); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'open': true, + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + const request = { + 'status': 'filled', + }; + return await this.fetchOrders (symbol, since, limit, this.extend (request, params)); + } + + async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); let market = undefined; - const request = {}; + const request = { + // 'symbol': market['id'], + // 'side': 'buy', // 'sell' + // 'status': 'new', // 'filled', 'pfilled', 'canceled' + // 'open': true, + // 'limit': limit, // default 50, max 100 + // 'page': 1, + // 'order_by': 'created_at', // id, ... + // 'order': 'asc', // 'desc' + // 'start_date': this.iso8601 (since), + // 'end_date': this.iso8601 (this.milliseconds ()), + }; if (symbol !== undefined) { market = this.market (symbol); request['symbol'] = market['id']; } - const response = await this.privateGetUserOrders (this.extend (request, params)); + if (since !== undefined) { + request['start_date'] = this.iso8601 (since); + } + if (limit !== undefined) { + request['limit'] = limit; // default 50, max 100 + } + const response = await this.privateGetOrders (this.extend (request, params)); // - // [ - // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 - // } - // ] + // { + // "count": 1, + // "data": [ + // { + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // } + // } + // ] + // } // - return this.parseOrders (response, market); + const data = this.safeValue (response, 'data', []); + return this.parseOrders (data, market, since, limit); + } + + parseOrderStatus (status) { + const statuses = { + 'new': 'open', + 'pfilled': 'open', + 'filled': 'closed', + 'canceled': 'canceled', + }; + return this.safeString (statuses, status, status); } parseOrder (order, market = undefined) { // - // fetchOpenOrder, fetchOpenOrders + // createOrder, fetchOpenOrder, fetchOpenOrders // // { - // "created_at":"2020-03-03T08:02:18.639Z", - // "title":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "side":"buy", - // "type":"limit", - // "price":226.19, - // "size":0.086, - // "symbol":"eth-usdt", - // "id":"5419ff3f-9d25-4af7-bcc2-803926518d76", - // "created_by":620, - // "filled":0 + // "id": "string", + // "side": "sell", + // "symbol": "xht-usdt", + // "size": 0.1, + // "filled": 0, + // "stop": null, + // "fee": 0, + // "fee_coin": "usdt", + // "type": "limit", + // "price": 1.09, + // "status": "new", + // "created_by": 116, + // "created_at": "2021-02-17T02:32:38.910Z", + // "updated_at": "2021-02-17T02:32:38.910Z", + // "User": { + // "id": 116, + // "email": "fight@club.com", + // "username": "narrator", + // "exchange_id": 176 + // }, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, // } // const marketId = this.safeString (order, 'symbol'); @@ -678,21 +759,11 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'filled'); - let cost = undefined; - let remaining = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (price !== undefined) { - cost = filled * price; - } - } - const status = (type === 'market') ? 'closed' : 'open'; - const result = { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'filled'); + const status = this.parseOrderStatus (this.safeString (order, 'status')); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -708,40 +779,56 @@ module.exports = class hollaex extends Exchange { 'stopPrice': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, - 'cost': cost, + 'remaining': undefined, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': undefined, - }; - return result; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); - const order = { + const request = { 'symbol': market['id'], 'side': side, 'size': amount, 'type': type, + // 'stop': parseFloat (this.priceToPrecision (symbol, stopPrice)), + // 'meta': {}, // other options such as post_only }; if (type !== 'market') { - order['price'] = price; + request['price'] = price; } - const response = await this.privatePostOrder (this.extend (order, params)); + const stopPrice = this.safeFloat2 (params, 'stopPrice', 'stop'); + if (stopPrice !== undefined) { + request['stop'] = parseFloat (this.priceToPrecision (symbol, stopPrice)); + params = this.omit (params, [ 'stopPrice', 'stop' ]); + } + const response = await this.privatePostOrder (this.extend (request, params)); // // { + // "fee": 0, + // "meta": {}, // "symbol": "xht-usdt", // "side": "sell", - // "size": 1, + // "size": 0.1, // "type": "limit", - // "price": 0.1, + // "price": 1, + // "fee_structure": { + // "maker": 0.2, + // "taker": 0.2 + // }, + // "fee_coin": "usdt", // "id": "string", - // "created_by": 34, + // "created_by": 116, // "filled": 0, - // "status": "pending" + // "status": "new", + // "updated_at": "2021-02-17T03:03:19.231Z", + // "created_at": "2021-02-17T03:03:19.231Z", + // "stop": null // } // return this.parseOrder (response, market); @@ -752,7 +839,7 @@ module.exports = class hollaex extends Exchange { const request = { 'order_id': id, }; - const response = await this.privateDeleteUserOrdersOrderId (this.extend (request, params)); + const response = await this.privateDeleteOrder (this.extend (request, params)); // // { // "title": "string", @@ -777,7 +864,7 @@ module.exports = class hollaex extends Exchange { market = this.markets (symbol); request['symbol'] = market['id']; } - const response = await this.privateDeleteUserOrders (this.extend (request, params)); + const response = await this.privateDeleteOrderAll (this.extend (request, params)); // // [ // { @@ -1043,7 +1130,7 @@ module.exports = class hollaex extends Exchange { const timestamp = this.parse8601 (this.safeString (transaction, 'created_at')); const updated = this.parse8601 (this.safeString (transaction, 'updated_at')); const type = this.safeString (transaction, 'type'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let address = this.safeString (transaction, 'address'); let addressTo = undefined; const addressFrom = undefined; @@ -1073,7 +1160,7 @@ module.exports = class hollaex extends Exchange { } const fee = { 'currency': code, - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), }; return { 'info': transaction, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/huobipro.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/huobipro.js index 52dc315e8..22c1d91d5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/huobipro.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/huobipro.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, ArgumentsRequired, BadSymbol, BadRequest, RequestTimeout, NetworkError } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -22,7 +23,9 @@ module.exports = class huobipro extends Exchange { 'hostname': 'api.huobi.pro', // api.testnet.huobi.pro 'pro': true, 'has': { + 'cancelAllOrders': true, 'cancelOrder': true, + 'cancelOrders': true, 'CORS': false, 'createOrder': true, 'fetchBalance': true, @@ -189,6 +192,7 @@ module.exports = class huobipro extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.002, @@ -252,6 +256,7 @@ module.exports = class huobipro extends Exchange { // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/ 'PNT': 'Penta', 'SBTC': 'Super Bitcoin', + 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706 }, }); } @@ -316,8 +321,8 @@ module.exports = class huobipro extends Exchange { 'info': limits, 'limits': { 'amount': { - 'min': this.safeFloat (limits, 'limit-order-must-greater-than'), - 'max': this.safeFloat (limits, 'limit-order-must-less-than'), + 'min': this.safeNumber (limits, 'limit-order-must-greater-than'), + 'max': this.safeNumber (limits, 'limit-order-must-less-than'), }, }, }; @@ -351,9 +356,9 @@ module.exports = class huobipro extends Exchange { }; const maker = (base === 'OMG') ? 0 : 0.2 / 100; const taker = (base === 'OMG') ? 0 : 0.2 / 100; - const minAmount = this.safeFloat (market, 'min-order-amt', Math.pow (10, -precision['amount'])); - const maxAmount = this.safeFloat (market, 'max-order-amt'); - const minCost = this.safeFloat (market, 'min-order-value', 0); + const minAmount = this.safeNumber (market, 'min-order-amt', Math.pow (10, -precision['amount'])); + const maxAmount = this.safeNumber (market, 'max-order-amt'); + const minCost = this.safeNumber (market, 'min-order-value', 0); const state = this.safeString (market, 'state'); const active = (state === 'online'); result.push ({ @@ -432,24 +437,24 @@ module.exports = class huobipro extends Exchange { let askVolume = undefined; if ('bid' in ticker) { if (Array.isArray (ticker['bid'])) { - bid = this.safeFloat (ticker['bid'], 0); - bidVolume = this.safeFloat (ticker['bid'], 1); + bid = this.safeNumber (ticker['bid'], 0); + bidVolume = this.safeNumber (ticker['bid'], 1); } else { - bid = this.safeFloat (ticker, 'bid'); + bid = this.safeNumber (ticker, 'bid'); bidVolume = this.safeValue (ticker, 'bidSize'); } } if ('ask' in ticker) { if (Array.isArray (ticker['ask'])) { - ask = this.safeFloat (ticker['ask'], 0); - askVolume = this.safeFloat (ticker['ask'], 1); + ask = this.safeNumber (ticker['ask'], 0); + askVolume = this.safeNumber (ticker['ask'], 1); } else { - ask = this.safeFloat (ticker, 'ask'); + ask = this.safeNumber (ticker, 'ask'); askVolume = this.safeValue (ticker, 'askSize'); } } - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; let percentage = undefined; let average = undefined; @@ -460,15 +465,15 @@ module.exports = class huobipro extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'amount'); - const quoteVolume = this.safeFloat (ticker, 'vol'); + const baseVolume = this.safeNumber (ticker, 'amount'); + const quoteVolume = this.safeNumber (ticker, 'vol'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': bid, 'bidVolume': bidVolume, 'ask': ask, @@ -557,7 +562,7 @@ module.exports = class huobipro extends Exchange { // } // const ticker = this.parseTicker (response['tick'], market); - const timestamp = this.safeValue (response, 'ts'); + const timestamp = this.safeInteger (response, 'ts'); ticker['timestamp'] = timestamp; ticker['datetime'] = this.iso8601 (timestamp); return ticker; @@ -626,21 +631,18 @@ module.exports = class huobipro extends Exchange { type = typeParts[1]; } const takerOrMaker = this.safeString (trade, 'role'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'filled-amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'filled-amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - let feeCost = this.safeFloat (trade, 'filled-fees'); + let feeCost = this.safeNumber (trade, 'filled-fees'); let feeCurrency = undefined; if (market !== undefined) { feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-currency')); } - const filledPoints = this.safeFloat (trade, 'filled-points'); + const filledPoints = this.safeNumber (trade, 'filled-points'); if (filledPoints !== undefined) { if ((feeCost === undefined) || (feeCost === 0.0)) { feeCost = filledPoints; @@ -754,11 +756,11 @@ module.exports = class huobipro extends Exchange { // return [ this.safeTimestamp (ohlcv, 'id'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'amount'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'amount'), ]; } @@ -855,11 +857,11 @@ module.exports = class huobipro extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'deposit-min-amount'), + 'min': this.safeNumber (currency, 'deposit-min-amount'), 'max': Math.pow (10, precision), }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdraw-min-amount'), + 'min': this.safeNumber (currency, 'withdraw-min-amount'), 'max': Math.pow (10, precision), }, }, @@ -890,14 +892,14 @@ module.exports = class huobipro extends Exchange { account = this.account (); } if (balance['type'] === 'trade') { - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); } if (balance['type'] === 'frozen') { - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); } result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrdersByStates (states, symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1072,28 +1074,14 @@ module.exports = class huobipro extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeInteger (order, 'created-at'); - let amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount - if ((type === 'market') && (side === 'buy')) { - amount = (status === 'closed') ? filled : undefined; - } - let price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount + let price = this.safeNumber (order, 'price'); if (price === 0.0) { price = undefined; } - const cost = this.safeFloat2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - // if cost is defined and filled is not zero - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - const feeCost = this.safeFloat2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees + const cost = this.safeNumber2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo + const feeCost = this.safeNumber2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -1105,7 +1093,7 @@ module.exports = class huobipro extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -1119,15 +1107,15 @@ module.exports = class huobipro extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1201,26 +1189,82 @@ module.exports = class huobipro extends Exchange { }); } - currencyToPrecision (currency, fee) { - return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); + async cancelOrders (ids, symbol = undefined, params = {}) { + await this.loadMarkets (); + const clientOrderIds = this.safeValue2 (params, 'clientOrderIds', 'client-order-ids'); + params = this.omit (params, [ 'clientOrderIds', 'client-order-ids' ]); + const request = {}; + if (clientOrderIds === undefined) { + request['order-ids'] = ids; + } else { + request['client-order-ids'] = clientOrderIds; + } + const response = await this.privatePostOrderOrdersBatchcancel (this.extend (request, params)); + // + // { + // "status": "ok", + // "data": { + // "success": [ + // "5983466" + // ], + // "failed": [ + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "first" + // }, + // { + // "err-msg": "Incorrect order state", + // "order-state": 7, + // "order-id": "", + // "err-code": "order-orderstate-error", + // "client-order-id": "second" + // }, + // { + // "err-msg": "The record is not found.", + // "order-id": "", + // "err-code": "base-not-found", + // "client-order-id": "third" + // } + // ] + // } + // } + // + return response; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let key = 'quote'; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.currencyToPrecision (market[key], cost)), + async cancelAllOrders (symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts + // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default + // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok + // 'side': 'buy', // or 'sell' + // 'size': 100, // the number of orders to cancel 1-100 }; + let market = undefined; + if (symbol !== undefined) { + market = this.market (symbol); + request['symbol'] = market['id']; + } + const response = await this.privatePostOrderOrdersBatchCancelOpenOrders (this.extend (request, params)); + // + // { + // code: 200, + // data: { + // "success-count": 2, + // "failed-count": 0, + // "next-id": 5454600 + // } + // } + // + return response; + } + + currencyToPrecision (currency, fee) { + return this.decimalToPrecision (fee, 0, this.currencies[currency]['precision']); } parseDepositAddress (depositAddress, currency = undefined) { @@ -1362,7 +1406,7 @@ module.exports = class huobipro extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); const tag = this.safeString (transaction, 'address-tag'); - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { feeCost = Math.abs (feeCost); } @@ -1375,7 +1419,7 @@ module.exports = class huobipro extends Exchange { 'address': this.safeString (transaction, 'address'), 'tag': tag, 'type': type, - 'amount': this.safeFloat (transaction, 'amount'), + 'amount': this.safeNumber (transaction, 'amount'), 'currency': code, 'status': status, 'updated': updated, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ice3x.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ice3x.js deleted file mode 100644 index f228076d1..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ice3x.js +++ /dev/null @@ -1,495 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); -const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); - -// --------------------------------------------------------------------------- - -module.exports = class ice3x extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'ice3x', - 'name': 'ICE3X', - 'countries': [ 'ZA' ], // South Africa - 'rateLimit': 1000, - 'version': 'v1', - 'has': { - 'cancelOrder': true, - 'createOrder': true, - 'fetchBalance': true, - 'fetchCurrencies': true, - 'fetchDepositAddress': true, - 'fetchMarkets': true, - 'fetchMyTrades': true, - 'fetchOpenOrders': true, - 'fetchOrder': true, - 'fetchOrderBook': true, - 'fetchTicker': true, - 'fetchTickers': true, - 'fetchTrades': true, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/51840849/87460809-1dd06c00-c616-11ea-98ad-7d5e1cb7fcdd.jpg', - 'api': 'https://ice3x.com/api', - 'www': 'https://ice3x.com', // 'https://ice3x.co.za', - 'doc': 'https://ice3x.co.za/ice-cubed-bitcoin-exchange-api-documentation-1-june-2017', - 'fees': [ - 'https://help.ice3.com/support/solutions/articles/11000033293-trading-fees', - 'https://help.ice3.com/support/solutions/articles/11000033288-fees-explained', - 'https://help.ice3.com/support/solutions/articles/11000008131-what-are-your-fiat-deposit-and-withdrawal-fees-', - 'https://help.ice3.com/support/solutions/articles/11000033289-deposit-fees', - ], - 'referral': 'https://ice3x.com?ref=14341802', - }, - 'api': { - 'public': { - 'get': [ - 'currency/list', - 'currency/info', - 'pair/list', - 'pair/info', - 'stats/marketdepthfull', - 'stats/marketdepthbtcav', - 'stats/marketdepth', - 'orderbook/info', - 'trade/list', - 'trade/info', - ], - }, - 'private': { - 'post': [ - 'balance/list', - 'balance/info', - 'order/new', - 'order/cancel', - 'order/list', - 'order/info', - 'trade/list', - 'trade/info', - 'transaction/list', - 'transaction/info', - 'invoice/list', - 'invoice/info', - 'invoice/pdf', - ], - }, - }, - 'fees': { - 'trading': { - 'maker': 0.005, - 'taker': 0.005, - }, - }, - 'precision': { - 'amount': 8, - 'price': 8, - }, - }); - } - - async fetchCurrencies (params = {}) { - const response = await this.publicGetCurrencyList (params); - const currencies = response['response']['entities']; - const precision = this.precision['amount']; - const result = {}; - for (let i = 0; i < currencies.length; i++) { - const currency = currencies[i]; - const id = this.safeString (currency, 'currency_id'); - const currencyId = this.safeString (currency, 'iso'); - const code = this.safeCurrencyCode (currencyId); - result[code] = { - 'id': id, - 'code': code, - 'name': currency['name'], - 'active': true, - 'precision': precision, - 'limits': { - 'amount': { - 'min': undefined, - 'max': Math.pow (10, precision), - }, - 'price': { - 'min': Math.pow (10, -precision), - 'max': Math.pow (10, precision), - }, - 'cost': { - 'min': undefined, - 'max': undefined, - }, - }, - 'info': currency, - 'fee': undefined, - }; - } - return result; - } - - async fetchMarkets (params = {}) { - if (this.currencies_by_id === undefined) { - this.currencies = await this.fetchCurrencies (); - this.currencies_by_id = this.indexBy (this.currencies, 'id'); - } - const response = await this.publicGetPairList (params); - const markets = this.safeValue (response['response'], 'entities'); - const result = []; - for (let i = 0; i < markets.length; i++) { - const market = markets[i]; - const id = this.safeString (market, 'pair_id'); - const baseId = this.safeString (market, 'currency_id_from'); - const quoteId = this.safeString (market, 'currency_id_to'); - const baseCurrency = this.currencies_by_id[baseId]; - const quoteCurrency = this.currencies_by_id[quoteId]; - const base = baseCurrency['code']; - const quote = quoteCurrency['code']; - const symbol = base + '/' + quote; - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'active': undefined, - 'info': market, - 'precision': this.precision, - 'limits': this.limits, - }); - } - return result; - } - - parseTicker (ticker, market = undefined) { - const timestamp = this.milliseconds (); - const symbol = market['symbol']; - const last = this.safeFloat (ticker, 'last_price'); - return { - 'symbol': symbol, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max'), - 'low': this.safeFloat (ticker, 'min'), - 'bid': this.safeFloat (ticker, 'max_bid'), - 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'min_ask'), - 'askVolume': undefined, - 'vwap': undefined, - 'open': undefined, - 'close': last, - 'last': last, - 'previousClose': undefined, - 'change': undefined, - 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'vol'), - 'info': ticker, - }; - } - - async fetchTicker (symbol, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetStatsMarketdepthfull (this.extend (request, params)); - const ticker = this.safeValue (response['response'], 'entity'); - return this.parseTicker (ticker, market); - } - - async fetchTickers (symbols = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetStatsMarketdepthfull (params); - const tickers = this.safeValue (response['response'], 'entities'); - const result = {}; - for (let i = 0; i < tickers.length; i++) { - const ticker = tickers[i]; - const marketId = this.safeString (ticker, 'pair_id'); - const market = this.safeValue (this.marketsById, marketId); - if (market !== undefined) { - const symbol = market['symbol']; - result[symbol] = this.parseTicker (ticker, market); - } - } - return this.filterByArray (result, 'symbol', symbols); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'pair_id': this.marketId (symbol), - }; - if (limit !== undefined) { - const type = this.safeString (params, 'type'); - if ((type !== 'ask') && (type !== 'bid')) { - // eslint-disable-next-line quotes - throw new ArgumentsRequired (this.id + " fetchOrderBook() requires an exchange-specific extra 'type' param ('bid' or 'ask') when used with a limit"); - } else { - request['items_per_page'] = limit; - } - } - const response = await this.publicGetOrderbookInfo (this.extend (request, params)); - const orderbook = this.safeValue (response['response'], 'entities'); - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.safeTimestamp (trade, 'created'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - 'currency': market['quote'], - }; - } - const type = 'limit'; - const side = this.safeString (trade, 'type'); - const id = this.safeString (trade, 'trade_id'); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - return { - 'id': id, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': type, - 'side': side, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': fee, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - const response = await this.publicGetTradeList (this.extend (request, params)); - const trades = this.safeValue (response['response'], 'entities'); - return this.parseTrades (trades, market, since, limit); - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privatePostBalanceList (params); - const result = { 'info': response }; - const balances = this.safeValue (response['response'], 'entities', []); - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - // currency ids are numeric strings - const currencyId = this.safeString (balance, 'currency_id'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - result[code] = account; - } - return this.parseBalance (result); - } - - parseOrder (order, market = undefined) { - const pairId = this.safeInteger (order, 'pair_id'); - let symbol = undefined; - if (pairId && !market && (pairId in this.marketsById)) { - market = this.marketsById[pairId]; - symbol = market['symbol']; - } - const timestamp = this.safeTimestamp (order, 'created'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - let status = this.safeInteger (order, 'active'); - let remaining = this.safeFloat (order, 'remaining'); - let filled = undefined; - if (status === 1) { - status = 'open'; - } else { - status = 'closed'; - remaining = 0; - filled = amount; - } - let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); - if (feeCost !== undefined) { - fee = { - 'cost': feeCost, - }; - if (market !== undefined) { - fee['currency'] = market['quote']; - } - } - return { - 'id': this.safeString (order, 'order_id'), - 'clientOrderId': undefined, - 'datetime': this.iso8601 (timestamp), - 'timestamp': timestamp, - 'lastTradeTimestamp': undefined, - 'status': status, - 'symbol': symbol, - 'type': 'limit', - 'timeInForce': undefined, - 'postOnly': undefined, - 'side': this.safeString (order, 'type'), - 'price': price, - 'stopPrice': undefined, - 'cost': undefined, - 'amount': amount, - 'filled': filled, - 'remaining': remaining, - 'trades': undefined, - 'fee': fee, - 'info': order, - 'average': undefined, - }; - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - 'type': side, - 'amount': amount, - 'price': price, - }; - const response = await this.privatePostOrderNew (this.extend (request, params)); - const order = this.parseOrder ({ - 'order_id': response['response']['entity']['order_id'], - 'created': this.seconds (), - 'active': 1, - 'type': side, - 'price': price, - 'volume': amount, - 'remaining': amount, - 'info': response, - }, market); - return order; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - const request = { - 'order_id': id, - }; - return await this.privatePostOrderCancel (this.extend (request, params)); - } - - async fetchOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'order _id': id, - }; - const response = await this.privatePostOrderInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const order = this.safeValue (data, 'entity'); - return this.parseOrder (order); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.privatePostOrderList (params); - const data = this.safeValue (response, 'response', {}); - const orders = this.safeValue (data, 'entities', []); - let market = undefined; - if (symbol !== undefined) { - market = this.market (symbol); - } - return this.parseOrders (orders, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'pair_id': market['id'], - }; - if (limit !== undefined) { - request['items_per_page'] = limit; - } - if (since !== undefined) { - request['date_from'] = parseInt (since / 1000); - } - const response = await this.privatePostTradeList (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const trades = this.safeValue (data, 'entities', []); - return this.parseTrades (trades, market, since, limit); - } - - async fetchDepositAddress (code, params = {}) { - await this.loadMarkets (); - const currency = this.currency (code); - const request = { - 'currency_id': currency['id'], - }; - const response = await this.privatePostBalanceInfo (this.extend (request, params)); - const data = this.safeValue (response, 'response', {}); - const balance = this.safeValue (data, 'entity', {}); - const address = this.safeString (balance, 'address'); - const status = address ? 'ok' : 'none'; - return { - 'currency': code, - 'address': address, - 'tag': undefined, - 'status': status, - 'info': response, - }; - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/' + this.version + '/' + path; - if (api === 'public') { - if (Object.keys (params).length) { - url += '?' + this.urlencode (params); - } - } else { - this.checkRequiredCredentials (); - body = this.urlencode (this.extend ({ - 'nonce': this.nonce (), - }, params)); - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Key': this.apiKey, - 'Sign': this.hmac (this.encode (body), this.encode (this.secret), 'sha512'), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } - - async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - const response = await this.fetch2 (path, api, method, params, headers, body); - const errors = this.safeValue (response, 'errors'); - const data = this.safeValue (response, 'response'); - if (errors || !data) { - const authErrorKeys = [ 'Key', 'user_id', 'Sign' ]; - for (let i = 0; i < authErrorKeys.length; i++) { - const errorKey = authErrorKeys[i]; - const errorMessage = this.safeString (errors, errorKey); - if (!errorMessage) { - continue; - } - if (errorKey === 'user_id' && errorMessage.indexOf ('authorization') < 0) { - continue; - } - throw new AuthenticationError (errorMessage); - } - throw new ExchangeError (this.json (errors)); - } - return response; - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/idex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/idex.js index 7d52a5286..c3c14d981 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/idex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/idex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { PAD_WITH_ZERO } = require ('./base/functions/number'); const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported, InvalidAddress, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -241,14 +242,6 @@ module.exports = class idex extends Exchange { return this.parseTickers (response, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // { // market: 'DIL-ETH', @@ -268,16 +261,16 @@ module.exports = class idex extends Exchange { // } const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'baseVolume'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume'); + const baseVolume = this.safeNumber (ticker, 'baseVolume'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume'); const timestamp = this.safeInteger (ticker, 'time'); - const open = this.safeFloat (ticker, 'open'); - const high = this.safeFloat (ticker, 'high'); - const low = this.safeFloat (ticker, 'low'); - const close = this.safeFloat (ticker, 'close'); - const ask = this.safeFloat (ticker, 'ask'); - const bid = this.safeFloat (ticker, 'bid'); - let percentage = this.safeFloat (ticker, 'percentChange'); + const open = this.safeNumber (ticker, 'open'); + const high = this.safeNumber (ticker, 'high'); + const low = this.safeNumber (ticker, 'low'); + const close = this.safeNumber (ticker, 'close'); + const ask = this.safeNumber (ticker, 'ask'); + const bid = this.safeNumber (ticker, 'bid'); + let percentage = this.safeNumber (ticker, 'percentChange'); if (percentage !== undefined) { percentage = 1 + percentage / 100; } @@ -353,11 +346,11 @@ module.exports = class idex extends Exchange { // sequence: 3853 // } const timestamp = this.safeInteger (ohlcv, 'start'); - const open = this.safeFloat (ohlcv, 'open'); - const high = this.safeFloat (ohlcv, 'high'); - const low = this.safeFloat (ohlcv, 'low'); - const close = this.safeFloat (ohlcv, 'close'); - const volume = this.safeFloat (ohlcv, 'volume'); + const open = this.safeNumber (ohlcv, 'open'); + const high = this.safeNumber (ohlcv, 'high'); + const low = this.safeNumber (ohlcv, 'low'); + const close = this.safeNumber (ohlcv, 'close'); + const volume = this.safeNumber (ohlcv, 'volume'); return [ timestamp, open, high, low, close, volume ]; } @@ -419,9 +412,14 @@ module.exports = class idex extends Exchange { // txStatus: 'mined' // } const id = this.safeString (trade, 'fillId'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - const cost = this.safeFloat (trade, 'quoteQuantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'quoteQuantity'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const timestamp = this.safeInteger (trade, 'time'); const marketId = this.safeString (trade, 'market'); const symbol = this.safeSymbol (marketId, market, '-'); @@ -430,7 +428,7 @@ module.exports = class idex extends Exchange { const oppositeSide = (makerSide === 'buy') ? 'sell' : 'buy'; const side = this.safeString (trade, 'side', oppositeSide); const takerOrMaker = this.safeString (trade, 'liquidity', 'taker'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeAsset'); @@ -503,8 +501,8 @@ module.exports = class idex extends Exchange { const result = []; for (let i = 0; i < bookSide.length; i++) { const order = bookSide[i]; - const price = this.safeFloat (order, 0); - const amount = this.safeFloat (order, 1); + const price = this.safeNumber (order, 0); + const amount = this.safeNumber (order, 1); const orderCount = this.safeInteger (order, 2); result.push ([ price, amount, orderCount ]); } @@ -591,16 +589,13 @@ module.exports = class idex extends Exchange { const entry = response[i]; const currencyId = this.safeString (entry, 'asset'); const code = this.safeCurrencyCode (currencyId); - const total = this.safeFloat (entry, 'quantity'); - const free = this.safeFloat (entry, 'availableForTrade'); - const used = this.safeFloat (entry, 'locked'); - result[code] = { - 'free': free, - 'used': used, - 'total': total, - }; + const account = this.account (); + account['total'] = this.safeString (entry, 'quantity'); + account['free'] = this.safeString (entry, 'availableForTrade'); + account['used'] = this.safeString (entry, 'locked'); + result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -821,10 +816,10 @@ module.exports = class idex extends Exchange { const symbol = this.safeSymbol (marketId, market, '-'); const trades = this.parseTrades (fills, market); const type = this.safeString (order, 'type'); - const amount = this.safeFloat (order, 'originalQuantity'); - const filled = this.safeFloat (order, 'executedQuantity'); - const average = this.safeFloat (order, 'avgExecutionPrice'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'originalQuantity'); + const filled = this.safeNumber (order, 'executedQuantity'); + const average = this.safeNumber (order, 'avgExecutionPrice'); + const price = this.safeNumber (order, 'price'); const rawStatus = this.safeString (order, 'status'); const status = this.parseOrderStatus (rawStatus); const fee = { @@ -933,7 +928,7 @@ module.exports = class idex extends Exchange { throw new NotSupported (this.id + ' quoteOrderQuantity is not supported for ' + type + ' orders, only supported for market orders'); } amountEnum = 1; - amount = this.safeFloat (params, 'quoteOrderQuantity'); + amount = this.safeNumber (params, 'quoteOrderQuantity'); } const sideEnum = (side === 'buy') ? 0 : 1; const walletBytes = this.remove0xPrefix (this.walletAddress); @@ -1236,13 +1231,13 @@ module.exports = class idex extends Exchange { } const id = this.safeString2 (transaction, 'depositId', 'withdrawId'); const code = this.safeCurrencyCode (this.safeString (transaction, 'asset'), currency); - const amount = this.safeFloat (transaction, 'quantity'); + const amount = this.safeNumber (transaction, 'quantity'); const txid = this.safeString (transaction, 'txId'); const timestamp = this.safeInteger (transaction, 'txTime'); let fee = undefined; if ('fee' in transaction) { fee = { - 'cost': this.safeFloat (transaction, 'fee'), + 'cost': this.safeNumber (transaction, 'fee'), 'currency': 'ETH', }; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/independentreserve.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/independentreserve.js index 119a216d5..86dcb348b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/independentreserve.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/independentreserve.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -126,11 +127,11 @@ module.exports = class independentreserve extends Exchange { const currencyId = this.safeString (balance, 'CurrencyCode'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'AvailableBalance'); - account['total'] = this.safeFloat (balance, 'TotalBalance'); + account['free'] = this.safeString (balance, 'AvailableBalance'); + account['total'] = this.safeString (balance, 'TotalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -151,16 +152,16 @@ module.exports = class independentreserve extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'LastPrice'); + const last = this.safeNumber (ticker, 'LastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'DayHighestPrice'), - 'low': this.safeFloat (ticker, 'DayLowestPrice'), - 'bid': this.safeFloat (ticker, 'CurrentHighestBidPrice'), + 'high': this.safeNumber (ticker, 'DayHighestPrice'), + 'low': this.safeNumber (ticker, 'DayLowestPrice'), + 'bid': this.safeNumber (ticker, 'CurrentHighestBidPrice'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'CurrentLowestOfferPrice'), + 'ask': this.safeNumber (ticker, 'CurrentLowestOfferPrice'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -169,8 +170,8 @@ module.exports = class independentreserve extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'DayAvgPrice'), - 'baseVolume': this.safeFloat (ticker, 'DayVolumeXbtInSecondaryCurrrency'), + 'average': this.safeNumber (ticker, 'DayAvgPrice'), + 'baseVolume': this.safeNumber (ticker, 'DayVolumeXbtInSecondaryCurrrency'), 'quoteVolume': undefined, 'info': ticker, }; @@ -249,20 +250,10 @@ module.exports = class independentreserve extends Exchange { orderType = 'limit'; } const timestamp = this.parse8601 (this.safeString (order, 'CreatedTimestampUtc')); - const amount = this.safeFloat2 (order, 'VolumeOrdered', 'Volume'); - let filled = this.safeFloat (order, 'VolumeFilled'); - let remaining = this.safeFloat (order, 'Outstanding'); - if (filled === undefined) { - if ((remaining !== undefined) && (amount !== undefined)) { - filled = Math.max (0, amount - remaining); - } - } - if (remaining === undefined) { - if ((filled !== undefined) && (amount !== undefined)) { - remaining = Math.max (0, amount - filled); - } - } - const feeRate = this.safeFloat (order, 'FeePercent'); + const amount = this.safeNumber2 (order, 'VolumeOrdered', 'Volume'); + const filled = this.safeNumber (order, 'VolumeFilled'); + const remaining = this.safeNumber (order, 'Outstanding'); + const feeRate = this.safeNumber (order, 'FeePercent'); let feeCost = undefined; if (feeRate !== undefined) { feeCost = feeRate * filled; @@ -274,10 +265,10 @@ module.exports = class independentreserve extends Exchange { }; const id = this.safeString (order, 'OrderGuid'); const status = this.parseOrderStatus (this.safeString (order, 'Status')); - const cost = this.safeFloat (order, 'Value'); - const average = this.safeFloat (order, 'AvgPrice'); - const price = this.safeFloat (order, 'Price', average); - return { + const cost = this.safeNumber (order, 'Value'); + const average = this.safeNumber (order, 'AvgPrice'); + const price = this.safeNumber (order, 'Price'); + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -299,7 +290,7 @@ module.exports = class independentreserve extends Exchange { 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -387,14 +378,11 @@ module.exports = class independentreserve extends Exchange { const timestamp = this.parse8601 (trade['TradeTimestampUtc']); const id = this.safeString (trade, 'TradeGuid'); const orderId = this.safeString (trade, 'OrderGuid'); - const price = this.safeFloat2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); - const amount = this.safeFloat2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'Price', 'SecondaryCurrencyTradePrice'); + const amountString = this.safeString2 (trade, 'VolumeTraded', 'PrimaryCurrencyAmount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const baseId = this.safeString (trade, 'PrimaryCurrencyCode'); const quoteId = this.safeString (trade, 'SecondaryCurrencyCode'); let marketId = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/indodax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/indodax.js index f1cc33732..05972a887 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/indodax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/indodax.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InsufficientFunds, InvalidOrder, OrderNotFound, AuthenticationError, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,7 +165,7 @@ module.exports = class indodax extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const taker = this.safeFloat (market, 'trade_fee_percent'); + const taker = this.safeNumber (market, 'trade_fee_percent'); const isMaintenance = this.safeInteger (market, 'is_maintenance'); const active = (isMaintenance) ? false : true; const pricePrecision = this.safeInteger (market, 'price_round'); @@ -174,11 +175,11 @@ module.exports = class indodax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'trade_min_traded_currency'), + 'min': this.safeNumber (market, 'trade_min_traded_currency'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'trade_min_base_currency'), + 'min': this.safeNumber (market, 'trade_min_base_currency'), 'max': undefined, }, 'cost': { @@ -216,11 +217,11 @@ module.exports = class indodax extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (used, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (used, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -257,16 +258,16 @@ module.exports = class indodax extends Exchange { const timestamp = this.safeTimestamp (ticker, 'server_time'); const baseVolume = 'vol_' + market['baseId'].toLowerCase (); const quoteVolume = 'vol_' + market['quoteId'].toLowerCase (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -276,8 +277,8 @@ module.exports = class indodax extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, baseVolume), - 'quoteVolume': this.safeFloat (ticker, quoteVolume), + 'baseVolume': this.safeNumber (ticker, baseVolume), + 'quoteVolume': this.safeNumber (ticker, quoteVolume), 'info': ticker, }; } @@ -291,14 +292,11 @@ module.exports = class indodax extends Exchange { } const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, @@ -353,7 +351,7 @@ module.exports = class indodax extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'status', 'open')); let symbol = undefined; let cost = undefined; - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let amount = undefined; let remaining = undefined; let filled = undefined; @@ -367,18 +365,18 @@ module.exports = class indodax extends Exchange { if ((market['baseId'] === 'idr') && ('remain_rp' in order)) { baseId = 'rp'; } - cost = this.safeFloat (order, 'order_' + quoteId); + cost = this.safeNumber (order, 'order_' + quoteId); if (cost) { amount = cost / price; - const remainingCost = this.safeFloat (order, 'remain_' + quoteId); + const remainingCost = this.safeNumber (order, 'remain_' + quoteId); if (remainingCost !== undefined) { remaining = remainingCost / price; filled = amount - remaining; } } else { - amount = this.safeFloat (order, 'order_' + baseId); + amount = this.safeNumber (order, 'order_' + baseId); cost = price * amount; - remaining = this.safeFloat (order, 'remain_' + baseId); + remaining = this.safeNumber (order, 'remain_' + baseId); filled = amount - remaining; } } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/itbit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/itbit.js index 552bb0de5..a46080ccc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/itbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/itbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -114,25 +115,25 @@ module.exports = class itbit extends Exchange { throw new ExchangeError (this.id + ' fetchTicker returned a bad response: ' + this.json (ticker)); } const timestamp = this.parse8601 (serverTimeUTC); - const vwap = this.safeFloat (ticker, 'vwap24h'); - const baseVolume = this.safeFloat (ticker, 'volume24h'); + const vwap = this.safeNumber (ticker, 'vwap24h'); + const baseVolume = this.safeNumber (ticker, 'volume24h'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'lastPrice'); + const last = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'openToday'), + 'open': this.safeNumber (ticker, 'openToday'), 'close': last, 'last': last, 'previousClose': undefined, @@ -179,23 +180,20 @@ module.exports = class itbit extends Exchange { const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); const side = this.safeString (trade, 'direction'); const orderId = this.safeString (trade, 'orderId'); - let feeCost = this.safeFloat (trade, 'commissionPaid'); + let feeCost = this.safeNumber (trade, 'commissionPaid'); const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - let rebatesApplied = this.safeFloat (trade, 'rebatesApplied'); + let rebatesApplied = this.safeNumber (trade, 'rebatesApplied'); if (rebatesApplied !== undefined) { rebatesApplied = -rebatesApplied; } const rebateCurrencyId = this.safeString (trade, 'rebateCurrency'); const rebateCurrency = this.safeCurrencyCode (rebateCurrencyId); - const price = this.safeFloat2 (trade, 'price', 'rate'); - const amount = this.safeFloat2 (trade, 'currency1Amount', 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'price', 'rate'); + const amountString = this.safeString2 (trade, 'currency1Amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; const marketId = this.safeString (trade, 'instrument'); if (marketId !== undefined) { @@ -317,7 +315,7 @@ module.exports = class itbit extends Exchange { 'txid': txnHash, 'type': transactionType, 'status': status, - 'amount': this.safeFloat (item, 'amount'), + 'amount': this.safeNumber (item, 'amount'), 'fee': undefined, 'info': item, }); @@ -417,11 +415,11 @@ module.exports = class itbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'availableBalance'); - account['total'] = this.safeFloat (balance, 'totalBalance'); + account['free'] = this.safeString (balance, 'availableBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchWallets (params = {}) { @@ -512,26 +510,16 @@ module.exports = class itbit extends Exchange { const type = this.safeString (order, 'type'); const symbol = this.markets_by_id[order['instrument']]['symbol']; const timestamp = this.parse8601 (order['createdTime']); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'amountFilled'); - let remaining = undefined; - let cost = undefined; + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'amountFilled'); const fee = undefined; - const price = this.safeFloat (order, 'price'); - const average = this.safeFloat (order, 'volumeWeightedAveragePrice'); - if (filled !== undefined) { - if (amount !== undefined) { - remaining = amount - filled; - } - if (average !== undefined) { - cost = filled * average; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'volumeWeightedAveragePrice'); const clientOrderId = this.safeString (order, 'clientOrderIdentifier'); const id = this.safeString (order, 'id'); const postOnlyString = this.safeString (order, 'postOnly'); const postOnly = (postOnlyString === 'True'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -546,15 +534,15 @@ module.exports = class itbit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, // 'trades': this.parseTrades (order['trades'], market), 'trades': undefined, - }; + }); } nonce () { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kraken.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kraken.js index 198ee4cf8..514ed0094 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kraken.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kraken.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { BadSymbol, ExchangeNotAvailable, ArgumentsRequired, PermissionDenied, AuthenticationError, ExchangeError, OrderNotFound, DDoSProtection, InvalidNonce, InsufficientFunds, CancelPending, InvalidOrder, InvalidAddress, RateLimitExceeded } = require ('./base/errors'); const { TRUNCATE, DECIMAL_PLACES } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -297,26 +298,38 @@ module.exports = class kraken extends Exchange { // } // } // - const keys = Object.keys (response['result']); + const markets = this.safeValue (response, 'result', {}); + const keys = Object.keys (markets); let result = []; for (let i = 0; i < keys.length; i++) { const id = keys[i]; - const market = response['result'][id]; - const baseId = market['base']; - const quoteId = market['quote']; + const market = markets[id]; + const baseId = this.safeString (market, 'base'); + const quoteId = this.safeString (market, 'quote'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const darkpool = id.indexOf ('.d') >= 0; - const symbol = darkpool ? market['altname'] : (base + '/' + quote); + const altname = this.safeString (market, 'altname'); + const symbol = darkpool ? altname : (base + '/' + quote); + const makerFees = this.safeValue (market, 'fees_maker', []); + const firstMakerFee = this.safeValue (makerFees, 0, []); + const firstMakerFeeRate = this.safeNumber (firstMakerFee, 1); let maker = undefined; - if ('fees_maker' in market) { - maker = parseFloat (market['fees_maker'][0][1]) / 100; + if (firstMakerFeeRate !== undefined) { + maker = parseFloat (firstMakerFeeRate) / 100; + } + const takerFees = this.safeValue (market, 'fees', []); + const firstTakerFee = this.safeValue (takerFees, 0, []); + const firstTakerFeeRate = this.safeNumber (firstTakerFee, 1); + let taker = undefined; + if (firstTakerFeeRate !== undefined) { + taker = parseFloat (firstTakerFeeRate) / 100; } const precision = { - 'amount': market['lot_decimals'], - 'price': market['pair_decimals'], + 'amount': this.safeInteger (market, 'lot_decimals'), + 'price': this.safeInteger (market, 'pair_decimals'), }; - const minAmount = this.safeFloat (market, 'ordermin'); + const minAmount = this.safeNumber (market, 'ordermin'); result.push ({ 'id': id, 'symbol': symbol, @@ -328,7 +341,7 @@ module.exports = class kraken extends Exchange { 'info': market, 'altname': market['altname'], 'maker': maker, - 'taker': parseFloat (market['fees'][0][1]) / 100, + 'taker': taker, 'active': true, 'precision': precision, 'limits': { @@ -451,7 +464,7 @@ module.exports = class kraken extends Exchange { await this.loadMarkets (); this.checkRequiredCredentials (); const response = await this.privatePostTradeVolume (params); - const tradedVolume = this.safeFloat (response['result'], 'volume'); + const tradedVolume = this.safeNumber (response['result'], 'volume'); const tiers = this.fees['trading']['tiers']; let taker = tiers['taker'][1]; let maker = tiers['maker'][1]; @@ -473,8 +486,8 @@ module.exports = class kraken extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - const amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + const amount = this.safeNumber (bidask, amountKey); const timestamp = this.safeInteger (bidask, 2); return [ price, amount, timestamp ]; } @@ -512,7 +525,14 @@ module.exports = class kraken extends Exchange { // } // const result = this.safeValue (response, 'result', {}); - const orderbook = this.safeValue (result, market['id']); + let orderbook = this.safeValue (result, market['id']); + // sometimes kraken returns wsname instead of market id + // https://github.com/ccxt/ccxt/issues/8662 + const marketInfo = this.safeValue (market, 'info', {}); + const wsName = this.safeValue (marketInfo, 'wsname'); + if (wsName !== undefined) { + orderbook = this.safeValue (result, wsName, orderbook); + } return this.parseOrderBook (orderbook); } @@ -540,7 +560,7 @@ module.exports = class kraken extends Exchange { 'ask': parseFloat (ticker['a'][0]), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'o'), + 'open': this.safeNumber (ticker, 'o'), 'close': last, 'last': last, 'previousClose': undefined, @@ -611,11 +631,11 @@ module.exports = class kraken extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 6), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 6), ]; } @@ -682,24 +702,24 @@ module.exports = class kraken extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'asset'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); } else { direction = 'in'; } - const time = this.safeFloat (item, 'time'); + const time = this.safeNumber (item, 'time'); let timestamp = undefined; if (time !== undefined) { timestamp = parseInt (time * 1000); } const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, @@ -823,9 +843,8 @@ module.exports = class kraken extends Exchange { let timestamp = undefined; let side = undefined; let type = undefined; - let price = undefined; - let amount = undefined; - let cost = undefined; + let priceString = undefined; + let amountString = undefined; let id = undefined; let orderId = undefined; let fee = undefined; @@ -834,8 +853,8 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 2); side = (trade[3] === 's') ? 'sell' : 'buy'; type = (trade[4] === 'l') ? 'limit' : 'market'; - price = this.safeFloat (trade, 0); - amount = this.safeFloat (trade, 1); + priceString = this.safeString (trade, 0); + amountString = this.safeString (trade, 1); const tradeLength = trade.length; if (tradeLength > 6) { id = this.safeString (trade, 6); // artificially added as per #1794 @@ -856,15 +875,15 @@ module.exports = class kraken extends Exchange { timestamp = this.safeTimestamp (trade, 'time'); side = this.safeString (trade, 'type'); type = this.safeString (trade, 'ordertype'); - price = this.safeFloat (trade, 'price'); - amount = this.safeFloat (trade, 'vol'); + priceString = this.safeString (trade, 'price'); + amountString = this.safeString (trade, 'vol'); if ('fee' in trade) { let currency = undefined; if (market !== undefined) { currency = market['quote']; } fee = { - 'cost': this.safeFloat (trade, 'fee'), + 'cost': this.safeNumber (trade, 'fee'), 'currency': currency, }; } @@ -872,11 +891,9 @@ module.exports = class kraken extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'order': orderId, @@ -951,10 +968,10 @@ module.exports = class kraken extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -983,15 +1000,15 @@ module.exports = class kraken extends Exchange { if (type === 'limit') { request['price'] = this.priceToPrecision (symbol, price); } else if ((type === 'stop-loss') || (type === 'take-profit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice', price); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice', price); if (stopPrice === undefined) { throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a price/stopPrice parameter for a ' + type + ' order'); } else { request['price'] = this.priceToPrecision (symbol, stopPrice); } } else if ((type === 'stop-loss-limit') || (type === 'take-profit-limit')) { - const stopPrice = this.safeFloat2 (params, 'price', 'stopPrice'); - const limitPrice = this.safeFloat (params, 'price2'); + const stopPrice = this.safeNumber2 (params, 'price', 'stopPrice'); + const limitPrice = this.safeNumber (params, 'price2'); const stopPriceDefined = (stopPrice !== undefined); const limitPriceDefined = (limitPrice !== undefined); if (stopPriceDefined && limitPriceDefined) { @@ -1100,10 +1117,10 @@ module.exports = class kraken extends Exchange { if (orderDescription !== undefined) { const parts = orderDescription.split (' '); side = this.safeString (parts, 0); - amount = this.safeFloat (parts, 1); + amount = this.safeNumber (parts, 1); marketId = this.safeString (parts, 2); type = this.safeString (parts, 4); - price = this.safeFloat (parts, 5); + price = this.safeNumber (parts, 5); } side = this.safeString (description, 'type', side); type = this.safeString (description, 'ordertype', type); @@ -1117,27 +1134,23 @@ module.exports = class kraken extends Exchange { market = this.getDelistedMarketById (marketId); } const timestamp = this.safeTimestamp (order, 'opentm'); - amount = this.safeFloat (order, 'vol', amount); - const filled = this.safeFloat (order, 'vol_exec'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = amount - filled; - } + amount = this.safeNumber (order, 'vol', amount); + const filled = this.safeNumber (order, 'vol_exec'); let fee = undefined; - const cost = this.safeFloat (order, 'cost'); - price = this.safeFloat (description, 'price', price); + const cost = this.safeNumber (order, 'cost'); + price = this.safeNumber (description, 'price', price); if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (description, 'price2'); + price = this.safeNumber (description, 'price2'); } if ((price === undefined) || (price === 0.0)) { - price = this.safeFloat (order, 'price', price); + price = this.safeNumber (order, 'price', price); } - const average = this.safeFloat (order, 'price'); + const average = this.safeNumber (order, 'price'); if (market !== undefined) { symbol = market['symbol']; if ('fee' in order) { const flags = order['oflags']; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); fee = { 'cost': feeCost, 'rate': undefined, @@ -1161,8 +1174,8 @@ module.exports = class kraken extends Exchange { if (rawTrades !== undefined) { trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id }); } - const stopPrice = this.safeFloat (order, 'stopprice'); - return { + const stopPrice = this.safeNumber (order, 'stopprice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -1181,10 +1194,10 @@ module.exports = class kraken extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -1534,10 +1547,10 @@ module.exports = class kraken extends Exchange { const currencyId = this.safeString (transaction, 'asset'); const code = this.safeCurrencyCode (currencyId, currency); const address = this.safeString (transaction, 'info'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const type = this.safeString (transaction, 'type'); // injected from the outside - let feeCost = this.safeFloat (transaction, 'fee'); + let feeCost = this.safeNumber (transaction, 'fee'); if (feeCost === undefined) { if (type === 'deposit') { feeCost = 0; @@ -1714,7 +1727,7 @@ module.exports = class kraken extends Exchange { throw new ExchangeError (this.id + " withdraw() requires a 'key' parameter (withdrawal key name, as set up on your account)"); } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const request = { // 'txid': 'comma delimited list of transaction ids to restrict output to', diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kucoin.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kucoin.js index bcb058989..0b5aca5af 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kucoin.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kucoin.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, InvalidNonce, NotSupported, BadRequest, AuthenticationError, BadSymbol, RateLimitExceeded, PermissionDenied } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -45,6 +46,7 @@ module.exports = class kucoin extends Exchange { 'fetchTrades': true, 'fetchWithdrawals': true, 'withdraw': true, + 'transfer': true, }, 'urls': { 'logo': 'https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg', @@ -52,6 +54,7 @@ module.exports = class kucoin extends Exchange { 'api': { 'public': 'https://openapi-v2.kucoin.com', 'private': 'https://openapi-v2.kucoin.com', + 'futuresPrivate': 'https://api-futures.kucoin.com', }, 'test': { 'public': 'https://openapi-sandbox.kucoin.com', @@ -160,6 +163,15 @@ module.exports = class kucoin extends Exchange { 'stop-order/cancel', ], }, + 'futuresPrivate': { + 'get': [ + 'account-overview', + 'positions', + ], + 'post': [ + 'transfer-out', + ], + }, }, 'timeframes': { '1m': '1min', @@ -184,6 +196,7 @@ module.exports = class kucoin extends Exchange { 'order_not_exist_or_not_allow_to_cancel': InvalidOrder, // {"code":"400100","msg":"order_not_exist_or_not_allow_to_cancel"} 'Order size below the minimum requirement.': InvalidOrder, // {"code":"400100","msg":"Order size below the minimum requirement."} 'The withdrawal amount is below the minimum requirement.': ExchangeError, // {"code":"400100","msg":"The withdrawal amount is below the minimum requirement."} + 'Unsuccessful! Exceeded the max. funds out-transfer limit': InsufficientFunds, // {"code":"200000","msg":"Unsuccessful! Exceeded the max. funds out-transfer limit"} '400': BadRequest, '401': AuthenticationError, '403': NotSupported, @@ -240,9 +253,7 @@ module.exports = class kucoin extends Exchange { 'version': 'v1', 'symbolSeparator': '-', 'fetchMyTradesMethod': 'private_get_fills', - 'fetchBalance': { - 'type': 'trade', // or 'main' - }, + 'fetchBalance': 'trade', // endpoint versions 'versions': { 'public': { @@ -262,6 +273,25 @@ module.exports = class kucoin extends Exchange { 'accounts/sub-transfer': 'v2', }, }, + 'futuresPrivate': { + 'GET': { + 'account-overview': 'v1', + 'positions': 'v1', + }, + 'POST': { + 'transfer-out': 'v2', + }, + }, + }, + 'accountsByType': { + 'trade': 'trade', + 'trading': 'trade', + 'margin': 'margin', + 'main': 'main', + 'futures': 'contract', + 'contract': 'contract', + 'pool': 'pool', + 'pool-x': 'pool', }, }, }); @@ -342,11 +372,11 @@ module.exports = class kucoin extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const active = this.safeValue (market, 'enableTrading'); - const baseMaxSize = this.safeFloat (market, 'baseMaxSize'); - const baseMinSize = this.safeFloat (market, 'baseMinSize'); - const quoteMaxSize = this.safeFloat (market, 'quoteMaxSize'); - const quoteMinSize = this.safeFloat (market, 'quoteMinSize'); - // const quoteIncrement = this.safeFloat (market, 'quoteIncrement'); + const baseMaxSize = this.safeNumber (market, 'baseMaxSize'); + const baseMinSize = this.safeNumber (market, 'baseMinSize'); + const quoteMaxSize = this.safeNumber (market, 'quoteMaxSize'); + const quoteMinSize = this.safeNumber (market, 'quoteMinSize'); + // const quoteIncrement = this.safeNumber (market, 'quoteIncrement'); const precision = { 'amount': this.precisionFromString (this.safeString (market, 'baseIncrement')), 'price': this.precisionFromString (this.safeString (market, 'priceIncrement')), @@ -357,7 +387,7 @@ module.exports = class kucoin extends Exchange { 'max': baseMaxSize, }, 'price': { - 'min': this.safeFloat (market, 'priceIncrement'), + 'min': this.safeNumber (market, 'priceIncrement'), 'max': quoteMaxSize / baseMinSize, }, 'cost': { @@ -408,7 +438,7 @@ module.exports = class kucoin extends Exchange { const precision = this.safeInteger (entry, 'precision'); const isWithdrawEnabled = this.safeValue (entry, 'isWithdrawEnabled', false); const isDepositEnabled = this.safeValue (entry, 'isDepositEnabled', false); - const fee = this.safeFloat (entry, 'withdrawalMinFee'); + const fee = this.safeNumber (entry, 'withdrawalMinFee'); const active = (isWithdrawEnabled && isDepositEnabled); result[code] = { 'id': id, @@ -475,7 +505,7 @@ module.exports = class kucoin extends Exchange { const response = await this.privateGetWithdrawalsQuotas (this.extend (request, params)); const data = response['data']; const withdrawFees = {}; - withdrawFees[code] = this.safeFloat (data, 'withdrawMinFee'); + withdrawFees[code] = this.safeNumber (data, 'withdrawMinFee'); return { 'info': response, 'withdraw': withdrawFees, @@ -522,35 +552,35 @@ module.exports = class kucoin extends Exchange { // "mark": 0 // } // - let percentage = this.safeFloat (ticker, 'changeRate'); + let percentage = this.safeNumber (ticker, 'changeRate'); if (percentage !== undefined) { percentage = percentage * 100; } - const last = this.safeFloat2 (ticker, 'last', 'lastTradedPrice'); + const last = this.safeNumber2 (ticker, 'last', 'lastTradedPrice'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '-'); - const baseVolume = this.safeFloat (ticker, 'vol'); - const quoteVolume = this.safeFloat (ticker, 'volValue'); + const baseVolume = this.safeNumber (ticker, 'vol'); + const quoteVolume = this.safeNumber (ticker, 'volValue'); const vwap = this.vwap (baseVolume, quoteVolume); const timestamp = this.safeInteger2 (ticker, 'time', 'datetime'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, - 'change': this.safeFloat (ticker, 'changePrice'), + 'change': this.safeNumber (ticker, 'changePrice'), 'percentage': percentage, - 'average': this.safeFloat (ticker, 'averagePrice'), + 'average': this.safeNumber (ticker, 'averagePrice'), 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'info': ticker, @@ -634,11 +664,11 @@ module.exports = class kucoin extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 5), ]; } @@ -836,16 +866,18 @@ module.exports = class kucoin extends Exchange { // 'marginMode': 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned // 'autoBorrow': false, // The system will first borrow you funds at the optimal interest rate and then place an order for you }; - if (type !== 'market') { - request['price'] = this.priceToPrecision (symbol, price); - request['size'] = this.amountToPrecision (symbol, amount); - } else { - if (this.safeValue (params, 'quoteAmount')) { - // used to create market order by quote amount - https://github.com/ccxt/ccxt/issues/4876 - request['funds'] = this.amountToPrecision (symbol, amount); + const quoteAmount = this.safeNumber2 (params, 'cost', 'funds'); + if (type === 'market') { + if (quoteAmount !== undefined) { + params = this.omit (params, [ 'cost', 'funds' ]); + // kucoin uses base precision even for quote values + request['funds'] = this.amountToPrecision (symbol, quoteAmount); } else { request['size'] = this.amountToPrecision (symbol, amount); } + } else { + request['price'] = this.priceToPrecision (symbol, price); + request['size'] = this.amountToPrecision (symbol, amount); } const response = await this.privatePostOrders (this.extend (request, params)); // @@ -879,8 +911,10 @@ module.exports = class kucoin extends Exchange { 'fee': undefined, 'trades': undefined, }; - if (!this.safeValue (params, 'quoteAmount')) { + if (quoteAmount === undefined) { order['amount'] = amount; + } else { + order['cost'] = quoteAmount; } return order; } @@ -1056,15 +1090,18 @@ module.exports = class kucoin extends Exchange { const type = this.safeString (order, 'type'); const timestamp = this.safeInteger (order, 'createdAt'); const datetime = this.iso8601 (timestamp); - let price = this.safeFloat (order, 'price'); + let price = this.safeNumber (order, 'price'); + if (price === 0.0) { + // market orders + price = undefined; + } const side = this.safeString (order, 'side'); const feeCurrencyId = this.safeString (order, 'feeCurrency'); const feeCurrency = this.safeCurrencyCode (feeCurrencyId); - const feeCost = this.safeFloat (order, 'fee'); - const amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat (order, 'dealSize'); - const cost = this.safeFloat (order, 'dealFunds'); - const remaining = amount - filled; + const feeCost = this.safeNumber (order, 'fee'); + const amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber (order, 'dealSize'); + const cost = this.safeNumber (order, 'dealFunds'); // bool const isActive = this.safeValue (order, 'isActive', false); const cancelExist = this.safeValue (order, 'cancelExist', false); @@ -1074,20 +1111,11 @@ module.exports = class kucoin extends Exchange { 'currency': feeCurrency, 'cost': feeCost, }; - if (type === 'market') { - if (price === 0.0) { - if ((cost !== undefined) && (filled !== undefined)) { - if ((cost > 0) && (filled > 0)) { - price = cost / filled; - } - } - } - } const clientOrderId = this.safeString (order, 'clientOid'); const timeInForce = this.safeString (order, 'timeInForce'); - const stopPrice = this.safeFloat (order, 'stopPrice'); + const stopPrice = this.safeNumber (order, 'stopPrice'); const postOnly = this.safeValue (order, 'postOnly'); - return { + return this.safeOrder ({ 'id': orderId, 'clientOrderId': clientOrderId, 'symbol': symbol, @@ -1100,7 +1128,7 @@ module.exports = class kucoin extends Exchange { 'stopPrice': stopPrice, 'cost': cost, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'timestamp': timestamp, 'datetime': datetime, 'fee': fee, @@ -1109,7 +1137,7 @@ module.exports = class kucoin extends Exchange { 'lastTradeTimestamp': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -1310,7 +1338,6 @@ module.exports = class kucoin extends Exchange { const id = this.safeString2 (trade, 'tradeId', 'id'); const orderId = this.safeString (trade, 'orderId'); const takerOrMaker = this.safeString (trade, 'liquidity'); - const amount = this.safeFloat2 (trade, 'size', 'amount'); let timestamp = this.safeInteger (trade, 'time'); if (timestamp !== undefined) { timestamp = parseInt (timestamp / 1000000); @@ -1321,10 +1348,13 @@ module.exports = class kucoin extends Exchange { timestamp = timestamp * 1000; } } - const price = this.safeFloat2 (trade, 'price', 'dealPrice'); + const priceString = this.safeString2 (trade, 'price', 'dealPrice'); + const amountString = this.safeString2 (trade, 'size', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const side = this.safeString (trade, 'side'); let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'feeCurrency'); let feeCurrency = this.safeCurrencyCode (feeCurrencyId); @@ -1336,20 +1366,16 @@ module.exports = class kucoin extends Exchange { fee = { 'cost': feeCost, 'currency': feeCurrency, - 'rate': this.safeFloat (trade, 'feeRate'), + 'rate': this.safeNumber (trade, 'feeRate'), }; } let type = this.safeString (trade, 'type'); if (type === 'match') { type = undefined; } - let cost = this.safeFloat2 (trade, 'funds', 'dealValue'); + let cost = this.safeNumber2 (trade, 'funds', 'dealValue'); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } return { 'info': trade, @@ -1445,7 +1471,7 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); let address = this.safeString (transaction, 'address'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let txid = this.safeString (transaction, 'walletTxId'); if (txid !== undefined) { const txidParts = txid.split ('@'); @@ -1463,7 +1489,7 @@ module.exports = class kucoin extends Exchange { const rawStatus = this.safeString (transaction, 'status'); const status = this.parseTransactionStatus (rawStatus); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { let rate = undefined; if (amount !== undefined) { @@ -1644,45 +1670,180 @@ module.exports = class kucoin extends Exchange { async fetchBalance (params = {}) { await this.loadMarkets (); - let type = undefined; - const request = {}; - if ('type' in params) { - type = params['type']; - if (type !== undefined) { - request['type'] = type; - } - params = this.omit (params, 'type'); + const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType', 'trade'); + const requestedType = this.safeString (params, 'type', defaultType); + const accountsByType = this.safeValue (this.options, 'accountsByType'); + const type = this.safeString (accountsByType, requestedType); + if (type === undefined) { + const keys = Object.keys (accountsByType); + throw new ExchangeError (this.id + ' type must be one of ' + keys.join (', ')); + } + params = this.omit (params, 'type'); + if (type === 'contract') { + // futures api requires a futures apiKey + // only fetches one balance at a time + // by default it will only fetch the BTC balance of the futures account + // you can send 'currency' in params to fetch other currencies + // fetchBalance ({ 'type': 'futures', 'currency': 'USDT' }) + const response = await this.futuresPrivateGetAccountOverview (params); + // + // { + // code: '200000', + // data: { + // accountEquity: 0.00005, + // unrealisedPNL: 0, + // marginBalance: 0.00005, + // positionMargin: 0, + // orderMargin: 0, + // frozenFunds: 0, + // availableBalance: 0.00005, + // currency: 'XBT' + // } + // } + // + const data = this.safeValue (response, 'data'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (data, 'availableBalance'); + account['total'] = this.safeString (data, 'accountEquity'); + const result = { 'info': response }; + result[code] = account; + return this.parseBalance (result, false); } else { - const options = this.safeValue (this.options, 'fetchBalance', {}); - type = this.safeString (options, 'type', 'trade'); - } - const response = await this.privateGetAccounts (this.extend (request, params)); - // - // { - // "code":"200000", - // "data":[ - // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, - // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, - // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, - // ] - // } - // - const data = this.safeValue (response, 'data', []); - const result = { 'info': response }; - for (let i = 0; i < data.length; i++) { - const balance = data[i]; - const balanceType = this.safeString (balance, 'type'); - if (balanceType === type) { - const currencyId = this.safeString (balance, 'currency'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'holds'); - result[code] = account; + const request = { + 'type': type, + }; + const response = await this.privateGetAccounts (this.extend (request, params)); + // + // { + // "code":"200000", + // "data":[ + // {"balance":"0.00009788","available":"0.00009788","holds":"0","currency":"BTC","id":"5c6a4fd399a1d81c4f9cc4d0","type":"trade"}, + // {"balance":"3.41060034","available":"3.41060034","holds":"0","currency":"SOUL","id":"5c6a4d5d99a1d8182d37046d","type":"trade"}, + // {"balance":"0.01562641","available":"0.01562641","holds":"0","currency":"NEO","id":"5c6a4f1199a1d8165a99edb1","type":"trade"}, + // ] + // } + // + const data = this.safeValue (response, 'data', []); + const result = { 'info': response }; + for (let i = 0; i < data.length; i++) { + const balance = data[i]; + const balanceType = this.safeString (balance, 'type'); + if (balanceType === type) { + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['total'] = this.safeString (balance, 'balance'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'holds'); + result[code] = account; + } } + return this.parseBalance (result, false); + } + } + + async transfer (code, amount, fromAccount, toAccount, params = {}) { + await this.loadMarkets (); + const currency = this.currency (code); + const requestedAmount = this.currencyToPrecision (code, amount); + const accountsById = this.safeValue (this.options, 'accountsByType', {}); + const fromId = this.safeString (accountsById, fromAccount); + if (fromId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' fromAccount must be one of ' + keys.join (', ')); + } + const toId = this.safeString (accountsById, toAccount); + if (toId === undefined) { + const keys = Object.keys (accountsById); + throw new ExchangeError (this.id + ' toAccount must be one of ' + keys.join (', ')); + } + if (fromId === 'contract') { + if (toId !== 'main') { + throw new ExchangeError (this.id + ' only supports transferring from futures account to main account'); + } + const request = { + 'currency': currency['id'], + 'amount': requestedAmount, + }; + if (!('bizNo' in params)) { + // it doesn't like more than 24 characters + request['bizNo'] = this.uuid22 (); + } + const response = await this.futuresPrivatePostTransferOut (this.extend (request, params)); + // + // { + // code: '200000', + // data: { + // applyId: '605a87217dff1500063d485d', + // bizNo: 'bcd6e5e1291f4905af84dc', + // payAccountType: 'CONTRACT', + // payTag: 'DEFAULT', + // remark: '', + // recAccountType: 'MAIN', + // recTag: 'DEFAULT', + // recRemark: '', + // recSystem: 'KUCOIN', + // status: 'PROCESSING', + // currency: 'XBT', + // amount: '0.00001', + // fee: '0', + // sn: '573688685663948', + // reason: '', + // createdAt: 1616545569000, + // updatedAt: 1616545569000 + // } + // } + // + const data = this.safeValue (response, 'data'); + const timestamp = this.safeInteger (data, 'createdAt'); + const id = this.safeString (data, 'applyId'); + const currencyId = this.safeString (data, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const amount = this.safeNumber (data, 'amount'); + const rawStatus = this.safeString (data, 'status'); + let status = undefined; + if (rawStatus === 'PROCESSING') { + status = 'pending'; + } + return { + 'info': response, + 'currency': code, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'amount': amount, + 'fromAccount': fromId, + 'toAccount': toId, + 'id': id, + 'status': status, + }; + } else { + const request = { + 'currency': currency['id'], + 'from': fromId, + 'to': toId, + 'amount': requestedAmount, + }; + if (!('clientOid' in params)) { + request['clientOid'] = this.uuid (); + } + const response = await this.privatePostAccountsInnerTransfer (this.extend (request, params)); + // { code: '200000', data: { orderId: '605a6211e657f00006ad0ad6' } } + const data = this.safeValue (response, 'data'); + const id = this.safeString (data, 'orderId'); + return { + 'info': response, + 'id': id, + 'timestamp': undefined, + 'datetime': undefined, + 'currency': code, + 'amount': requestedAmount, + 'fromAccount': fromId, + 'toAccount': toId, + 'status': undefined, + }; } - return this.parseBalance (result); } async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) { @@ -1770,11 +1931,11 @@ module.exports = class kucoin extends Exchange { const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'code': code, }; - const amount = this.safeFloat (item, 'amount'); - const after = this.safeFloat (item, 'balance'); + const amount = this.safeNumber (item, 'amount'); + const after = this.safeNumber (item, 'balance'); const direction = this.safeString (item, 'direction'); let before = undefined; if (after !== undefined && amount !== undefined) { @@ -1824,6 +1985,94 @@ module.exports = class kucoin extends Exchange { return this.safeString (types, type, type); } + async fetchPositions (symbols = undefined, params = {}) { + const response = await this.futuresPrivateGetPositions (params); + // + // { + // code: '200000', + // data: [ + // { + // id: '605a9772a229ab0006408258', + // symbol: 'XBTUSDTM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746099, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54371.92, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'USDT', + // isInverse: false + // }, + // { + // id: '605a9772026ac900066550df', + // symbol: 'XBTUSDM', + // autoDeposit: false, + // maintMarginReq: 0.005, + // riskLimit: 200, + // realLeverage: 0, + // crossMode: false, + // delevPercentage: 0, + // currentTimestamp: 1616549746110, + // currentQty: 0, + // currentCost: 0, + // currentComm: 0, + // unrealisedCost: 0, + // realisedGrossCost: 0, + // realisedCost: 0, + // isOpen: false, + // markPrice: 54354.76, + // markValue: 0, + // posCost: 0, + // posCross: 0, + // posInit: 0, + // posComm: 0, + // posLoss: 0, + // posMargin: 0, + // posMaint: 0, + // maintMargin: 0, + // realisedGrossPnl: 0, + // realisedPnl: 0, + // unrealisedPnl: 0, + // unrealisedPnlPcnt: 0, + // unrealisedRoePcnt: 0, + // avgEntryPrice: 0, + // liquidationPrice: 0, + // bankruptPrice: 0, + // settleCurrency: 'XBT', + // isInverse: true + // } + // ] + // } + // + return this.safeValue (response, 'data', response); + } + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { // // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint @@ -1840,16 +2089,16 @@ module.exports = class kucoin extends Exchange { let endpart = ''; headers = (headers !== undefined) ? headers : {}; if (Object.keys (query).length) { - if (method !== 'GET') { + if ((method === 'GET') || (method === 'DELETE')) { + endpoint += '?' + this.urlencode (query); + } else { body = this.json (query); endpart = body; headers['Content-Type'] = 'application/json'; - } else { - endpoint += '?' + this.urlencode (query); } } const url = this.urls['api'][api] + endpoint; - if (api === 'private') { + if ((api === 'private') || (api === 'futuresPrivate')) { this.checkRequiredCredentials (); const timestamp = this.nonce ().toString (); headers = this.extend ({ @@ -1892,8 +2141,8 @@ module.exports = class kucoin extends Exchange { // { code: '200000', data: { ... }} // const errorCode = this.safeString (response, 'code'); - const message = this.safeString (response, 'msg'); - this.throwExactlyMatchedException (this.exceptions['exact'], message, message); - this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, message); + const message = this.safeString (response, 'msg', ''); + this.throwExactlyMatchedException (this.exceptions['exact'], message, this.id + ' ' + message); + this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, this.id + ' ' + message); } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kuna.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kuna.js index e652171d1..0067e406f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kuna.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/kuna.js @@ -2,12 +2,13 @@ // --------------------------------------------------------------------------- -const acx = require ('./acx.js'); -const { ArgumentsRequired } = require ('./base/errors'); +const Exchange = require ('./base/Exchange'); +const { ArgumentsRequired, InsufficientFunds, OrderNotFound } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- -module.exports = class kuna extends acx { +module.exports = class kuna extends Exchange { describe () { return this.deepExtend (super.describe (), { 'id': 'kuna', @@ -17,14 +18,24 @@ module.exports = class kuna extends acx { 'version': 'v2', 'has': { 'CORS': false, - 'fetchTickers': true, + 'cancelOrder': true, + 'createOrder': true, + 'fetchBalance': true, + 'fetchMarkets': true, + 'fetchMyTrades': true, 'fetchOHLCV': 'emulated', 'fetchOpenOrders': true, - 'fetchMyTrades': true, + 'fetchOrder': true, + 'fetchOrderBook': true, + 'fetchTicker': true, + 'fetchTickers': true, + 'fetchTime': true, + 'fetchTrades': true, 'withdraw': false, }, 'timeframes': undefined, 'urls': { + 'extension': '.json', 'referral': 'https://kuna.io?r=kunaid-gvfihe8az7o4', 'logo': 'https://user-images.githubusercontent.com/51840849/87153927-f0578b80-c2c0-11ea-84b6-74612568e9e1.jpg', 'api': 'https://kuna.io', @@ -32,8 +43,47 @@ module.exports = class kuna extends acx { 'doc': 'https://kuna.io/documents/api', 'fees': 'https://kuna.io/documents/api', }, + 'api': { + 'public': { + 'get': [ + 'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest. + 'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator + 'k', // Get OHLC(k line) of specific market + 'markets', // Get all available markets + 'order_book', // Get the order book of specified market + 'order_book/{market}', + 'tickers', // Get ticker of all markets + 'tickers/{market}', // Get ticker of specific market + 'timestamp', // Get server current time, in seconds since Unix epoch + 'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order. + 'trades/{market}', + ], + }, + 'private': { + 'get': [ + 'members/me', // Get your profile and accounts info + 'deposits', // Get your deposits history + 'deposit', // Get details of specific deposit + 'deposit_address', // Where to deposit The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case. + 'orders', // Get your orders, results is paginated + 'order', // Get information of specified order + 'trades/my', // Get your executed trades Trades are sorted in reverse creation order. + 'withdraws', // Get your cryptocurrency withdraws + 'withdraw', // Get your cryptocurrency withdraw + ], + 'post': [ + 'orders', // Create a Sell/Buy order + 'orders/multi', // Create multiple sell/buy orders + 'orders/clear', // Cancel all my orders + 'order/delete', // Cancel an order + 'withdraw', // Create a withdraw + ], + }, + }, 'fees': { 'trading': { + 'tierBased': false, + 'percentage': true, 'taker': 0.25 / 100, 'maker': 0.25 / 100, }, @@ -56,9 +106,24 @@ module.exports = class kuna extends acx { }, }, }, + 'commonCurrencies': { + 'PLA': 'Plair', + }, + 'exceptions': { + '2002': InsufficientFunds, + '2003': OrderNotFound, + }, }); } + async fetchTime (params = {}) { + const response = await this.publicGetTimestamp (params); + // + // 1594911427 + // + return response * 1000; + } + async fetchMarkets (params = {}) { const quotes = [ 'btc', 'eth', 'eurs', 'rub', 'uah', 'usd', 'usdt', 'gol' ]; const pricePrecisions = { @@ -114,24 +179,100 @@ module.exports = class kuna extends acx { return markets; } - async fetchL3OrderBook (symbol, limit = undefined, params = {}) { - return await this.fetchOrderBook (symbol, limit, params); - } - - async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); - } + async fetchOrderBook (symbol, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); const request = { 'market': market['id'], }; - const response = await this.privateGetOrders (this.extend (request, params)); - // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder - // with order cache + fetchOpenOrders - // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX - return this.parseOrders (response, market, since, limit); + if (limit !== undefined) { + request['limit'] = limit; // default = 300 + } + const orderbook = await this.publicGetDepth (this.extend (request, params)); + const timestamp = this.safeTimestamp (orderbook, 'timestamp'); + return this.parseOrderBook (orderbook, timestamp); + } + + parseTicker (ticker, market = undefined) { + const timestamp = this.safeTimestamp (ticker, 'at'); + ticker = ticker['ticker']; + let symbol = undefined; + if (market) { + symbol = market['symbol']; + } + const last = this.safeNumber (ticker, 'last'); + return { + 'symbol': symbol, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'bidVolume': undefined, + 'ask': this.safeNumber (ticker, 'sell'), + 'askVolume': undefined, + 'vwap': undefined, + 'open': this.safeNumber (ticker, 'open'), + 'close': last, + 'last': last, + 'previousClose': undefined, + 'change': undefined, + 'percentage': undefined, + 'average': undefined, + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': undefined, + 'info': ticker, + }; + } + + async fetchTickers (symbols = undefined, params = {}) { + await this.loadMarkets (); + const response = await this.publicGetTickers (params); + const ids = Object.keys (response); + const result = {}; + for (let i = 0; i < ids.length; i++) { + const id = ids[i]; + let market = undefined; + let symbol = id; + if (id in this.markets_by_id) { + market = this.markets_by_id[id]; + symbol = market['symbol']; + } else { + let base = id.slice (0, 3); + let quote = id.slice (3, 6); + base = base.toUpperCase (); + quote = quote.toUpperCase (); + base = this.safeCurrencyCode (base); + quote = this.safeCurrencyCode (quote); + symbol = base + '/' + quote; + } + result[symbol] = this.parseTicker (response[id], market); + } + return this.filterByArray (result, 'symbol', symbols); + } + + async fetchTicker (symbol, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTickersMarket (this.extend (request, params)); + return this.parseTicker (response, market); + } + + async fetchL3OrderBook (symbol, limit = undefined, params = {}) { + return await this.fetchOrderBook (symbol, limit, params); + } + + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.publicGetTrades (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); } parseTrade (trade, market = undefined) { @@ -148,9 +289,14 @@ module.exports = class kuna extends acx { }; side = this.safeString (sideMap, side, side); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const orderId = this.safeString (trade, 'order_id'); const id = this.safeString (trade, 'id'); return { @@ -170,29 +316,6 @@ module.exports = class kuna extends acx { }; } - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.publicGetTrades (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - - async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { - if (symbol === undefined) { - throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); - } - await this.loadMarkets (); - const market = this.market (symbol); - const request = { - 'market': market['id'], - }; - const response = await this.privateGetTradesMy (this.extend (request, params)); - return this.parseTrades (response, market, since, limit); - } - async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const trades = await this.fetchTrades (symbol, since, limit, params); @@ -211,4 +334,198 @@ module.exports = class kuna extends acx { } return result; } + + async fetchBalance (params = {}) { + await this.loadMarkets (); + const response = await this.privateGetMembersMe (params); + const balances = this.safeValue (response, 'accounts'); + const result = { 'info': balances }; + for (let i = 0; i < balances.length; i++) { + const balance = balances[i]; + const currencyId = this.safeString (balance, 'currency'); + const code = this.safeCurrencyCode (currencyId); + const account = this.account (); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); + result[code] = account; + } + return this.parseBalance (result, false); + } + + async createOrder (symbol, type, side, amount, price = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'market': this.marketId (symbol), + 'side': side, + 'volume': amount.toString (), + 'ord_type': type, + }; + if (type === 'limit') { + request['price'] = price.toString (); + } + const response = await this.privatePostOrders (this.extend (request, params)); + const marketId = this.safeValue (response, 'market'); + const market = this.safeValue (this.markets_by_id, marketId); + return this.parseOrder (response, market); + } + + async cancelOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': id, + }; + const response = await this.privatePostOrderDelete (this.extend (request, params)); + const order = this.parseOrder (response); + const status = order['status']; + if (status === 'closed' || status === 'canceled') { + throw new OrderNotFound (this.id + ' ' + this.json (order)); + } + return order; + } + + parseOrderStatus (status) { + const statuses = { + 'done': 'closed', + 'wait': 'open', + 'cancel': 'canceled', + }; + return this.safeString (statuses, status, status); + } + + parseOrder (order, market = undefined) { + const marketId = this.safeString (order, 'market'); + const symbol = this.safeSymbol (marketId, market); + const timestamp = this.parse8601 (this.safeString (order, 'created_at')); + const status = this.parseOrderStatus (this.safeString (order, 'state')); + const type = this.safeString (order, 'type'); + const side = this.safeString (order, 'side'); + const id = this.safeString (order, 'id'); + return this.safeOrder ({ + 'id': id, + 'clientOrderId': undefined, + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'lastTradeTimestamp': undefined, + 'status': status, + 'symbol': symbol, + 'type': type, + 'timeInForce': undefined, + 'postOnly': undefined, + 'side': side, + 'price': this.safeNumber (order, 'price'), + 'stopPrice': undefined, + 'amount': this.safeNumber (order, 'volume'), + 'filled': this.safeNumber (order, 'executed_volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'trades': undefined, + 'fee': undefined, + 'info': order, + 'cost': undefined, + 'average': undefined, + }); + } + + async fetchOrder (id, symbol = undefined, params = {}) { + await this.loadMarkets (); + const request = { + 'id': parseInt (id), + }; + const response = await this.privateGetOrder (this.extend (request, params)); + return this.parseOrder (response); + } + + async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetOrders (this.extend (request, params)); + // todo emulation of fetchClosedOrders, fetchOrders, fetchOrder + // with order cache + fetchOpenOrders + // as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX + return this.parseOrders (response, market, since, limit); + } + + async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) { + if (symbol === undefined) { + throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument'); + } + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'market': market['id'], + }; + const response = await this.privateGetTradesMy (this.extend (request, params)); + return this.parseTrades (response, market, since, limit); + } + + nonce () { + return this.milliseconds (); + } + + encodeParams (params) { + if ('orders' in params) { + const orders = params['orders']; + let query = this.urlencode (this.keysort (this.omit (params, 'orders'))); + for (let i = 0; i < orders.length; i++) { + const order = orders[i]; + const keys = Object.keys (order); + for (let k = 0; k < keys.length; k++) { + const key = keys[k]; + const value = order[key]; + query += '&orders%5B%5D%5B' + key + '%5D=' + value.toString (); + } + } + return query; + } + return this.urlencode (this.keysort (params)); + } + + sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { + let request = '/api/' + this.version + '/' + this.implodeParams (path, params); + if ('extension' in this.urls) { + request += this.urls['extension']; + } + const query = this.omit (params, this.extractParams (path)); + let url = this.urls['api'] + request; + if (api === 'public') { + if (Object.keys (query).length) { + url += '?' + this.urlencode (query); + } + } else { + this.checkRequiredCredentials (); + const nonce = this.nonce ().toString (); + const query = this.encodeParams (this.extend ({ + 'access_key': this.apiKey, + 'tonce': nonce, + }, params)); + const auth = method + '|' + request + '|' + query; + const signed = this.hmac (this.encode (auth), this.encode (this.secret)); + const suffix = query + '&signature=' + signed; + if (method === 'GET') { + url += '?' + suffix; + } else { + body = suffix; + headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; + } + } + return { 'url': url, 'method': method, 'body': body, 'headers': headers }; + } + + handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) { + if (response === undefined) { + return; + } + if (code === 400) { + const error = this.safeValue (response, 'error'); + const errorCode = this.safeString (error, 'code'); + const feedback = this.id + ' ' + this.json (response); + this.throwExactlyMatchedException (this.exceptions, errorCode, feedback); + // fallback to default error handler + } + } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lakebtc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lakebtc.js index 8acd8cc41..991e6ff86 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lakebtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lakebtc.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, BadSymbol, InvalidOrder, InsufficientFunds } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -112,10 +113,10 @@ module.exports = class lakebtc extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balances, currencyId); + account['total'] = this.safeString (balances, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -133,16 +134,16 @@ module.exports = class lakebtc extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -152,7 +153,7 @@ module.exports = class lakebtc extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -183,14 +184,11 @@ module.exports = class lakebtc extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/latoken.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/latoken.js index 45cb5951d..ecc53a8c6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/latoken.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/latoken.js @@ -4,7 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, DDoSProtection, BadRequest, AuthenticationError } = require ('./base/errors'); -const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -85,6 +85,7 @@ module.exports = class latoken extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'maker': 0.1 / 100, @@ -169,7 +170,7 @@ module.exports = class latoken extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minQty'), + 'min': this.safeNumber (market, 'minQty'), 'max': undefined, }, 'price': { @@ -219,7 +220,7 @@ module.exports = class latoken extends Exchange { const numericId = this.safeInteger (currency, 'currencyId'); const code = this.safeCurrencyCode (id); const precision = this.safeInteger (currency, 'precission'); - const fee = this.safeFloat (currency, 'fee'); + const fee = this.safeNumber (currency, 'fee'); const active = undefined; result[code] = { 'id': id, @@ -253,27 +254,6 @@ module.exports = class latoken extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = amount * rate; - let precision = market['precision']['price']; - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - precision = market['precision']['amount']; - } - cost = this.decimalToPrecision (cost, ROUND, precision, this.precisionMode); - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (cost), - }; - } - async fetchBalance (params = {}) { await this.loadMarkets (); const response = await this.privateGetAccountBalances (params); @@ -297,17 +277,15 @@ module.exports = class latoken extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); - const frozen = this.safeFloat (balance, 'frozen'); - const pending = this.safeFloat (balance, 'pending'); - const used = this.sum (frozen, pending); - const account = { - 'free': this.safeFloat (balance, 'available'), - 'used': used, - 'total': this.safeFloat (balance, 'amount'), - }; + const frozen = this.safeString (balance, 'frozen'); + const pending = this.safeString (balance, 'pending'); + const account = this.account (); + account['used'] = Precise.stringAdd (frozen, pending); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -352,20 +330,20 @@ module.exports = class latoken extends Exchange { // const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const open = this.safeFloat (ticker, 'open'); - const close = this.safeFloat (ticker, 'close'); + const open = this.safeNumber (ticker, 'open'); + const close = this.safeNumber (ticker, 'close'); let change = undefined; if (open !== undefined && close !== undefined) { change = close - open; } - const percentage = this.safeFloat (ticker, 'priceChange'); + const percentage = this.safeNumber (ticker, 'priceChange'); const timestamp = this.nonce (); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'low': this.safeFloat (ticker, 'low'), - 'high': this.safeFloat (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -379,7 +357,7 @@ module.exports = class latoken extends Exchange { 'percentage': percentage, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -463,22 +441,19 @@ module.exports = class latoken extends Exchange { timestamp *= 1000; } } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'orderId'); - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -613,29 +588,17 @@ module.exports = class latoken extends Exchange { const symbol = this.safeSymbol (marketId, market); const side = this.safeString (order, 'side'); const type = this.safeString (order, 'orderType'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - const filled = this.safeFloat (order, 'executedAmount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); + const filled = this.safeNumber (order, 'executedAmount'); const status = this.parseOrderStatus (this.safeString (order, 'orderStatus')); - let cost = undefined; - if (filled !== undefined) { - if (price !== undefined) { - cost = filled * price; - } - } const timeFilled = this.safeTimestamp (order, 'timeFilled'); let lastTradeTimestamp = undefined; if ((timeFilled !== undefined) && (timeFilled > 0)) { lastTradeTimestamp = timeFilled; } const clientOrderId = this.safeString (order, 'cliOrdId'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -650,14 +613,14 @@ module.exports = class latoken extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, 'average': undefined, - 'remaining': remaining, + 'remaining': undefined, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lbank.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lbank.js index 9b39a0236..e9e4658dc 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lbank.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lbank.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, DDoSProtection, AuthenticationError, InvalidOrder, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -201,8 +202,8 @@ module.exports = class lbank extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const info = ticker; ticker = info['ticker']; - const last = this.safeFloat (ticker, 'latest'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'latest'); + const percentage = this.safeNumber (ticker, 'change'); let open = undefined; if (percentage !== undefined) { const relativeChange = this.sum (1, percentage / 100); @@ -223,8 +224,8 @@ module.exports = class lbank extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -237,8 +238,8 @@ module.exports = class lbank extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'vol'), - 'quoteVolume': this.safeFloat (ticker, 'turnover'), + 'baseVolume': this.safeNumber (ticker, 'vol'), + 'quoteVolume': this.safeNumber (ticker, 'turnover'), 'info': info, }; } @@ -288,17 +289,15 @@ module.exports = class lbank extends Exchange { symbol = market['symbol']; } const timestamp = this.safeInteger (trade, 'date_ms'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = parseFloat (this.costToPrecision (symbol, price * amount)); - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'tid'); const type = undefined; - const side = this.safeString (trade, 'type'); + let side = this.safeString (trade, 'type'); + side = side.replace ('_market', ''); return { 'id': id, 'info': this.safeValue (trade, 'info', trade), @@ -346,11 +345,11 @@ module.exports = class lbank extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -415,12 +414,12 @@ module.exports = class lbank extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['used'] = this.safeFloat (freeze, currencyId); - account['total'] = this.safeFloat (asset, currencyId); + account['free'] = this.safeString (free, currencyId); + account['used'] = this.safeString (freeze, currencyId); + account['total'] = this.safeString (asset, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -448,35 +447,20 @@ module.exports = class lbank extends Exchange { // "status":2 // } // - let symbol = undefined; - const responseMarket = this.safeValue (this.marketsById, order['symbol']); - if (responseMarket !== undefined) { - symbol = responseMarket['symbol']; - } else if (market !== undefined) { - symbol = market['symbol']; - } + const marketId = this.safeString (order, 'symbol'); + const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeInteger (order, 'create_time'); // Limit Order Request Returns: Order Price // Market Order Returns: cny amount of market order - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount', 0.0); - const filled = this.safeFloat (order, 'deal_amount', 0.0); - const av_price = this.safeFloat (order, 'avg_price'); - let cost = undefined; - if (av_price !== undefined) { - cost = filled * av_price; - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount', 0.0); + const filled = this.safeNumber (order, 'deal_amount', 0.0); + const average = this.safeNumber (order, 'avg_price'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const id = this.safeString (order, 'order_id'); const type = this.safeString (order, 'order_type'); const side = this.safeString (order, 'type'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -490,15 +474,15 @@ module.exports = class lbank extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': undefined, 'info': this.safeValue (order, 'info', order), - 'average': undefined, - }; + 'average': average, + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/liquid.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/liquid.js index 732eda853..0365ef102 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/liquid.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/liquid.js @@ -4,7 +4,8 @@ const Exchange = require ('./base/Exchange'); const { TICK_SIZE } = require ('./base/functions/number'); -const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported } = require ('./base/errors'); +const { ExchangeError, ArgumentsRequired, InvalidNonce, OrderNotFound, InvalidOrder, InsufficientFunds, AuthenticationError, DDoSProtection, NotSupported, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -108,7 +109,7 @@ module.exports = class liquid extends Exchange { 'trading': { 'tierBased': true, 'percentage': true, - 'taker': 0.0015, + 'taker': 0.0030, 'maker': 0.0000, 'tiers': { 'perpetual': { @@ -127,48 +128,52 @@ module.exports = class liquid extends Exchange { [ 300000000, -0.00025 ], ], 'taker': [ - [ 0, 0.000600 ], - [ 25000, 0.000575 ], - [ 50000, 0.000550 ], - [ 100000, 0.000525 ], - [ 1000000, 0.000500 ], - [ 10000000, 0.000475 ], - [ 25000000, 0.000450 ], - [ 50000000, 0.000425 ], - [ 75000000, 0.000400 ], - [ 100000000, 0.000375 ], - [ 200000000, 0.000350 ], - [ 300000000, 0.000325 ], + [ 0, 0.00120 ], + [ 25000, 0.00115 ], + [ 50000, 0.00110 ], + [ 100000, 0.00105 ], + [ 1000000, 0.00100 ], + [ 10000000, 0.00095 ], + [ 25000000, 0.00090 ], + [ 50000000, 0.00085 ], + [ 75000000, 0.00080 ], + [ 100000000, 0.00075 ], + [ 200000000, 0.00070 ], + [ 300000000, 0.00065 ], ], }, 'spot': { 'taker': [ - [ 0, 0.0015 ], - [ 10000, 0.0015 ], - [ 20000, 0.0014 ], - [ 50000, 0.0013 ], - [ 100000, 0.0010 ], - [ 1000000, 0.0008 ], - [ 5000000, 0.0006 ], - [ 10000000, 0.0005 ], - [ 25000000, 0.0005 ], - [ 50000000, 0.00045 ], - [ 100000000, 0.0004 ], - [ 200000000, 0.0003 ], + [ 0, 0.003 ], + [ 10000, 0.0029 ], + [ 20000, 0.0028 ], + [ 50000, 0.0026 ], + [ 100000, 0.0020 ], + [ 1000000, 0.0016 ], + [ 5000000, 0.0012 ], + [ 10000000, 0.0010 ], + [ 25000000, 0.0009 ], + [ 50000000, 0.0008 ], + [ 100000000, 0.0007 ], + [ 200000000, 0.0006 ], + [ 500000000, 0.0004 ], + [ 1000000000, 0.0003 ], ], 'maker': [ [ 0, 0.0000 ], - [ 10000, 0.0015 ], - [ 20000, 0.1400 ], - [ 50000, 0.1300 ], - [ 100000, 0.0800 ], - [ 1000000, 0.0004 ], - [ 5000000, 0.00035 ], - [ 10000000, 0.00025 ], + [ 10000, 0.0020 ], + [ 20000, 0.0019 ], + [ 50000, 0.0018 ], + [ 100000, 0.0016 ], + [ 1000000, 0.0008 ], + [ 5000000, 0.0007 ], + [ 10000000, 0.0005 ], [ 25000000, 0.0000 ], [ 50000000, 0.0000 ], [ 100000000, 0.0000 ], [ 200000000, 0.0000 ], + [ 500000000, 0.0000 ], + [ 1000000000, 0.0000 ], ], }, }, @@ -187,6 +192,7 @@ module.exports = class liquid extends Exchange { 'less_than_order_size': InvalidOrder, 'price_too_high': InvalidOrder, 'price_too_small': InvalidOrder, // {"errors":{"order":["price_too_small"]}} + 'product_disabled': BadSymbol, // {"errors":{"order":["product_disabled"]}} }, 'commonCurrencies': { 'WIN': 'WCOIN', @@ -236,7 +242,7 @@ module.exports = class liquid extends Exchange { 'info': currency, 'name': code, 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': decimalPrecision, 'limits': { 'amount': { @@ -252,7 +258,7 @@ module.exports = class liquid extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal'), + 'min': this.safeNumber (currency, 'minimum_withdrawal'), 'max': undefined, }, }, @@ -377,19 +383,19 @@ module.exports = class liquid extends Exchange { let maker = this.fees['trading']['maker']; let taker = this.fees['trading']['taker']; if (type === 'swap') { - maker = this.safeFloat (market, 'maker_fee', this.fees['trading']['maker']); - taker = this.safeFloat (market, 'taker_fee', this.fees['trading']['taker']); + maker = this.safeNumber (market, 'maker_fee', this.fees['trading']['maker']); + taker = this.safeNumber (market, 'taker_fee', this.fees['trading']['taker']); } const disabled = this.safeValue (market, 'disabled', false); const active = !disabled; const baseCurrency = this.safeValue (currenciesByCode, base); const precision = { 'amount': 0.00000001, - 'price': this.safeFloat (market, 'tick_size'), + 'price': this.safeNumber (market, 'tick_size'), }; let minAmount = undefined; if (baseCurrency !== undefined) { - minAmount = this.safeFloat (baseCurrency['info'], 'minimum_order_quantity'); + minAmount = this.safeNumber (baseCurrency['info'], 'minimum_order_quantity'); } const limits = { 'amount': { @@ -471,8 +477,8 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } for (let i = 0; i < fiat.length; i++) { @@ -480,11 +486,11 @@ module.exports = class liquid extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'reserved_balance'); + account['total'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'reserved_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -503,7 +509,7 @@ module.exports = class liquid extends Exchange { if (ticker['last_traded_price']) { const length = ticker['last_traded_price'].length; if (length > 0) { - last = this.safeFloat (ticker, 'last_traded_price'); + last = this.safeNumber (ticker, 'last_traded_price'); } } } @@ -528,7 +534,7 @@ module.exports = class liquid extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.safeFloat (ticker, 'last_price_24h'); + const open = this.safeNumber (ticker, 'last_price_24h'); if (open !== undefined && last !== undefined) { change = last - open; average = this.sum (last, open) / 2; @@ -540,11 +546,11 @@ module.exports = class liquid extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_market_ask'), - 'low': this.safeFloat (ticker, 'low_market_bid'), - 'bid': this.safeFloat (ticker, 'market_bid'), + 'high': this.safeNumber (ticker, 'high_market_ask'), + 'low': this.safeNumber (ticker, 'low_market_bid'), + 'bid': this.safeNumber (ticker, 'market_bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'market_ask'), + 'ask': this.safeNumber (ticker, 'market_ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -554,7 +560,7 @@ module.exports = class liquid extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'volume_24h'), 'quoteVolume': undefined, 'info': ticker, }; @@ -600,14 +606,11 @@ module.exports = class liquid extends Exchange { if (mySide !== undefined) { takerOrMaker = (takerSide === mySide) ? 'taker' : 'maker'; } - let cost = undefined; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); let symbol = undefined; if (market !== undefined) { @@ -810,9 +813,9 @@ module.exports = class liquid extends Exchange { const marketId = this.safeString (order, 'product_id'); market = this.safeValue (this.markets_by_id, marketId); const status = this.parseOrderStatus (this.safeString (order, 'status')); - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'filled_quantity'); - const price = this.safeFloat (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + let filled = this.safeNumber (order, 'filled_quantity'); + const price = this.safeNumber (order, 'price'); let symbol = undefined; let feeCurrency = undefined; if (market !== undefined) { @@ -822,7 +825,7 @@ module.exports = class liquid extends Exchange { const type = this.safeString (order, 'order_type'); let tradeCost = 0; let tradeFilled = 0; - let average = this.safeFloat (order, 'average_price'); + let average = this.safeNumber (order, 'average_price'); const trades = this.parseTrades (this.safeValue (order, 'executions', []), market, undefined, undefined, { 'order': orderId, 'type': type, @@ -879,7 +882,7 @@ module.exports = class liquid extends Exchange { 'trades': trades, 'fee': { 'currency': feeCurrency, - 'cost': this.safeFloat (order, 'order_fee'), + 'cost': this.safeNumber (order, 'order_fee'), }, 'info': order, }; @@ -1034,7 +1037,7 @@ module.exports = class liquid extends Exchange { const updated = this.safeTimestamp (transaction, 'updated_at'); const type = 'withdrawal'; const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); return { 'info': transaction, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/luno.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/luno.js index 2bbec0ec1..ad5568218 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/luno.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/luno.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -79,6 +80,10 @@ module.exports = class luno extends Exchange { 'quotes/{id}', 'withdrawals', 'withdrawals/{id}', + 'transfers', + // GET /api/exchange/2/listorders + // GET /api/exchange/2/orders/{id} + // GET /api/exchange/3/order ], 'post': [ 'accounts', @@ -153,12 +158,12 @@ module.exports = class luno extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_volume'), - 'max': this.safeFloat (market, 'max_volume'), + 'min': this.safeNumber (market, 'min_volume'), + 'max': this.safeNumber (market, 'max_volume'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { 'min': undefined, @@ -209,20 +214,22 @@ module.exports = class luno extends Exchange { const wallet = wallets[i]; const currencyId = this.safeString (wallet, 'asset'); const code = this.safeCurrencyCode (currencyId); - const reserved = this.safeFloat (wallet, 'reserved'); - const unconfirmed = this.safeFloat (wallet, 'unconfirmed'); - const balance = this.safeFloat (wallet, 'balance'); + const reserved = this.safeString (wallet, 'reserved'); + const unconfirmed = this.safeString (wallet, 'unconfirmed'); + const balance = this.safeString (wallet, 'balance'); + const reservedUnconfirmed = Precise.stringAdd (reserved, unconfirmed); + const balanceUnconfirmed = Precise.stringAdd (balance, unconfirmed); if (code in result) { - result[code]['used'] = this.sum (result[code]['used'], reserved, unconfirmed); - result[code]['total'] = this.sum (result[code]['total'], balance, unconfirmed); + result[code]['used'] = Precise.stringAdd (result[code]['used'], reservedUnconfirmed); + result[code]['total'] = Precise.stringAdd (result[code]['total'], balanceUnconfirmed); } else { const account = this.account (); - account['used'] = this.sum (reserved, unconfirmed); - account['total'] = this.sum (balance, unconfirmed); + account['used'] = reservedUnconfirmed; + account['total'] = balanceUnconfirmed; result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -273,18 +280,12 @@ module.exports = class luno extends Exchange { const side = (order['type'] === 'ASK') ? 'sell' : 'buy'; const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'limit_price'); - const amount = this.safeFloat (order, 'limit_volume'); - const quoteFee = this.safeFloat (order, 'fee_counter'); - const baseFee = this.safeFloat (order, 'fee_base'); - const filled = this.safeFloat (order, 'base'); - const cost = this.safeFloat (order, 'counter'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } + const price = this.safeNumber (order, 'limit_price'); + const amount = this.safeNumber (order, 'limit_volume'); + const quoteFee = this.safeNumber (order, 'fee_counter'); + const baseFee = this.safeNumber (order, 'fee_base'); + const filled = this.safeNumber (order, 'base'); + const cost = this.safeNumber (order, 'counter'); const fee = { 'currency': undefined }; if (quoteFee) { fee['cost'] = quoteFee; @@ -298,7 +299,7 @@ module.exports = class luno extends Exchange { } } const id = this.safeString (order, 'order_id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'datetime': this.iso8601 (timestamp), @@ -315,12 +316,12 @@ module.exports = class luno extends Exchange { 'amount': amount, 'filled': filled, 'cost': cost, - 'remaining': remaining, + 'remaining': undefined, 'trades': undefined, 'fee': fee, 'info': order, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -366,16 +367,16 @@ module.exports = class luno extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last_trade'); + const last = this.safeNumber (ticker, 'last_trade'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -385,7 +386,7 @@ module.exports = class luno extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'rolling_24_hour_volume'), + 'baseVolume': this.safeNumber (ticker, 'rolling_24_hour_volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -436,8 +437,8 @@ module.exports = class luno extends Exchange { } else { side = trade['is_buy'] ? 'buy' : 'sell'; } - const feeBase = this.safeFloat (trade, 'fee_base'); - const feeCounter = this.safeFloat (trade, 'fee_counter'); + const feeBase = this.safeNumber (trade, 'fee_base'); + const feeCounter = this.safeNumber (trade, 'fee_counter'); let feeCurrency = undefined; let feeCost = undefined; if (feeBase !== undefined) { @@ -462,10 +463,10 @@ module.exports = class luno extends Exchange { 'type': undefined, 'side': side, 'takerOrMaker': takerOrMaker, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), // Does not include potential fee costs - 'cost': this.safeFloat (trade, 'counter'), + 'cost': this.safeNumber (trade, 'counter'), 'fee': { 'cost': feeCost, 'currency': feeCurrency, @@ -512,8 +513,8 @@ module.exports = class luno extends Exchange { const response = await this.privateGetFeeInfo (params); return { 'info': response, - 'maker': this.safeFloat (response, 'maker_fee'), - 'taker': this.safeFloat (response, 'taker_fee'), + 'maker': this.safeNumber (response, 'maker_fee'), + 'taker': this.safeNumber (response, 'taker_fee'), }; } @@ -647,9 +648,9 @@ module.exports = class luno extends Exchange { const timestamp = this.safeValue (entry, 'timestamp'); const currencyId = this.safeString (entry, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); - const available_delta = this.safeFloat (entry, 'available_delta'); - const balance_delta = this.safeFloat (entry, 'balance_delta'); - const after = this.safeFloat (entry, 'balance'); + const available_delta = this.safeNumber (entry, 'available_delta'); + const balance_delta = this.safeNumber (entry, 'balance_delta'); + const after = this.safeNumber (entry, 'balance'); const comment = this.safeString (entry, 'description'); let before = after; let amount = 0.0; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lykke.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lykke.js index edc0fe73a..707034d20 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lykke.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/lykke.js @@ -3,6 +3,7 @@ // --------------------------------------------------------------------------- const Exchange = require ('./base/Exchange'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -184,18 +185,16 @@ module.exports = class lykke extends Exchange { const id = this.safeString2 (trade, 'id', 'Id'); const orderId = this.safeString (trade, 'OrderId'); const timestamp = this.parse8601 (this.safeString2 (trade, 'dateTime', 'DateTime')); - const price = this.safeFloat2 (trade, 'price', 'Price'); - let amount = this.safeFloat2 (trade, 'volume', 'Amount'); + const priceString = this.safeString2 (trade, 'price', 'Price'); + let amountString = this.safeString2 (trade, 'volume', 'Amount'); let side = this.safeStringLower (trade, 'action'); if (side === undefined) { - if (amount < 0) { - side = 'sell'; - } else { - side = 'buy'; - } + side = (amountString[0] === '-') ? 'sell' : 'buy'; } - amount = Math.abs (amount); - const cost = price * amount; + amountString = (amountString[0] === '-') ? amountString.slice (1) : amountString; + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const fee = { 'cost': 0, // There are no fees for trading. https://www.lykke.com/wallet-fees-and-limits/ 'currency': market['quote'], @@ -256,11 +255,11 @@ module.exports = class lykke extends Exchange { const currencyId = this.safeString (balance, 'AssetId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Balance'); - account['used'] = this.safeFloat (balance, 'Reserved'); + account['total'] = this.safeString (balance, 'Balance'); + account['used'] = this.safeString (balance, 'Reserved'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -307,7 +306,7 @@ module.exports = class lykke extends Exchange { // } // const id = this.safeString (result, 'Id'); - price = this.safeFloat (result, 'Price'); + price = this.safeNumber (result, 'Price'); return { 'id': id, 'info': result, @@ -398,16 +397,16 @@ module.exports = class lykke extends Exchange { if (market) { symbol = market['symbol']; } - const close = this.safeFloat (ticker, 'lastPrice'); + const close = this.safeNumber (ticker, 'lastPrice'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'bid'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -418,7 +417,7 @@ module.exports = class lykke extends Exchange { 'percentage': undefined, 'average': undefined, 'baseVolume': undefined, - 'quoteVolume': this.safeFloat (ticker, 'volume24H'), + 'quoteVolume': this.safeNumber (ticker, 'volume24H'), 'info': ticker, }; } @@ -476,20 +475,18 @@ module.exports = class lykke extends Exchange { } else if (('CreatedAt' in order) && (order['CreatedAt'])) { timestamp = this.parse8601 (order['CreatedAt']); } - const price = this.safeFloat (order, 'Price'); + const price = this.safeNumber (order, 'Price'); let side = undefined; - let amount = this.safeFloat (order, 'Volume'); + let amount = this.safeNumber (order, 'Volume'); if (amount < 0) { side = 'sell'; amount = Math.abs (amount); } else { side = 'buy'; } - const remaining = Math.abs (this.safeFloat (order, 'RemainingVolume')); - const filled = amount - remaining; - const cost = filled * price; + const remaining = Math.abs (this.safeNumber (order, 'RemainingVolume')); const id = this.safeString (order, 'Id'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -503,15 +500,15 @@ module.exports = class lykke extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'amount': amount, - 'filled': filled, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -572,8 +569,8 @@ module.exports = class lykke extends Exchange { } parseBidAsk (bidask, priceKey = 0, amountKey = 1) { - const price = this.safeFloat (bidask, priceKey); - let amount = this.safeFloat (bidask, amountKey); + const price = this.safeNumber (bidask, priceKey); + let amount = this.safeNumber (bidask, amountKey); if (amount < 0) { amount = -amount; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mercado.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mercado.js index a2fd9593e..2746e14b8 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mercado.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mercado.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -160,7 +161,7 @@ module.exports = class mercado extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, baseId), + 'min': this.safeNumber (amountLimits, baseId), 'max': undefined, }, 'price': { @@ -196,16 +197,16 @@ module.exports = class mercado extends Exchange { const response = await this.publicGetCoinTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'ticker', {}); const timestamp = this.safeTimestamp (ticker, 'date'); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -215,7 +216,7 @@ module.exports = class mercado extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -230,15 +231,12 @@ module.exports = class mercado extends Exchange { const id = this.safeString2 (trade, 'tid', 'operation_id'); const type = undefined; const side = this.safeString (trade, 'type'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } - const feeCost = this.safeFloat (trade, 'fee_rate'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const feeCost = this.safeNumber (trade, 'fee_rate'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -295,12 +293,12 @@ module.exports = class mercado extends Exchange { if (currencyId in balances) { const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['total'] = this.safeFloat (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -407,32 +405,31 @@ module.exports = class mercado extends Exchange { // } // const id = this.safeString (order, 'order_id'); + const order_type = this.safeString (order, 'order_type'); let side = undefined; if ('order_type' in order) { - side = (order['order_type'] === 1) ? 'buy' : 'sell'; + side = (order_type === '1') ? 'buy' : 'sell'; } const status = this.parseOrderStatus (this.safeString (order, 'status')); const marketId = this.safeString (order, 'coin_pair'); market = this.safeMarket (marketId, market); const timestamp = this.safeTimestamp (order, 'created_timestamp'); const fee = { - 'cost': this.safeFloat (order, 'fee'), + 'cost': this.safeNumber (order, 'fee'), 'currency': market['quote'], }; - const price = this.safeFloat (order, 'limit_price'); - // price = this.safeFloat (order, 'executed_price_avg', price); - const average = this.safeFloat (order, 'executed_price_avg'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'executed_quantity'); - const remaining = amount - filled; - const cost = filled * average; + const price = this.safeNumber (order, 'limit_price'); + // price = this.safeNumber (order, 'executed_price_avg', price); + const average = this.safeNumber (order, 'executed_price_avg'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const lastTradeTimestamp = this.safeTimestamp (order, 'updated_timestamp'); const rawTrades = this.safeValue (order, 'operations', []); const trades = this.parseTrades (rawTrades, market, undefined, undefined, { 'side': side, 'order': id, }); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -446,15 +443,15 @@ module.exports = class mercado extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'average': average, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': trades, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { @@ -512,11 +509,11 @@ module.exports = class mercado extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeTimestamp (ohlcv, 'timestamp'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mixcoins.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mixcoins.js index 85138f138..11bbf93b6 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mixcoins.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/mixcoins.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -72,11 +73,11 @@ module.exports = class mixcoins extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (balances, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'avail'); - account['used'] = this.safeFloat (balance, 'lock'); + account['free'] = this.safeString (balance, 'avail'); + account['used'] = this.safeString (balance, 'lock'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -96,16 +97,16 @@ module.exports = class mixcoins extends Exchange { const response = await this.publicGetTicker (this.extend (request, params)); const ticker = this.safeValue (response, 'result'); const timestamp = this.milliseconds (); - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -115,7 +116,7 @@ module.exports = class mixcoins extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -128,14 +129,11 @@ module.exports = class mixcoins extends Exchange { symbol = market['symbol']; } const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'id': id, 'info': trade, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ndax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ndax.js index 0367c2695..37e8b2760 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ndax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ndax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, AuthenticationError, InsufficientFunds, BadSymbol, OrderNotFound } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -244,7 +245,7 @@ module.exports = class ndax extends Exchange { const name = this.safeString (currency, 'ProductFullName'); const type = this.safeString (currency, 'ProductType'); const code = this.safeCurrencyCode (this.safeString (currency, 'Product')); - const precision = this.safeFloat (currency, 'TickSize'); + const precision = this.safeNumber (currency, 'TickSize'); const isDisabled = this.safeValue (currency, 'IsDisabled'); const active = !isDisabled; result[code] = { @@ -325,8 +326,8 @@ module.exports = class ndax extends Exchange { const quote = this.safeCurrencyCode (this.safeString (market, 'Product2Symbol')); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'QuantityIncrement'), - 'price': this.safeFloat (market, 'PriceIncrement'), + 'amount': this.safeNumber (market, 'QuantityIncrement'), + 'price': this.safeNumber (market, 'PriceIncrement'), }; const sessionStatus = this.safeString (market, 'SessionStatus'); const isDisable = this.safeValue (market, 'IsDisable'); @@ -344,11 +345,11 @@ module.exports = class ndax extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'MinimumQuantity'), + 'min': this.safeNumber (market, 'MinimumQuantity'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'MinimumPrice'), + 'min': this.safeNumber (market, 'MinimumPrice'), 'max': undefined, }, 'cost': { @@ -469,27 +470,27 @@ module.exports = class ndax extends Exchange { const timestamp = this.safeInteger (ticker, 'TimeStamp'); const marketId = this.safeString (ticker, 'InstrumentId'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'LastTradedPx'); - const percentage = this.safeFloat (ticker, 'Rolling24HrPxChangePercent'); - const change = this.safeFloat (ticker, 'Rolling24HrPxChange'); - const open = this.safeFloat (ticker, 'SessionOpen'); + const last = this.safeNumber (ticker, 'LastTradedPx'); + const percentage = this.safeNumber (ticker, 'Rolling24HrPxChangePercent'); + const change = this.safeNumber (ticker, 'Rolling24HrPxChange'); + const open = this.safeNumber (ticker, 'SessionOpen'); let average = undefined; if ((last !== undefined) && (change !== undefined)) { average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'Rolling24HrVolume'); - const quoteVolume = this.safeFloat (ticker, 'Rolling24HrNotional'); + const baseVolume = this.safeNumber (ticker, 'Rolling24HrVolume'); + const quoteVolume = this.safeNumber (ticker, 'Rolling24HrNotional'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'SessionHigh'), - 'low': this.safeFloat (ticker, 'SessionLow'), - 'bid': this.safeFloat (ticker, 'BestBid'), - 'bidVolume': undefined, // this.safeFloat (ticker, 'BidQty'), always shows 0 - 'ask': this.safeFloat (ticker, 'BestOffer'), - 'askVolume': undefined, // this.safeFloat (ticker, 'AskQty'), always shows 0 + 'high': this.safeNumber (ticker, 'SessionHigh'), + 'low': this.safeNumber (ticker, 'SessionLow'), + 'bid': this.safeNumber (ticker, 'BestBid'), + 'bidVolume': undefined, // this.safeNumber (ticker, 'BidQty'), always shows 0 + 'ask': this.safeNumber (ticker, 'BestOffer'), + 'askVolume': undefined, // this.safeNumber (ticker, 'AskQty'), always shows 0 'vwap': vwap, 'open': open, 'close': last, @@ -562,11 +563,11 @@ module.exports = class ndax extends Exchange { // return [ this.safeInteger (ohlcv, 0), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -714,8 +715,8 @@ module.exports = class ndax extends Exchange { // "OMSId":1 // } // - let price = undefined; - let amount = undefined; + let priceString = undefined; + let amountString = undefined; let cost = undefined; let timestamp = undefined; let id = undefined; @@ -726,11 +727,8 @@ module.exports = class ndax extends Exchange { let fee = undefined; let type = undefined; if (Array.isArray (trade)) { - price = this.safeFloat (trade, 3); - amount = this.safeFloat (trade, 2); - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + priceString = this.safeString (trade, 3); + amountString = this.safeString (trade, 2); timestamp = this.safeInteger (trade, 6); id = this.safeString (trade, 0); marketId = this.safeInteger (trade, 1); @@ -742,13 +740,13 @@ module.exports = class ndax extends Exchange { id = this.safeString (trade, 'TradeId'); orderId = this.safeString2 (trade, 'OrderId', 'OrigOrderId'); marketId = this.safeString2 (trade, 'InstrumentId', 'Instrument'); - price = this.safeFloat (trade, 'Price'); - amount = this.safeFloat (trade, 'Quantity'); - cost = this.safeFloat2 (trade, 'Value', 'GrossValueExecuted'); + priceString = this.safeString (trade, 'Price'); + amountString = this.safeString (trade, 'Quantity'); + cost = this.safeNumber2 (trade, 'Value', 'GrossValueExecuted'); takerOrMaker = this.safeStringLower (trade, 'MakerTaker'); side = this.safeStringLower (trade, 'Side'); type = this.safeStringLower (trade, 'OrderType'); - const feeCost = this.safeFloat (trade, 'Fee'); + const feeCost = this.safeNumber (trade, 'Fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'FeeProductId'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -758,6 +756,11 @@ module.exports = class ndax extends Exchange { }; } } + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const symbol = this.safeSymbol (marketId, market); return { 'info': trade, @@ -872,11 +875,11 @@ module.exports = class ndax extends Exchange { const currencyId = this.safeString (balance, 'ProductId'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'Amount'); - account['used'] = this.safeFloat (balance, 'Hold'); + account['total'] = this.safeString (balance, 'Amount'); + account['used'] = this.safeString (balance, 'Hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseLedgerEntryType (type) { @@ -922,8 +925,8 @@ module.exports = class ndax extends Exchange { const type = this.parseLedgerEntryType (this.safeString (item, 'ReferenceType')); const currencyId = this.safeString (item, 'ProductId'); const code = this.safeCurrencyCode (currencyId, currency); - const credit = this.safeFloat (item, 'CR'); - const debit = this.safeFloat (item, 'DR'); + const credit = this.safeNumber (item, 'CR'); + const debit = this.safeNumber (item, 'DR'); let amount = undefined; let direction = undefined; if (credit > 0) { @@ -935,7 +938,7 @@ module.exports = class ndax extends Exchange { } const timestamp = this.safeInteger (item, 'TimeStamp'); let before = undefined; - const after = this.safeFloat (item, 'Balance'); + const after = this.safeNumber (item, 'Balance'); if (direction === 'out') { before = this.sum (after, amount); } else if (direction === 'in') { @@ -1083,36 +1086,26 @@ module.exports = class ndax extends Exchange { // const id = this.safeString2 (order, 'ReplacementOrderId', 'OrderId'); const timestamp = this.safeInteger (order, 'ReceiveTime'); - let lastTradeTimestamp = undefined; + const lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); const marketId = this.safeString (order, 'Instrument'); const symbol = this.safeSymbol (marketId, market); const side = this.safeStringLower (order, 'Side'); const type = this.safeStringLower (order, 'OrderType'); const clientOrderId = this.safeString2 (order, 'ReplacementClOrdId', 'ClientOrderId'); - let price = this.safeFloat (order, 'Price', 0.0); + let price = this.safeNumber (order, 'Price', 0.0); price = (price > 0.0) ? price : undefined; - const amount = this.safeFloat (order, 'OrigQuantity'); - const filled = this.safeFloat (order, 'QuantityExecuted'); - const cost = this.safeFloat (order, 'GrossValueExecuted'); - let remaining = undefined; - let average = undefined; - if (filled !== undefined) { - if (amount !== undefined) { - remaining = Math.max (0, amount - filled); - } - if (filled > 0) { - lastTradeTimestamp = this.safeInteger (order, 'LastUpdatedTime'); - average = this.safeFloat (order, 'AvgPrice', 0.0); - average = (average > 0) ? average : undefined; - } - } - let stopPrice = this.safeFloat (order, 'StopPrice', 0.0); + const amount = this.safeNumber (order, 'OrigQuantity'); + const filled = this.safeNumber (order, 'QuantityExecuted'); + const cost = this.safeNumber (order, 'GrossValueExecuted'); + let average = this.safeNumber (order, 'AvgPrice', 0.0); + average = (average > 0) ? average : undefined; + let stopPrice = this.safeNumber (order, 'StopPrice', 0.0); stopPrice = (stopPrice > 0.0) ? stopPrice : undefined; const timeInForce = undefined; const status = this.parseOrderStatus (this.safeString (order, 'OrderState')); const fee = undefined; const trades = undefined; - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -1131,10 +1124,10 @@ module.exports = class ndax extends Exchange { 'amount': amount, 'filled': filled, 'average': average, - 'remaining': remaining, + 'remaining': undefined, 'fee': fee, 'trades': trades, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1932,8 +1925,8 @@ module.exports = class ndax extends Exchange { } const addressTo = address; const status = this.parseTransactionStatusByType (this.safeString (transaction, 'TicketStatus'), type); - const amount = this.safeFloat (transaction, 'Amount'); - const feeCost = this.safeFloat (transaction, 'FeeAmount'); + const amount = this.safeNumber (transaction, 'Amount'); + const feeCost = this.safeNumber (transaction, 'FeeAmount'); let fee = undefined; if (feeCost !== undefined) { fee = { 'currency': code, 'cost': feeCost }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/novadax.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/novadax.js index dfc6569d2..76f763414 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/novadax.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/novadax.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, PermissionDenied, BadRequest, CancelPending, OrderNotFound, InsufficientFunds, RateLimitExceeded, InvalidOrder, AccountSuspended, BadSymbol, OnMaintenance } = require ('./base/errors'); const { TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -197,7 +198,7 @@ module.exports = class novadax extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'minOrderAmount'), + 'min': this.safeNumber (market, 'minOrderAmount'), 'max': undefined, }, 'price': { @@ -205,7 +206,7 @@ module.exports = class novadax extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minOrderValue'), + 'min': this.safeNumber (market, 'minOrderValue'), 'max': undefined, }, }; @@ -247,8 +248,8 @@ module.exports = class novadax extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const open = this.safeFloat (ticker, 'open24h'); - const last = this.safeFloat (ticker, 'lastPrice'); + const open = this.safeNumber (ticker, 'open24h'); + const last = this.safeNumber (ticker, 'lastPrice'); let percentage = undefined; let change = undefined; let average = undefined; @@ -257,18 +258,18 @@ module.exports = class novadax extends Exchange { percentage = change / open * 100; average = this.sum (last, open) / 2; } - const baseVolume = this.safeFloat (ticker, 'baseVolume24h'); - const quoteVolume = this.safeFloat (ticker, 'quoteVolume24h'); + const baseVolume = this.safeNumber (ticker, 'baseVolume24h'); + const quoteVolume = this.safeNumber (ticker, 'quoteVolume24h'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24h'), - 'low': this.safeFloat (ticker, 'low24h'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high24h'), + 'low': this.safeNumber (ticker, 'low24h'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -424,11 +425,13 @@ module.exports = class novadax extends Exchange { const orderId = this.safeString (trade, 'orderId'); const timestamp = this.safeInteger (trade, 'timestamp'); const side = this.safeStringLower (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = this.safeFloat (trade, 'volume'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - cost = amount * price; + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'volume'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); @@ -440,7 +443,7 @@ module.exports = class novadax extends Exchange { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); fee = { - 'cost': this.safeFloat (parts, 0), + 'cost': this.safeNumber (parts, 0), 'currency': feeCurrencyCode, }; } @@ -548,11 +551,11 @@ module.exports = class novadax extends Exchange { const volumeField = this.safeString (options, 'volume', 'amount'); // or vol return [ this.safeTimestamp (ohlcv, 'score'), - this.safeFloat (ohlcv, 'openPrice'), - this.safeFloat (ohlcv, 'highPrice'), - this.safeFloat (ohlcv, 'lowPrice'), - this.safeFloat (ohlcv, 'closePrice'), - this.safeFloat (ohlcv, volumeField), + this.safeNumber (ohlcv, 'openPrice'), + this.safeNumber (ohlcv, 'highPrice'), + this.safeNumber (ohlcv, 'lowPrice'), + this.safeNumber (ohlcv, 'closePrice'), + this.safeNumber (ohlcv, volumeField), ]; } @@ -580,12 +583,12 @@ module.exports = class novadax extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'available'); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); + account['total'] = this.safeString (balance, 'available'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'hold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -608,7 +611,7 @@ module.exports = class novadax extends Exchange { if (uppercaseSide === 'SELL') { request['amount'] = this.amountToPrecision (symbol, amount); } else if (uppercaseSide === 'BUY') { - let value = this.safeFloat (params, 'value'); + let value = this.safeNumber (params, 'value'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -838,21 +841,17 @@ module.exports = class novadax extends Exchange { // } // const id = this.safeString (order, 'id'); - const amount = this.safeFloat (order, 'amount'); - const price = this.safeFloat (order, 'price'); - const cost = this.safeFloat (order, 'filledValue'); + const amount = this.safeNumber (order, 'amount'); + const price = this.safeNumber (order, 'price'); + const cost = this.safeNumber (order, 'filledValue'); const type = this.safeStringLower (order, 'type'); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeInteger (order, 'timestamp'); - const average = this.safeFloat (order, 'averagePrice'); - const filled = this.safeFloat (order, 'filledAmount'); - let remaining = undefined; - if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (0, amount - filled); - } + const average = this.safeNumber (order, 'averagePrice'); + const filled = this.safeNumber (order, 'filledAmount'); let fee = undefined; - const feeCost = this.safeFloat (order, 'filledFee'); + const feeCost = this.safeNumber (order, 'filledFee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -861,7 +860,7 @@ module.exports = class novadax extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'info': order, @@ -879,11 +878,11 @@ module.exports = class novadax extends Exchange { 'cost': cost, 'average': average, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } async withdraw (code, amount, address, tag = undefined, params = {}) { @@ -1046,7 +1045,7 @@ module.exports = class novadax extends Exchange { } else if (type === 'COIN_OUT') { type = 'withdraw'; } - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'addressTag'); const txid = this.safeString (transaction, 'txHash'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/oceanex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/oceanex.js index 28cb8e857..6073f75d5 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/oceanex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/oceanex.js @@ -147,10 +147,10 @@ module.exports = class oceanex extends Exchange { 'active': true, 'info': market, 'precision': { - 'amount': this.safeValue (market, 'amount_precision'), - 'price': this.safeValue (market, 'price_precision'), - 'base': this.safeValue (market, 'ask_precision'), - 'quote': this.safeValue (market, 'bid_precision'), + 'amount': this.safeInteger (market, 'amount_precision'), + 'price': this.safeInteger (market, 'price_precision'), + 'base': this.safeInteger (market, 'ask_precision'), + 'quote': this.safeInteger (market, 'bid_precision'), }, 'limits': { 'amount': { @@ -162,7 +162,7 @@ module.exports = class oceanex extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeValue (market, 'minimum_trading_amount'), + 'min': this.safeNumber (market, 'minimum_trading_amount'), 'max': undefined, }, }, @@ -256,21 +256,21 @@ module.exports = class oceanex extends Exchange { 'symbol': market['symbol'], 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, - 'close': this.safeFloat (ticker, 'last'), - 'last': this.safeFloat (ticker, 'last'), + 'close': this.safeNumber (ticker, 'last'), + 'last': this.safeNumber (ticker, 'last'), 'previousClose': undefined, 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume'), 'quoteVolume': undefined, 'info': ticker, }; @@ -395,8 +395,8 @@ module.exports = class oceanex extends Exchange { 'type': 'limit', 'takerOrMaker': undefined, 'side': side, - 'price': this.safeFloat (trade, 'price'), - 'amount': this.safeFloat (trade, 'volume'), + 'price': this.safeNumber (trade, 'price'), + 'amount': this.safeNumber (trade, 'volume'), 'cost': undefined, 'fee': undefined, }; @@ -423,8 +423,8 @@ module.exports = class oceanex extends Exchange { result[symbol] = { 'info': group, 'symbol': symbol, - 'maker': this.safeFloat (maker, 'value'), - 'taker': this.safeFloat (taker, 'value'), + 'maker': this.safeNumber (maker, 'value'), + 'taker': this.safeNumber (taker, 'value'), }; } return result; @@ -446,11 +446,11 @@ module.exports = class oceanex extends Exchange { const currencyId = this.safeValue (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -558,12 +558,12 @@ module.exports = class oceanex extends Exchange { // const status = this.parseOrderStatus (this.safeValue (order, 'state')); const marketId = this.safeString2 (order, 'market', 'market_id'); - const symbol = this.safeSymbol (marketId); + const symbol = this.safeSymbol (marketId, market); let timestamp = this.safeTimestamp (order, 'created_on'); if (timestamp === undefined) { timestamp = this.parse8601 (this.safeString (order, 'created_at')); } - return { + return this.safeOrder ({ 'info': order, 'id': this.safeString (order, 'id'), 'clientOrderId': undefined, @@ -575,17 +575,17 @@ module.exports = class oceanex extends Exchange { 'timeInForce': undefined, 'postOnly': undefined, 'side': this.safeValue (order, 'side'), - 'price': this.safeFloat (order, 'price'), + 'price': this.safeNumber (order, 'price'), 'stopPrice': undefined, - 'average': this.safeFloat (order, 'avg_price'), - 'amount': this.safeFloat (order, 'volume'), - 'remaining': this.safeFloat (order, 'remaining_volume'), - 'filled': this.safeFloat (order, 'executed_volume'), + 'average': this.safeNumber (order, 'avg_price'), + 'amount': this.safeNumber (order, 'volume'), + 'remaining': this.safeNumber (order, 'remaining_volume'), + 'filled': this.safeNumber (order, 'executed_volume'), 'status': status, 'cost': undefined, 'trades': undefined, 'fee': undefined, - }; + }); } parseOrderStatus (status) { @@ -678,7 +678,7 @@ module.exports = class oceanex extends Exchange { const feedback = this.id + ' ' + body; this.throwExactlyMatchedException (this.exceptions['codes'], errorCode, feedback); this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback); - throw new ExchangeError (response); + throw new ExchangeError (feedback); } } }; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/okex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/okex.js index b9b09c4e0..02d686c17 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/okex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/okex.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors'); const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -798,7 +799,7 @@ module.exports = class okex extends Exchange { let option = false; let baseId = this.safeString (market, 'base_currency'); let quoteId = this.safeString (market, 'quote_currency'); - const contractVal = this.safeFloat (market, 'contract_val'); + const contractVal = this.safeNumber (market, 'contract_val'); if (contractVal !== undefined) { if ('option_type' in market) { marketType = 'option'; @@ -824,12 +825,12 @@ module.exports = class okex extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = spot ? (base + '/' + quote) : id; - const lotSize = this.safeFloat2 (market, 'lot_size', 'trade_increment'); + const lotSize = this.safeNumber2 (market, 'lot_size', 'trade_increment'); const precision = { - 'amount': this.safeFloat (market, 'size_increment', lotSize), - 'price': this.safeFloat (market, 'tick_size'), + 'amount': this.safeNumber (market, 'size_increment', lotSize), + 'price': this.safeNumber (market, 'tick_size'), }; - const minAmount = this.safeFloat2 (market, 'min_size', 'base_min_size'); + const minAmount = this.safeNumber2 (market, 'min_size', 'base_min_size'); const active = true; const fees = this.safeValue2 (this.fees, marketType, 'trading', {}); return this.extend (fees, { @@ -1004,7 +1005,7 @@ module.exports = class okex extends Exchange { 'price': { 'min': undefined, 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdrawal'), + 'min': this.safeNumber (currency, 'min_withdrawal'), 'max': undefined, }, }, @@ -1079,18 +1080,18 @@ module.exports = class okex extends Exchange { if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open_24h'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open_24h'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_24h'), - 'low': this.safeFloat (ticker, 'low_24h'), - 'bid': this.safeFloat (ticker, 'best_bid'), - 'bidVolume': this.safeFloat (ticker, 'best_bid_size'), - 'ask': this.safeFloat (ticker, 'best_ask'), - 'askVolume': this.safeFloat (ticker, 'best_ask_size'), + 'high': this.safeNumber (ticker, 'high_24h'), + 'low': this.safeNumber (ticker, 'low_24h'), + 'bid': this.safeNumber (ticker, 'best_bid'), + 'bidVolume': this.safeNumber (ticker, 'best_bid_size'), + 'ask': this.safeNumber (ticker, 'best_ask'), + 'askVolume': this.safeNumber (ticker, 'best_ask_size'), 'vwap': undefined, 'open': open, 'close': last, @@ -1099,8 +1100,8 @@ module.exports = class okex extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'base_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'quote_volume_24h'), + 'baseVolume': this.safeNumber (ticker, 'base_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'quote_volume_24h'), 'info': ticker, }; } @@ -1237,9 +1238,12 @@ module.exports = class okex extends Exchange { quote = market['quote']; } const timestamp = this.parse8601 (this.safeString2 (trade, 'timestamp', 'created_at')); - const price = this.safeFloat (trade, 'price'); - let amount = this.safeFloat2 (trade, 'size', 'qty'); - amount = this.safeFloat (trade, 'order_qty', amount); + const priceString = this.safeString (trade, 'price'); + let amountString = this.safeString2 (trade, 'size', 'qty'); + amountString = this.safeString (trade, 'order_qty', amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity'); if (takerOrMaker === 'M') { takerOrMaker = 'maker'; @@ -1247,13 +1251,7 @@ module.exports = class okex extends Exchange { takerOrMaker = 'taker'; } const side = this.safeString (trade, 'side'); - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = (side === 'buy') ? base : quote; @@ -1362,22 +1360,22 @@ module.exports = class okex extends Exchange { } return [ timestamp, // timestamp - this.safeFloat (ohlcv, 1), // Open - this.safeFloat (ohlcv, 2), // High - this.safeFloat (ohlcv, 3), // Low - this.safeFloat (ohlcv, 4), // Close - // this.safeFloat (ohlcv, 5), // Quote Volume - // this.safeFloat (ohlcv, 6), // Base Volume - this.safeFloat (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets + this.safeNumber (ohlcv, 1), // Open + this.safeNumber (ohlcv, 2), // High + this.safeNumber (ohlcv, 3), // Low + this.safeNumber (ohlcv, 4), // Close + // this.safeNumber (ohlcv, 5), // Quote Volume + // this.safeNumber (ohlcv, 6), // Base Volume + this.safeNumber (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets ]; } else { return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), // Open - this.safeFloat (ohlcv, 'high'), // High - this.safeFloat (ohlcv, 'low'), // Low - this.safeFloat (ohlcv, 'close'), // Close - this.safeFloat (ohlcv, 'volume'), // Base Volume + this.safeNumber (ohlcv, 'open'), // Open + this.safeNumber (ohlcv, 'high'), // High + this.safeNumber (ohlcv, 'low'), // Low + this.safeNumber (ohlcv, 'close'), // Close + this.safeNumber (ohlcv, 'volume'), // Base Volume ]; } } @@ -1523,9 +1521,9 @@ module.exports = class okex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'hold'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeNumber (balance, 'balance'); + account['used'] = this.safeNumber (balance, 'hold'); + account['free'] = this.safeNumber (balance, 'available'); result[code] = account; } return this.parseBalance (result); @@ -1595,9 +1593,9 @@ module.exports = class okex extends Exchange { const currencyId = parts[1]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (marketBalance, 'balance'); - account['used'] = this.safeFloat (marketBalance, 'hold'); - account['free'] = this.safeFloat (marketBalance, 'available'); + account['total'] = this.safeNumber (marketBalance, 'balance'); + account['used'] = this.safeNumber (marketBalance, 'hold'); + account['free'] = this.safeNumber (marketBalance, 'available'); accounts[code] = account; } else { throw new NotSupported (this.id + ' margin balance response format has changed!'); @@ -1650,29 +1648,29 @@ module.exports = class okex extends Exchange { const code = this.safeCurrencyCode (id); const balance = this.safeValue (info, id, {}); const account = this.account (); - const totalAvailBalance = this.safeFloat (balance, 'total_avail_balance'); + const totalAvailBalance = this.safeNumber (balance, 'total_avail_balance'); if (this.safeString (balance, 'margin_mode') === 'fixed') { const contracts = this.safeValue (balance, 'contracts', []); let free = totalAvailBalance; for (let i = 0; i < contracts.length; i++) { const contract = contracts[i]; - const fixedBalance = this.safeFloat (contract, 'fixed_balance'); - const realizedPnl = this.safeFloat (contract, 'realized_pnl'); - const marginFrozen = this.safeFloat (contract, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (contract, 'margin_for_unfilled'); + const fixedBalance = this.safeNumber (contract, 'fixed_balance'); + const realizedPnl = this.safeNumber (contract, 'realized_pnl'); + const marginFrozen = this.safeNumber (contract, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (contract, 'margin_for_unfilled'); const margin = this.sum (fixedBalance, realizedPnl) - marginFrozen - marginForUnfilled; free = this.sum (free, margin); } account['free'] = free; } else { - const realizedPnl = this.safeFloat (balance, 'realized_pnl'); - const unrealizedPnl = this.safeFloat (balance, 'unrealized_pnl'); - const marginFrozen = this.safeFloat (balance, 'margin_frozen'); - const marginForUnfilled = this.safeFloat (balance, 'margin_for_unfilled'); + const realizedPnl = this.safeNumber (balance, 'realized_pnl'); + const unrealizedPnl = this.safeNumber (balance, 'unrealized_pnl'); + const marginFrozen = this.safeNumber (balance, 'margin_frozen'); + const marginForUnfilled = this.safeNumber (balance, 'margin_for_unfilled'); account['free'] = this.sum (totalAvailBalance, realizedPnl, unrealizedPnl) - marginFrozen - marginForUnfilled; } // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); + account['total'] = this.safeNumber (balance, 'equity'); result[code] = account; } return this.parseBalance (result); @@ -1710,8 +1708,8 @@ module.exports = class okex extends Exchange { } const account = this.account (); // it may be incorrect to use total, free and used for swap accounts - account['total'] = this.safeFloat (balance, 'equity'); - account['free'] = this.safeFloat (balance, 'total_avail_balance'); + account['total'] = this.safeNumber (balance, 'equity'); + account['free'] = this.safeNumber (balance, 'total_avail_balance'); result[symbol] = account; } return this.parseBalance (result); @@ -1915,7 +1913,7 @@ module.exports = class okex extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let notional = this.safeFloat (params, 'notional'); + let notional = this.safeNumber (params, 'notional'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -2125,8 +2123,8 @@ module.exports = class okex extends Exchange { symbol = market['symbol']; } } - let amount = this.safeFloat (order, 'size'); - const filled = this.safeFloat2 (order, 'filled_size', 'filled_qty'); + let amount = this.safeNumber (order, 'size'); + const filled = this.safeNumber2 (order, 'filled_size', 'filled_qty'); let remaining = undefined; if (amount !== undefined) { if (filled !== undefined) { @@ -2137,9 +2135,9 @@ module.exports = class okex extends Exchange { if (type === 'market') { remaining = 0; } - let cost = this.safeFloat2 (order, 'filled_notional', 'funds'); - const price = this.safeFloat (order, 'price'); - let average = this.safeFloat (order, 'price_avg'); + let cost = this.safeNumber2 (order, 'filled_notional', 'funds'); + const price = this.safeNumber (order, 'price'); + let average = this.safeNumber (order, 'price_avg'); if (cost === undefined) { if (filled !== undefined && average !== undefined) { cost = average * filled; @@ -2150,7 +2148,7 @@ module.exports = class okex extends Exchange { } } const status = this.parseOrderStatus (this.safeString (order, 'state')); - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); let fee = undefined; if (feeCost !== undefined) { const feeCurrency = undefined; @@ -2163,7 +2161,7 @@ module.exports = class okex extends Exchange { if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) { clientOrderId = undefined; // fix empty clientOrderId string } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); return { 'info': order, 'id': id, @@ -2407,16 +2405,6 @@ module.exports = class okex extends Exchange { return await this.fetchOrdersByState ('7', symbol, since, limit, params); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - parseDepositAddress (depositAddress, currency = undefined) { // // { @@ -2444,7 +2432,8 @@ module.exports = class okex extends Exchange { async fetchDepositAddress (code, params = {}) { await this.loadMarkets (); - const currency = this.currency (code); + const parts = code.split ('-'); + const currency = this.currency (parts[0]); const request = { 'currency': currency['id'], }; @@ -2457,8 +2446,8 @@ module.exports = class okex extends Exchange { // } // ] // - const addresses = this.parseDepositAddresses (response); - const address = this.safeValue (addresses, code); + const addressesByCode = this.parseDepositAddresses (response); + const address = this.safeValue (addressesByCode, code); if (address === undefined) { throw new InvalidAddress (this.id + ' fetchDepositAddress cannot return nonexistent addresses, you should create withdrawal addresses with the exchange website first'); } @@ -2633,7 +2622,7 @@ module.exports = class okex extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const txid = this.safeString (transaction, 'txid'); const timestamp = this.parse8601 (this.safeString (transaction, 'timestamp')); @@ -2696,19 +2685,19 @@ module.exports = class okex extends Exchange { let feeCurrencyId = undefined; if (receivedCurrencyId === quoteId) { side = this.safeString (otherTrade, 'side'); - amount = this.safeFloat (otherTrade, 'size'); - cost = this.safeFloat (userTrade, 'size'); + amount = this.safeNumber (otherTrade, 'size'); + cost = this.safeNumber (userTrade, 'size'); feeCurrencyId = this.safeString (otherTrade, 'currency'); } else { side = this.safeString (userTrade, 'side'); - amount = this.safeFloat (userTrade, 'size'); - cost = this.safeFloat (otherTrade, 'size'); + amount = this.safeNumber (userTrade, 'size'); + cost = this.safeNumber (otherTrade, 'size'); feeCurrencyId = this.safeString (userTrade, 'currency'); } const id = this.safeString (userTrade, 'trade_id'); - const price = this.safeFloat (userTrade, 'price'); - const feeCostFirst = this.safeFloat (otherTrade, 'fee'); - const feeCostSecond = this.safeFloat (userTrade, 'fee'); + const price = this.safeNumber (userTrade, 'price'); + const feeCostFirst = this.safeNumber (otherTrade, 'fee'); + const feeCostSecond = this.safeNumber (userTrade, 'fee'); const feeCurrencyCodeFirst = this.safeCurrencyCode (this.safeString (otherTrade, 'currency')); const feeCurrencyCodeSecond = this.safeCurrencyCode (this.safeString (userTrade, 'currency')); let fee = undefined; @@ -3140,7 +3129,7 @@ module.exports = class okex extends Exchange { return response; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); let method = undefined; const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType'); @@ -3522,14 +3511,14 @@ module.exports = class okex extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'type')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - const amount = this.safeFloat (item, 'amount'); + const amount = this.safeNumber (item, 'amount'); const timestamp = this.parse8601 (this.safeString (item, 'timestamp')); const fee = { - 'cost': this.safeFloat (item, 'fee'), + 'cost': this.safeNumber (item, 'fee'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; const marketId = this.safeString (item, 'instrument_id'); let symbol = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/paymium.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/paymium.js index 1af0c5355..2d0d8418c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/paymium.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/paymium.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -96,12 +97,12 @@ module.exports = class paymium extends Exchange { if (free in response) { const account = this.account (); const used = 'locked_' + currencyId; - account['free'] = this.safeFloat (response, free); - account['used'] = this.safeFloat (response, used); + account['free'] = this.safeString (response, free); + account['used'] = this.safeString (response, used); result[code] = account; } } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -120,30 +121,30 @@ module.exports = class paymium extends Exchange { }; const ticker = await this.publicGetDataCurrencyTicker (this.extend (request, params)); const timestamp = this.safeTimestamp (ticker, 'at'); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'price'); + const last = this.safeNumber (ticker, 'price'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'variation'), + 'percentage': this.safeNumber (ticker, 'variation'), 'average': undefined, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, @@ -159,15 +160,12 @@ module.exports = class paymium extends Exchange { symbol = market['symbol']; } const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); + const priceString = this.safeString (trade, 'price'); const amountField = 'traded_' + market['base'].toLowerCase (); - const amount = this.safeFloat (trade, amountField); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const amountString = this.safeString (trade, amountField); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); return { 'info': trade, 'id': id, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/phemex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/phemex.js index b1c294ab2..ae494da41 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/phemex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/phemex.js @@ -305,13 +305,13 @@ module.exports = class phemex extends Exchange { }); } - parseSafeFloat (value = undefined) { + parseSafeNumber (value = undefined) { if (value === undefined) { return value; } value = value.replace (',', ''); const parts = value.split (' '); - return this.safeFloat (parts, 0); + return this.safeNumber (parts, 0); } parseSwapMarket (market) { @@ -335,7 +335,9 @@ module.exports = class phemex extends Exchange { // "minPriceEp":5000, // "maxPriceEp":10000000000, // "maxOrderQty":1000000, - // "type":"Perpetual" + // "type":"Perpetual", + // "status":"Listed", + // "tipOrderQty":1000000, // "steps":"50", // "riskLimits":[ // {"limit":100,"initialMargin":"1.0%","initialMarginEr":1000000,"maintenanceMargin":"0.5%","maintenanceMarginEr":500000}, @@ -360,7 +362,7 @@ module.exports = class phemex extends Exchange { // } // const id = this.safeString (market, 'symbol'); - const baseId = this.safeString (market, 'baseCurrency', 'contractUnderlyingAssets'); + const baseId = this.safeString2 (market, 'baseCurrency', 'contractUnderlyingAssets'); const quoteId = this.safeString (market, 'quoteCurrency'); const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); @@ -377,16 +379,16 @@ module.exports = class phemex extends Exchange { } const linear = !inverse; const precision = { - 'amount': this.safeFloat (market, 'lotSize'), - 'price': this.safeFloat (market, 'tickSize'), + 'amount': this.safeNumber (market, 'lotSize'), + 'price': this.safeNumber (market, 'tickSize'), }; const priceScale = this.safeInteger (market, 'priceScale'); const ratioScale = this.safeInteger (market, 'ratioScale'); const valueScale = this.safeInteger (market, 'valueScale'); - const minPriceEp = this.safeFloat (market, 'minPriceEp'); - const maxPriceEp = this.safeFloat (market, 'maxPriceEp'); - const makerFeeRateEr = this.safeFloat (market, 'makerFeeRateEr'); - const takerFeeRateEr = this.safeFloat (market, 'takerFeeRateEr'); + const minPriceEp = this.safeNumber (market, 'minPriceEp'); + const maxPriceEp = this.safeNumber (market, 'maxPriceEp'); + const makerFeeRateEr = this.safeNumber (market, 'makerFeeRateEr'); + const takerFeeRateEr = this.safeNumber (market, 'takerFeeRateEr'); if (makerFeeRateEr !== undefined) { maker = this.fromEn (makerFeeRateEr, ratioScale, 0.00000001); } @@ -404,10 +406,11 @@ module.exports = class phemex extends Exchange { }, 'cost': { 'min': undefined, - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderQty')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderQty')), }, }; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -456,7 +459,9 @@ module.exports = class phemex extends Exchange { // "defaultMakerFee":"0.001", // "defaultMakerFeeEr":100000, // "baseQtyPrecision":6, - // "quoteQtyPrecision":2 + // "quoteQtyPrecision":2, + // "status":"Listed", + // "tipOrderQty":20 // } // const type = this.safeStringLower (market, 'type'); @@ -467,30 +472,31 @@ module.exports = class phemex extends Exchange { const inverse = undefined; const spot = true; const swap = false; - const taker = this.safeFloat (market, 'defaultTakerFee'); - const maker = this.safeFloat (market, 'defaultMakerFee'); + const taker = this.safeNumber (market, 'defaultTakerFee'); + const maker = this.safeNumber (market, 'defaultMakerFee'); const precision = { - 'amount': this.parseSafeFloat (this.safeString (market, 'baseTickSize')), - 'price': this.parseSafeFloat (this.safeString (market, 'quoteTickSize')), + 'amount': this.parseSafeNumber (this.safeString (market, 'baseTickSize')), + 'price': this.parseSafeNumber (this.safeString (market, 'quoteTickSize')), }; const limits = { 'amount': { 'min': precision['amount'], - 'max': this.parseSafeFloat (this.safeString (market, 'maxBaseOrderSize')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxBaseOrderSize')), }, 'price': { 'min': precision['price'], 'max': undefined, }, 'cost': { - 'min': this.parseSafeFloat (this.safeString (market, 'minOrderValue')), - 'max': this.parseSafeFloat (this.safeString (market, 'maxOrderValue')), + 'min': this.parseSafeNumber (this.safeString (market, 'minOrderValue')), + 'max': this.parseSafeNumber (this.safeString (market, 'maxOrderValue')), }, }; const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const active = undefined; + const status = this.safeString (market, 'status'); + const active = status === 'Listed'; return { 'id': id, 'symbol': symbol, @@ -680,8 +686,8 @@ module.exports = class phemex extends Exchange { const name = this.safeString (currency, 'name'); const code = this.safeCurrencyCode (id); const valueScale = this.safeInteger (currency, 'valueScale'); - const minValueEv = this.safeFloat (currency, 'minValueEv'); - const maxValueEv = this.safeFloat (currency, 'maxValueEv'); + const minValueEv = this.safeNumber (currency, 'minValueEv'); + const maxValueEv = this.safeNumber (currency, 'maxValueEv'); let minAmount = undefined; let maxAmount = undefined; let precision = undefined; @@ -731,12 +737,12 @@ module.exports = class phemex extends Exchange { if (market === undefined) { throw new ArgumentsRequired (this.id + ' parseBidAsk() requires a market argument'); } - let amount = this.safeFloat (bidask, amountKey); + let amount = this.safeNumber (bidask, amountKey); if (market['spot']) { amount = this.fromEv (amount, market); } return [ - this.fromEp (this.safeFloat (bidask, priceKey), market), + this.fromEp (this.safeNumber (bidask, priceKey), market), amount, ]; } @@ -870,16 +876,16 @@ module.exports = class phemex extends Exchange { // let baseVolume = undefined; if ((market !== undefined) && market['spot']) { - baseVolume = this.fromEv (this.safeFloat (ohlcv, 7), market); + baseVolume = this.fromEv (this.safeNumber (ohlcv, 7), market); } else { baseVolume = this.safeInteger (ohlcv, 7); } return [ this.safeTimestamp (ohlcv, 0), - this.fromEp (this.safeFloat (ohlcv, 3), market), - this.fromEp (this.safeFloat (ohlcv, 4), market), - this.fromEp (this.safeFloat (ohlcv, 5), market), - this.fromEp (this.safeFloat (ohlcv, 6), market), + this.fromEp (this.safeNumber (ohlcv, 3), market), + this.fromEp (this.safeNumber (ohlcv, 4), market), + this.fromEp (this.safeNumber (ohlcv, 5), market), + this.fromEp (this.safeNumber (ohlcv, 6), market), baseVolume, ]; } @@ -972,11 +978,11 @@ module.exports = class phemex extends Exchange { const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.safeIntegerProduct (ticker, 'timestamp', 0.000001); - const last = this.fromEp (this.safeFloat (ticker, 'lastEp'), market); - const quoteVolume = this.fromEp (this.safeFloat (ticker, 'turnoverEv'), market); - let baseVolume = this.safeFloat (ticker, 'volume'); + const last = this.fromEp (this.safeNumber (ticker, 'lastEp'), market); + const quoteVolume = this.fromEp (this.safeNumber (ticker, 'turnoverEv'), market); + let baseVolume = this.safeNumber (ticker, 'volume'); if (baseVolume === undefined) { - baseVolume = this.fromEv (this.safeFloat (ticker, 'volumeEv')); + baseVolume = this.fromEv (this.safeNumber (ticker, 'volumeEv')); } let vwap = undefined; if ((market !== undefined) && (market['spot'])) { @@ -985,7 +991,7 @@ module.exports = class phemex extends Exchange { let change = undefined; let percentage = undefined; let average = undefined; - const open = this.fromEp (this.safeFloat (ticker, 'openEp'), market); + const open = this.fromEp (this.safeNumber (ticker, 'openEp'), market); if ((open !== undefined) && (last !== undefined)) { change = last - open; if (open > 0) { @@ -997,11 +1003,11 @@ module.exports = class phemex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.fromEp (this.safeFloat (ticker, 'highEp'), market), - 'low': this.fromEp (this.safeFloat (ticker, 'lowEp'), market), - 'bid': this.fromEp (this.safeFloat (ticker, 'bidEp'), market), + 'high': this.fromEp (this.safeNumber (ticker, 'highEp'), market), + 'low': this.fromEp (this.safeNumber (ticker, 'lowEp'), market), + 'bid': this.fromEp (this.safeNumber (ticker, 'bidEp'), market), 'bidVolume': undefined, - 'ask': this.fromEp (this.safeFloat (ticker, 'askEp'), market), + 'ask': this.fromEp (this.safeNumber (ticker, 'askEp'), market), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -1192,8 +1198,8 @@ module.exports = class phemex extends Exchange { id = this.safeString (trade, tradeLength - 4); } side = this.safeStringLower (trade, tradeLength - 3); - price = this.fromEp (this.safeFloat (trade, tradeLength - 2), market); - amount = this.fromEv (this.safeFloat (trade, tradeLength - 1), market); + price = this.fromEp (this.safeNumber (trade, tradeLength - 2), market); + amount = this.fromEv (this.safeNumber (trade, tradeLength - 1), market); if (market['spot']) { if ((price !== undefined) && (amount !== undefined)) { cost = price * amount; @@ -1209,14 +1215,14 @@ module.exports = class phemex extends Exchange { if (execStatus === 'MakerFill') { takerOrMaker = 'maker'; } - price = this.fromEp (this.safeFloat (trade, 'execPriceEp'), market); - amount = this.fromEv (this.safeFloat (trade, 'execBaseQtyEv'), market); - amount = this.safeFloat (trade, 'execQty', amount); - cost = this.fromEv (this.safeFloat2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); - const feeCost = this.fromEv (this.safeFloat (trade, 'execFeeEv'), market); + price = this.fromEp (this.safeNumber (trade, 'execPriceEp'), market); + amount = this.fromEv (this.safeNumber (trade, 'execBaseQtyEv'), market); + amount = this.safeNumber (trade, 'execQty', amount); + cost = this.fromEv (this.safeNumber2 (trade, 'execQuoteQtyEv', 'execValueEv'), market); + const feeCost = this.fromEv (this.safeNumber (trade, 'execFeeEv'), market); if (feeCost !== undefined) { let feeRate = undefined; - let feeRateEr = this.safeFloat (trade, 'feeRateEr'); + let feeRateEr = this.safeNumber (trade, 'feeRateEr'); if (feeRateEr < 0) { feeRateEr = Math.abs (feeRateEr); feeRate = this.fromEr (feeRateEr, market); @@ -1292,9 +1298,9 @@ module.exports = class phemex extends Exchange { const currency = this.safeValue (this.currencies, code, {}); const scale = this.safeInteger (currency, 'valueScale', 8); const account = this.account (); - const balanceEv = this.safeFloat (balance, 'balanceEv'); - const lockedTradingBalanceEv = this.safeFloat (balance, 'lockedTradingBalanceEv'); - const lockedWithdrawEv = this.safeFloat (balance, 'lockedWithdrawEv'); + const balanceEv = this.safeNumber (balance, 'balanceEv'); + const lockedTradingBalanceEv = this.safeNumber (balance, 'lockedTradingBalanceEv'); + const lockedWithdrawEv = this.safeNumber (balance, 'lockedWithdrawEv'); const total = this.fromEn (balanceEv, scale, scale, DECIMAL_PLACES); const lockedTradingBalance = this.fromEn (lockedTradingBalanceEv, scale, scale, DECIMAL_PLACES); const lockedWithdraw = this.fromEn (lockedWithdrawEv, scale, scale, DECIMAL_PLACES); @@ -1388,8 +1394,8 @@ module.exports = class phemex extends Exchange { const code = this.safeCurrencyCode (currencyId); const currency = this.currency (code); const account = this.account (); - const accountBalanceEv = this.safeFloat (balance, 'accountBalanceEv'); - const totalUsedBalanceEv = this.safeFloat (balance, 'totalUsedBalanceEv'); + const accountBalanceEv = this.safeNumber (balance, 'accountBalanceEv'); + const totalUsedBalanceEv = this.safeNumber (balance, 'totalUsedBalanceEv'); const valueScale = this.safeInteger (currency, 'valueScale', 8); account['total'] = this.fromEn (accountBalanceEv, valueScale, valueScale, DECIMAL_PLACES); account['used'] = this.fromEn (totalUsedBalanceEv, valueScale, valueScale, DECIMAL_PLACES); @@ -1621,21 +1627,21 @@ module.exports = class phemex extends Exchange { } const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - let price = this.fromEp (this.safeFloat (order, 'priceEp'), market); + let price = this.fromEp (this.safeNumber (order, 'priceEp'), market); if (price === 0) { price = undefined; } - const amount = this.fromEv (this.safeFloat (order, 'baseQtyEv'), market); - const remaining = this.fromEv (this.safeFloat (order, 'leavesBaseQtyEv'), market); - let filled = this.fromEv (this.safeFloat (order, 'cumBaseQtyEv'), market); - const cost = this.fromEv (this.safeFloat (order, 'quoteQtyEv'), market); - const average = this.fromEp (this.safeFloat (order, 'avgPriceEp'), market); + const amount = this.fromEv (this.safeNumber (order, 'baseQtyEv'), market); + const remaining = this.fromEv (this.safeNumber (order, 'leavesBaseQtyEv'), market); + let filled = this.fromEv (this.safeNumber (order, 'cumBaseQtyEv'), market); + const cost = this.fromEv (this.safeNumber (order, 'quoteQtyEv'), market); + const average = this.fromEp (this.safeNumber (order, 'avgPriceEp'), market); const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'ordType')); const timestamp = this.safeIntegerProduct2 (order, 'actionTimeNs', 'createTimeNs', 0.000001); let fee = undefined; - const feeCost = this.fromEv (this.safeFloat (order, 'cumFeeEv'), market); + const feeCost = this.fromEv (this.safeNumber (order, 'cumFeeEv'), market); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1648,7 +1654,7 @@ module.exports = class phemex extends Exchange { } } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.fromEp (this.safeFloat (order, 'stopPxEp', market)); + const stopPrice = this.fromEp (this.safeNumber (order, 'stopPxEp', market)); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -1721,18 +1727,18 @@ module.exports = class phemex extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const side = this.safeStringLower (order, 'side'); const type = this.parseOrderType (this.safeString (order, 'orderType')); - const price = this.fromEp (this.safeFloat (order, 'priceEp'), market); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); + const price = this.fromEp (this.safeNumber (order, 'priceEp'), market); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); const timestamp = this.safeIntegerProduct (order, 'actionTimeNs', 0.000001); - const cost = this.safeFloat (order, 'cumValue'); + const cost = this.safeNumber (order, 'cumValue'); let lastTradeTimestamp = this.safeIntegerProduct (order, 'transactTimeNs', 0.000001); if (lastTradeTimestamp === 0) { lastTradeTimestamp = undefined; } const timeInForce = this.parseTimeInForce (this.safeString (order, 'timeInForce')); - const stopPrice = this.safeFloat (order, 'stopPx'); + const stopPrice = this.safeNumber (order, 'stopPx'); const postOnly = (timeInForce === 'PO'); return { 'info': order, @@ -1807,7 +1813,7 @@ module.exports = class phemex extends Exchange { } request['qtyType'] = qtyType; if (qtyType === 'ByQuote') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); params = this.omit (params, 'cost'); if (this.options['createOrderByQuoteRequiresPrice']) { if (price !== undefined) { @@ -1827,7 +1833,7 @@ module.exports = class phemex extends Exchange { if (type === 'Limit') { request['priceEp'] = this.toEp (price, market); } - const stopPrice = this.safeFloat2 (params, 'stopPx', 'stopPrice'); + const stopPrice = this.safeNumber2 (params, 'stopPx', 'stopPrice'); if (stopPrice !== undefined) { request['stopPxEp'] = this.toEp (stopPrice, market); } @@ -2335,7 +2341,7 @@ module.exports = class phemex extends Exchange { const code = currency['code']; const timestamp = this.safeInteger2 (transaction, 'createdAt', 'submitedAt'); let type = this.safeStringLower (transaction, 'type'); - const feeCost = this.fromEn (this.safeFloat (transaction, 'feeEv'), currency['valueScale'], currency['precision']); + const feeCost = this.fromEn (this.safeNumber (transaction, 'feeEv'), currency['valueScale'], currency['precision']); let fee = undefined; if (feeCost !== undefined) { type = 'withdrawal'; @@ -2345,7 +2351,7 @@ module.exports = class phemex extends Exchange { }; } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const amount = this.fromEn (this.safeFloat (transaction, 'amountEv'), currency['valueScale'], currency['precision']); + const amount = this.fromEn (this.safeNumber (transaction, 'amountEv'), currency['valueScale'], currency['precision']); return { 'info': transaction, 'id': id, @@ -2367,7 +2373,7 @@ module.exports = class phemex extends Exchange { }; } - async fetchPositions (symbols = undefined, since = undefined, limit = undefined, params = {}) { + async fetchPositions (symbols = undefined, params = {}) { await this.loadMarkets (); const code = this.safeString (params, 'code'); const request = {}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/poloniex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/poloniex.js index 30eee15c9..fbb6447ad 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/poloniex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/poloniex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, RequestTimeout, AuthenticationError, PermissionDenied, DDoSProtection, InsufficientFunds, OrderNotFound, InvalidOrder, AccountSuspended, CancelPending, InvalidNonce, OnMaintenance, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -113,6 +114,7 @@ module.exports = class poloniex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', // starting from Jan 8 2020 'maker': 0.0009, 'taker': 0.0009, @@ -207,24 +209,6 @@ module.exports = class poloniex extends Exchange { }); } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': parseFloat (this.feeToPrecision (symbol, cost)), - }; - } - parseOHLCV (ohlcv, market = undefined) { // // { @@ -240,11 +224,11 @@ module.exports = class poloniex extends Exchange { // return [ this.safeTimestamp (ohlcv, 'date'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'quoteVolume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'quoteVolume'), ]; } @@ -337,11 +321,11 @@ module.exports = class poloniex extends Exchange { const balance = this.safeValue (response, currencyId, {}); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onOrders'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchTradingFees (params = {}) { @@ -359,8 +343,8 @@ module.exports = class poloniex extends Exchange { // return { 'info': fees, - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), 'withdraw': {}, 'deposit': {}, }; @@ -418,8 +402,8 @@ module.exports = class poloniex extends Exchange { let open = undefined; let change = undefined; let average = undefined; - const last = this.safeFloat (ticker, 'last'); - const relativeChange = this.safeFloat (ticker, 'percentChange'); + const last = this.safeNumber (ticker, 'last'); + const relativeChange = this.safeNumber (ticker, 'percentChange'); if (relativeChange !== -1) { open = last / this.sum (1, relativeChange); change = last - open; @@ -429,11 +413,11 @@ module.exports = class poloniex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high24hr'), - 'low': this.safeFloat (ticker, 'low24hr'), - 'bid': this.safeFloat (ticker, 'highestBid'), + 'high': this.safeNumber (ticker, 'high24hr'), + 'low': this.safeNumber (ticker, 'low24hr'), + 'bid': this.safeNumber (ticker, 'highestBid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'lowestAsk'), + 'ask': this.safeNumber (ticker, 'lowestAsk'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -443,8 +427,8 @@ module.exports = class poloniex extends Exchange { 'change': change, 'percentage': relativeChange * 100, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'quoteVolume'), - 'quoteVolume': this.safeFloat (ticker, 'baseVolume'), + 'baseVolume': this.safeNumber (ticker, 'quoteVolume'), + 'quoteVolume': this.safeNumber (ticker, 'baseVolume'), 'info': ticker, }; } @@ -485,7 +469,7 @@ module.exports = class poloniex extends Exchange { const code = this.safeCurrencyCode (id); const active = (currency['delisted'] === 0) && !currency['disabled']; const numericId = this.safeInteger (currency, 'id'); - const fee = this.safeFloat (currency, 'txFee'); + const fee = this.safeNumber (currency, 'txFee'); result[code] = { 'id': id, 'numericId': numericId, @@ -576,13 +560,18 @@ module.exports = class poloniex extends Exchange { } const side = this.safeString (trade, 'type'); let fee = undefined; - const price = this.safeFloat (trade, 'rate'); - const cost = this.safeFloat (trade, 'total'); - const amount = this.safeFloat (trade, 'amount'); + const priceString = this.safeString (trade, 'rate'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'total'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } const feeDisplay = this.safeString (trade, 'feeDisplay'); if (feeDisplay !== undefined) { const parts = feeDisplay.split (' '); - const feeCost = this.safeFloat (parts, 0); + const feeCost = this.safeNumber (parts, 0); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (parts, 1); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -601,7 +590,7 @@ module.exports = class poloniex extends Exchange { } } let takerOrMaker = undefined; - const takerAdjustment = this.safeFloat (trade, 'takerAdjustment'); + const takerAdjustment = this.safeNumber (trade, 'takerAdjustment'); if (takerAdjustment !== undefined) { takerOrMaker = 'taker'; } @@ -847,9 +836,9 @@ module.exports = class poloniex extends Exchange { if (resultingTrades !== undefined) { trades = this.parseTrades (resultingTrades, market); } - const price = this.safeFloat2 (order, 'price', 'rate'); - let remaining = this.safeFloat (order, 'amount'); - let amount = this.safeFloat (order, 'startingAmount'); + const price = this.safeNumber2 (order, 'price', 'rate'); + let remaining = this.safeNumber (order, 'amount'); + let amount = this.safeNumber (order, 'startingAmount'); let filled = undefined; let cost = 0; if (amount !== undefined) { @@ -899,7 +888,7 @@ module.exports = class poloniex extends Exchange { } const id = this.safeString (order, 'orderNumber'); let fee = undefined; - const feeCost = this.safeFloat (order, 'fee'); + const feeCost = this.safeNumber (order, 'fee'); if (feeCost !== undefined) { let feeCurrencyCode = undefined; if (market !== undefined) { @@ -1396,11 +1385,11 @@ module.exports = class poloniex extends Exchange { const defaultType = ('withdrawalNumber' in transaction) ? 'withdrawal' : 'deposit'; const type = this.safeString (transaction, 'type', defaultType); const id = this.safeString2 (transaction, 'withdrawalNumber', 'depositNumber'); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'paymentID'); // according to https://poloniex.com/fees/ - const feeCost = this.safeFloat (transaction, 'fee', 0); + const feeCost = this.safeNumber (transaction, 'fee', 0); if (type === 'withdrawal') { // poloniex withdrawal amount includes the fee amount = amount - feeCost; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/probit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/probit.js index 522045f2c..2b551ca0a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/probit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/probit.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ExchangeNotAvailable, BadResponse, BadRequest, InvalidOrder, InsufficientFunds, AuthenticationError, ArgumentsRequired, InvalidAddress, RateLimitExceeded, DDoSProtection, BadSymbol } = require ('./base/errors'); const { TRUNCATE, TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -140,9 +141,11 @@ module.exports = class probit extends Exchange { }, }, 'commonCurrencies': { + 'AUTO': 'Cube', 'BTCBEAR': 'BEAR', 'BTCBULL': 'BULL', 'CBC': 'CryptoBharatCoin', + 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909 'HBC': 'Hybrid Bank Cash', 'UNI': 'UNICORN Token', }, @@ -191,11 +194,11 @@ module.exports = class probit extends Exchange { const costPrecision = this.safeInteger (market, 'cost_precision'); const precision = { 'amount': 1 / Math.pow (10, amountPrecision), - 'price': this.safeFloat (market, 'price_increment'), + 'price': this.safeNumber (market, 'price_increment'), 'cost': 1 / Math.pow (10, costPrecision), }; - const takerFeeRate = this.safeFloat (market, 'taker_fee_rate'); - const makerFeeRate = this.safeFloat (market, 'maker_fee_rate'); + const takerFeeRate = this.safeNumber (market, 'taker_fee_rate'); + const makerFeeRate = this.safeNumber (market, 'maker_fee_rate'); result.push ({ 'id': id, 'info': market, @@ -210,16 +213,16 @@ module.exports = class probit extends Exchange { 'maker': makerFeeRate / 100, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_quantity'), - 'max': this.safeFloat (market, 'max_quantity'), + 'min': this.safeNumber (market, 'min_quantity'), + 'max': this.safeNumber (market, 'max_quantity'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_cost'), - 'max': this.safeFloat (market, 'max_cost'), + 'min': this.safeNumber (market, 'min_cost'), + 'max': this.safeNumber (market, 'max_cost'), }, }, }); @@ -306,7 +309,7 @@ module.exports = class probit extends Exchange { // [ { 'amount': '0.015', 'priority': 1, 'currency_id': 'ETH' }, {} ] for (let j = 0; j < withdrawalFees.length; j++) { const withdrawalFee = withdrawalFees[j]; - const amount = this.safeFloat (withdrawalFee, 'amount'); + const amount = this.safeNumber (withdrawalFee, 'amount'); const priority = this.safeInteger (withdrawalFee, 'priority'); if ((amount !== undefined) && (priority !== undefined)) { fees.push (withdrawalFee); @@ -314,7 +317,7 @@ module.exports = class probit extends Exchange { } const withdrawalFeesByPriority = this.sortBy (fees, 'priority'); const withdrawalFee = this.safeValue (withdrawalFeesByPriority, 0, {}); - const fee = this.safeFloat (withdrawalFee, 'amount'); + const fee = this.safeNumber (withdrawalFee, 'amount'); result[code] = { 'id': id, 'code': code, @@ -337,11 +340,11 @@ module.exports = class probit extends Exchange { 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (platform, 'min_deposit_amount'), + 'min': this.safeNumber (platform, 'min_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (platform, 'min_withdrawal_amount'), + 'min': this.safeNumber (platform, 'min_withdrawal_amount'), 'max': undefined, }, }, @@ -371,11 +374,11 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (balance, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'total'); - account['free'] = this.safeFloat (balance, 'available'); + account['total'] = this.safeString (balance, 'total'); + account['free'] = this.safeString (balance, 'available'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -427,14 +430,6 @@ module.exports = class probit extends Exchange { return this.parseTickers (data, symbols); } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - async fetchTicker (symbol, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -482,8 +477,8 @@ module.exports = class probit extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'time')); const marketId = this.safeString (ticker, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); - const close = this.safeFloat (ticker, 'last'); - const change = this.safeFloat (ticker, 'change'); + const close = this.safeNumber (ticker, 'last'); + const change = this.safeNumber (ticker, 'change'); let percentage = undefined; let open = undefined; if (change !== undefined) { @@ -492,15 +487,15 @@ module.exports = class probit extends Exchange { percentage = (change / open) * 100; } } - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, @@ -642,16 +637,13 @@ module.exports = class probit extends Exchange { marketId = this.safeString (trade, 'market_id', marketId); const symbol = this.safeSymbol (marketId, market, '-'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const orderId = this.safeString (trade, 'order_id'); - const feeCost = this.safeFloat (trade, 'fee_amount'); + const feeCost = this.safeNumber (trade, 'fee_amount'); let fee = undefined; if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'fee_currency_id'); @@ -795,11 +787,11 @@ module.exports = class probit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'start_time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'base_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'base_volume'), ]; } @@ -898,37 +890,24 @@ module.exports = class probit extends Exchange { const marketId = this.safeString (order, 'market_id'); const symbol = this.safeSymbol (marketId, market, '-'); const timestamp = this.parse8601 (this.safeString (order, 'time')); - let price = this.safeFloat (order, 'limit_price'); - const filled = this.safeFloat (order, 'filled_quantity'); - let remaining = this.safeFloat (order, 'open_quantity'); - const canceledAmount = this.safeFloat (order, 'cancelled_quantity'); + let price = this.safeNumber (order, 'limit_price'); + const filled = this.safeNumber (order, 'filled_quantity'); + let remaining = this.safeNumber (order, 'open_quantity'); + const canceledAmount = this.safeNumber (order, 'cancelled_quantity'); if (canceledAmount !== undefined) { remaining = this.sum (remaining, canceledAmount); } - const amount = this.safeFloat (order, 'quantity', this.sum (filled, remaining)); - let cost = this.safeFloat2 (order, 'filled_cost', 'cost'); + const amount = this.safeNumber (order, 'quantity', this.sum (filled, remaining)); + const cost = this.safeNumber2 (order, 'filled_cost', 'cost'); if (type === 'market') { price = undefined; } - let average = undefined; - if (filled !== undefined) { - if (cost === undefined) { - if (price !== undefined) { - cost = price * filled; - } - } - if (cost !== undefined) { - if (filled > 0) { - average = cost / filled; - } - } - } let clientOrderId = this.safeString (order, 'client_order_id'); if (clientOrderId === '') { clientOrderId = undefined; } const timeInForce = this.safeStringUpper (order, 'time_in_force'); - return { + return this.safeOrder ({ 'id': id, 'info': order, 'clientOrderId': clientOrderId, @@ -945,11 +924,11 @@ module.exports = class probit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'average': average, + 'average': undefined, 'cost': cost, 'fee': undefined, 'trades': undefined, - }; + }); } costToPrecision (symbol, cost) { @@ -979,7 +958,7 @@ module.exports = class probit extends Exchange { } else if (type === 'market') { // for market buy it requires the amount of quote currency to spend if (side === 'buy') { - let cost = this.safeFloat (params, 'cost'); + let cost = this.safeNumber (params, 'cost'); const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true); if (createMarketBuyOrderRequiresPrice) { if (price !== undefined) { @@ -1104,16 +1083,6 @@ module.exports = class probit extends Exchange { return this.parseDepositAddresses (data); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async withdraw (code, amount, address, tag = undefined, params = {}) { // In order to use this method // you need to allow API withdrawal from the API Settings Page, and @@ -1144,7 +1113,7 @@ module.exports = class probit extends Exchange { parseTransaction (transaction, currency = undefined) { const id = this.safeString (transaction, 'id'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = this.safeString (transaction, 'address'); const tag = this.safeString (transaction, 'destination_tag'); const txid = this.safeString (transaction, 'hash'); @@ -1153,7 +1122,7 @@ module.exports = class probit extends Exchange { const currencyId = this.safeString (transaction, 'currency_id'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); let fee = undefined; if (feeCost !== undefined && feeCost !== 0) { fee = { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/qtrade.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/qtrade.js index aa66545bf..d77b576c4 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/qtrade.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/qtrade.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InvalidOrder, InsufficientFunds, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -179,11 +180,11 @@ module.exports = class qtrade extends Exchange { 'quote': quote, 'active': active, 'precision': precision, - 'taker': this.safeFloat (market, 'taker_fee'), - 'maker': this.safeFloat (market, 'maker_fee'), + 'taker': this.safeNumber (market, 'taker_fee'), + 'maker': this.safeNumber (market, 'maker_fee'), 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_buy_value'), + 'min': this.safeNumber (market, 'minimum_buy_value'), 'max': undefined, }, 'price': { @@ -264,12 +265,12 @@ module.exports = class qtrade extends Exchange { 'info': currency, 'type': type, 'name': name, - 'fee': this.safeFloat (config, 'withdraw_fee'), + 'fee': this.safeNumber (config, 'withdraw_fee'), 'precision': this.safeInteger (currency, 'precision'), 'active': active, 'limits': { 'amount': { - 'min': this.safeFloat (currency, 'minimum_order'), + 'min': this.safeNumber (currency, 'minimum_order'), 'max': undefined, }, 'price': { @@ -304,11 +305,11 @@ module.exports = class qtrade extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'time')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'market_volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'market_volume'), ]; } @@ -370,8 +371,8 @@ module.exports = class qtrade extends Exchange { const result = []; for (let j = 0; j < prices.length; j++) { const priceAsString = prices[j]; - const price = this.safeFloat (prices, j); - const amount = this.safeFloat (bidasks, priceAsString); + const price = this.safeNumber (prices, j); + const amount = this.safeNumber (bidasks, priceAsString); result.push ([ price, amount ]); } orderbook[side] = result; @@ -403,12 +404,12 @@ module.exports = class qtrade extends Exchange { const marketId = this.safeString (ticker, 'id_hr'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeIntegerProduct (ticker, 'last_change', 0.001); - const previous = this.safeFloat (ticker, 'day_open'); - const last = this.safeFloat (ticker, 'last'); - const day_change = this.safeFloat (ticker, 'day_change'); + const previous = this.safeNumber (ticker, 'day_open'); + const last = this.safeNumber (ticker, 'last'); + const day_change = this.safeNumber (ticker, 'day_change'); let percentage = undefined; let change = undefined; - let average = this.safeFloat (ticker, 'day_avg_price'); + let average = this.safeNumber (ticker, 'day_avg_price'); if (day_change !== undefined) { percentage = day_change * 100; if (previous !== undefined) { @@ -418,18 +419,18 @@ module.exports = class qtrade extends Exchange { if ((average === undefined) && (last !== undefined) && (previous !== undefined)) { average = this.sum (last, previous) / 2; } - const baseVolume = this.safeFloat (ticker, 'day_volume_market'); - const quoteVolume = this.safeFloat (ticker, 'day_volume_base'); + const baseVolume = this.safeNumber (ticker, 'day_volume_market'); + const quoteVolume = this.safeNumber (ticker, 'day_volume_base'); const vwap = this.vwap (baseVolume, quoteVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'day_high'), - 'low': this.safeFloat (ticker, 'day_low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'day_high'), + 'low': this.safeNumber (ticker, 'day_low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': previous, @@ -637,16 +638,16 @@ module.exports = class qtrade extends Exchange { const side = this.safeString (trade, 'side'); const marketId = this.safeString (trade, 'market_string'); const symbol = this.safeSymbol (marketId, market, '_'); - let cost = this.safeFloat2 (trade, 'base_volume', 'base_amount'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'market_amount', 'amount'); - if ((cost === undefined) && (amount !== undefined) && (price !== undefined)) { - if (price !== undefined) { - cost = price * amount; - } + let cost = this.safeNumber2 (trade, 'base_volume', 'base_amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'market_amount', 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'base_fee'); + const feeCost = this.safeNumber (trade, 'base_fee'); if (feeCost !== undefined) { const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; fee = { @@ -703,7 +704,7 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['free'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'balance'); account['used'] = 0; result[code] = account; } @@ -713,10 +714,10 @@ module.exports = class qtrade extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = (code in result) ? result[code] : this.account (); - account['used'] = this.safeFloat (balance, 'balance'); + account['used'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -845,10 +846,9 @@ module.exports = class qtrade extends Exchange { side = this.safeString (parts, 0); orderType = this.safeString (parts, 1); } - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'market_amount'); - let remaining = this.safeFloat (order, 'market_amount_remaining'); - let filled = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'market_amount'); + const remaining = this.safeNumber (order, 'market_amount_remaining'); const open = this.safeValue (order, 'open', false); const closeReason = this.safeString (order, 'close_reason'); let status = undefined; @@ -860,58 +860,21 @@ module.exports = class qtrade extends Exchange { status = 'closed'; } const marketId = this.safeString (order, 'market_string'); - const symbol = this.safeSymbol (marketId, market, '_'); + market = this.safeMarket (marketId, market, '_'); + const symbol = market['symbol']; const rawTrades = this.safeValue (order, 'trades', []); const parsedTrades = this.parseTrades (rawTrades, market, undefined, undefined, { 'order': id, 'side': side, 'type': orderType, }); - const numTrades = parsedTrades.length; - let lastTradeTimestamp = undefined; - let feeCost = undefined; - let cost = undefined; - if (numTrades > 0) { - feeCost = 0; - cost = 0; - filled = 0; - remaining = amount; - for (let i = 0; i < parsedTrades.length; i++) { - const trade = parsedTrades[i]; - feeCost = this.sum (trade['fee']['cost'], feeCost); - lastTradeTimestamp = this.safeInteger (trade, 'timestamp'); - cost = this.sum (trade['cost'], cost); - filled = this.sum (trade['amount'], filled); - remaining = Math.max (0, remaining - trade['amount']); - } - } - let fee = undefined; - if (feeCost !== undefined) { - const feeCurrencyCode = (market === undefined) ? undefined : market['quote']; - fee = { - 'currency': feeCurrencyCode, - 'cost': feeCost, - }; - } - if ((amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - let average = undefined; - if (filled !== undefined) { - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': orderType, 'timeInForce': undefined, @@ -919,15 +882,16 @@ module.exports = class qtrade extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, - 'fee': fee, - 'cost': cost, + 'fee': undefined, + 'fees': undefined, + 'cost': undefined, 'trades': parsedTrades, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -1396,7 +1360,7 @@ module.exports = class qtrade extends Exchange { const tagTo = tag; const cancelRequested = this.safeValue (transaction, 'cancel_requested'); const type = (cancelRequested === undefined) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); let status = this.parseTransactionStatus (this.safeString (transaction, 'status')); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/rightbtc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/rightbtc.js index d22048303..c1cc6bc9b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/rightbtc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/rightbtc.js @@ -185,8 +185,8 @@ module.exports = class rightbtc extends Exchange { return result; } - divideSafeFloat (x, key, divisor) { - const value = this.safeFloat (x, key); + divideSafeNumber (x, key, divisor) { + const value = this.safeNumber (x, key); if (value !== undefined) { return value / divisor; } @@ -196,12 +196,12 @@ module.exports = class rightbtc extends Exchange { parseTicker (ticker, market = undefined) { const symbol = market['symbol']; const timestamp = this.safeInteger (ticker, 'date'); - const last = this.divideSafeFloat (ticker, 'last', 1e8); - const high = this.divideSafeFloat (ticker, 'high', 1e8); - const low = this.divideSafeFloat (ticker, 'low', 1e8); - const bid = this.divideSafeFloat (ticker, 'buy', 1e8); - const ask = this.divideSafeFloat (ticker, 'sell', 1e8); - const baseVolume = this.divideSafeFloat (ticker, 'vol24h', 1e8); + const last = this.divideSafeNumber (ticker, 'last', 1e8); + const high = this.divideSafeNumber (ticker, 'high', 1e8); + const low = this.divideSafeNumber (ticker, 'low', 1e8); + const bid = this.divideSafeNumber (ticker, 'buy', 1e8); + const ask = this.divideSafeNumber (ticker, 'sell', 1e8); + const baseVolume = this.divideSafeNumber (ticker, 'vol24h', 1e8); return { 'symbol': symbol, 'timestamp': timestamp, @@ -305,9 +305,9 @@ module.exports = class rightbtc extends Exchange { let id = this.safeString (trade, 'tid'); id = this.safeString (trade, 'trade_id', id); const orderId = this.safeString (trade, 'order_id'); - const price = this.divideSafeFloat (trade, 'price', 1e8); - let amount = this.safeFloat (trade, 'amount'); - amount = this.safeFloat (trade, 'quantity', amount); + const price = this.divideSafeNumber (trade, 'price', 1e8); + let amount = this.safeNumber (trade, 'amount'); + amount = this.safeNumber (trade, 'quantity', amount); if (amount !== undefined) { amount = amount / 1e8; } @@ -404,8 +404,8 @@ module.exports = class rightbtc extends Exchange { const code = this.safeCurrencyCode (currencyId); const account = this.account (); // https://github.com/ccxt/ccxt/issues/3873 - account['free'] = this.divideSafeFloat (balance, 'balance', 1e8); - account['used'] = this.divideSafeFloat (balance, 'frozen', 1e8); + account['free'] = this.divideSafeNumber (balance, 'balance', 1e8); + account['used'] = this.divideSafeNumber (balance, 'frozen', 1e8); result[code] = account; } return this.parseBalance (result); @@ -494,30 +494,18 @@ module.exports = class rightbtc extends Exchange { } else if ('transactTime' in order) { timestamp = order['transactTime']; } - let price = this.safeFloat2 (order, 'limit', 'price'); + let price = this.safeNumber2 (order, 'limit', 'price'); if (price !== undefined) { price = price / 1e8; } - const amount = this.divideSafeFloat (order, 'quantity', 1e8); - let filled = this.divideSafeFloat (order, 'filled_quantity', 1e8); - let remaining = this.divideSafeFloat (order, 'rest', 1e8); - const cost = this.divideSafeFloat (order, 'cost', 1e8); + const amount = this.divideSafeNumber (order, 'quantity', 1e8); + const filled = this.divideSafeNumber (order, 'filled_quantity', 1e8); + const remaining = this.divideSafeNumber (order, 'rest', 1e8); + const cost = this.divideSafeNumber (order, 'cost', 1e8); // lines 483-494 should be generalized into a base class method - if (amount !== undefined) { - if (remaining === undefined) { - if (filled !== undefined) { - remaining = Math.max (0, amount - filled); - } - } - if (filled === undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - } - } - } const type = 'limit'; const side = this.safeStringLower (order, 'side'); - const feeCost = this.divideSafeFloat (order, 'min_fee', 1e8); + const feeCost = this.divideSafeNumber (order, 'min_fee', 1e8); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -525,13 +513,13 @@ module.exports = class rightbtc extends Exchange { feeCurrency = market['quote']; } fee = { - 'rate': this.safeFloat (order, 'fee'), + 'rate': this.safeNumber (order, 'fee'), 'cost': feeCost, 'currency': feeCurrency, }; } const trades = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -553,7 +541,7 @@ module.exports = class rightbtc extends Exchange { 'fee': fee, 'trades': trades, 'average': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ripio.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ripio.js index b3a30607e..8155014d3 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ripio.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/ripio.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { AuthenticationError, ExchangeError, BadSymbol, BadRequest, InvalidOrder, ArgumentsRequired, OrderNotFound, InsufficientFunds, DDoSProtection } = require ('./base/errors'); const { TICK_SIZE } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -149,12 +150,12 @@ module.exports = class ripio extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': this.safeFloat (market, 'min_amount'), - 'price': this.safeFloat (market, 'price_tick'), + 'amount': this.safeNumber (market, 'min_amount'), + 'price': this.safeNumber (market, 'price_tick'), }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), + 'min': this.safeNumber (market, 'min_amount'), 'max': undefined, }, 'price': { @@ -162,15 +163,15 @@ module.exports = class ripio extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'min_value'), + 'min': this.safeNumber (market, 'min_value'), 'max': undefined, }, }; const active = this.safeValue (market, 'enabled', true); const fees = this.safeValue (market, 'fees', []); const firstFee = this.safeValue (fees, 0, {}); - const maker = this.safeFloat (firstFee, 'maker_fee', 0.0); - const taker = this.safeFloat (firstFee, 'taker_fee', 0.0); + const maker = this.safeNumber (firstFee, 'maker_fee', 0.0); + const taker = this.safeNumber (firstFee, 'taker_fee', 0.0); result.push ({ 'id': id, 'symbol': symbol, @@ -277,18 +278,18 @@ module.exports = class ripio extends Exchange { const timestamp = this.parse8601 (this.safeString (ticker, 'created_at')); const marketId = this.safeString (ticker, 'pair'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'last_price'); - const average = this.safeFloat (ticker, 'avg'); + const last = this.safeNumber (ticker, 'last_price'); + const average = this.safeNumber (ticker, 'avg'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), - 'bidVolume': this.safeFloat (ticker, 'bid_volume'), - 'ask': this.safeFloat (ticker, 'ask'), - 'askVolume': this.safeFloat (ticker, 'ask_volume'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), + 'bidVolume': this.safeNumber (ticker, 'bid_volume'), + 'ask': this.safeNumber (ticker, 'ask'), + 'askVolume': this.safeNumber (ticker, 'ask_volume'), 'vwap': undefined, 'open': undefined, 'close': last, @@ -430,15 +431,14 @@ module.exports = class ripio extends Exchange { if (side !== undefined) { side = side.toLowerCase (); } - const price = this.safeFloat2 (trade, 'price', 'match_price'); - const amount = this.safeFloat2 (trade, 'amount', 'exchanged'); - let cost = undefined; - if ((amount !== undefined) && (price !== undefined)) { - cost = amount * price; - } + const priceString = this.safeString2 (trade, 'price', 'match_price'); + const amountString = this.safeString2 (trade, 'amount', 'exchanged'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'pair'); market = this.safeMarket (marketId, market); - const feeCost = this.safeFloat (trade, takerOrMaker + '_fee'); + const feeCost = this.safeNumber (trade, takerOrMaker + '_fee'); const orderId = this.safeString (trade, takerOrMaker); let fee = undefined; if (feeCost !== undefined) { @@ -512,11 +512,11 @@ module.exports = class ripio extends Exchange { const currencyId = this.safeString (balance, 'symbol'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -775,16 +775,16 @@ module.exports = class ripio extends Exchange { // } // const id = this.safeString (order, 'order_id'); - const amount = this.safeFloat (order, 'amount'); - let cost = this.safeFloat (order, 'notional'); + const amount = this.safeNumber (order, 'amount'); + let cost = this.safeNumber (order, 'notional'); const type = this.safeStringLower (order, 'order_type'); const priceField = (type === 'market') ? 'fill_price' : 'limit_price'; - const price = this.safeFloat (order, priceField); + const price = this.safeNumber (order, priceField); const side = this.safeStringLower (order, 'side'); const status = this.parseOrderStatus (this.safeString (order, 'status')); const timestamp = this.safeTimestamp (order, 'created_at'); let average = this.safeValue (order, 'fill_price'); - let filled = this.safeFloat (order, 'filled'); + let filled = this.safeNumber (order, 'filled'); let remaining = undefined; const fills = this.safeValue (order, 'fills'); let trades = undefined; @@ -819,7 +819,7 @@ module.exports = class ripio extends Exchange { } const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const stopPrice = this.safeFloat (order, 'stop_price'); + const stopPrice = this.safeNumber (order, 'stop_price'); return { 'id': id, 'clientOrderId': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/southxchange.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/southxchange.js index d2bdd8cec..96ca247a0 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/southxchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/southxchange.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -114,14 +115,14 @@ module.exports = class southxchange extends Exchange { const balance = response[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const deposited = this.safeFloat (balance, 'Deposited'); - const unconfirmed = this.safeFloat (balance, 'Unconfirmed'); + const deposited = this.safeString (balance, 'Deposited'); + const unconfirmed = this.safeString (balance, 'Unconfirmed'); const account = this.account (); - account['free'] = this.safeFloat (balance, 'Available'); - account['total'] = this.sum (deposited, unconfirmed); + account['free'] = this.safeString (balance, 'Available'); + account['total'] = Precise.stringAdd (deposited, unconfirmed); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -139,16 +140,16 @@ module.exports = class southxchange extends Exchange { if (market) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'Last'); + const last = this.safeNumber (ticker, 'Last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), 'high': undefined, 'low': undefined, - 'bid': this.safeFloat (ticker, 'Bid'), + 'bid': this.safeNumber (ticker, 'Bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'Ask'), + 'ask': this.safeNumber (ticker, 'Ask'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -156,9 +157,9 @@ module.exports = class southxchange extends Exchange { 'last': last, 'previousClose': undefined, 'change': undefined, - 'percentage': this.safeFloat (ticker, 'Variation24Hr'), + 'percentage': this.safeNumber (ticker, 'Variation24Hr'), 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'Volume24Hr'), + 'baseVolume': this.safeNumber (ticker, 'Volume24Hr'), 'quoteVolume': undefined, 'info': ticker, }; @@ -192,14 +193,11 @@ module.exports = class southxchange extends Exchange { parseTrade (trade, market) { const timestamp = this.safeTimestamp (trade, 'At'); - const price = this.safeFloat (trade, 'Price'); - const amount = this.safeFloat (trade, 'Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'Price'); + const amountString = this.safeString (trade, 'Amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const side = this.safeString (trade, 'Type'); let symbol = undefined; if (market !== undefined) { @@ -240,21 +238,13 @@ module.exports = class southxchange extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const timestamp = undefined; - const price = this.safeFloat (order, 'LimitPrice'); - const amount = this.safeFloat (order, 'OriginalAmount'); - const remaining = this.safeFloat (order, 'Amount'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - cost = price * amount; - if (remaining !== undefined) { - filled = amount - remaining; - } - } + const price = this.safeNumber (order, 'LimitPrice'); + const amount = this.safeNumber (order, 'OriginalAmount'); + const remaining = this.safeNumber (order, 'Amount'); const type = 'limit'; const side = this.safeStringLower (order, 'Type'); const id = this.safeString (order, 'Code'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -269,15 +259,14 @@ module.exports = class southxchange extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, - 'filled': filled, + 'cost': undefined, + 'filled': undefined, 'remaining': remaining, 'status': status, 'fee': undefined, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { @@ -410,8 +399,8 @@ module.exports = class southxchange extends Exchange { const type = this.safeString (item, 'Type'); const ledgerEntryType = this.parseLedgerEntryType (type); const code = this.safeCurrencyCode (this.safeString (item, 'CurrencyCode'), currency); - let amount = this.safeFloat (item, 'Amount'); - const after = this.safeFloat (item, 'TotalBalance'); + let amount = this.safeNumber (item, 'Amount'); + const after = this.safeNumber (item, 'TotalBalance'); let before = undefined; if (amount !== undefined) { if (after !== undefined) { @@ -582,7 +571,7 @@ module.exports = class southxchange extends Exchange { // } // const id = this.safeString (transaction, 'MovementId'); - const amount = this.safeFloat (transaction, 'Amount'); + const amount = this.safeNumber (transaction, 'Amount'); const address = this.safeString (transaction, 'Address'); const addressTo = address; const addressFrom = undefined; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/stex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/stex.js index af2e256f3..f4979c48a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/stex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/stex.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ArgumentsRequired, AuthenticationError, ExchangeError, InsufficientFunds, OrderNotFound, PermissionDenied, BadRequest, DDoSProtection } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -186,6 +187,7 @@ module.exports = class stex extends Exchange { 'BITSW': 'BITS', 'BHD': 'Bithold', 'BTH': 'Bithereum', + 'MPH': 'Chasyr Token', 'SBTC': 'SBTCT', // SiamBitcoin }, 'options': { @@ -249,7 +251,7 @@ module.exports = class stex extends Exchange { // differentiated fees for each particular method const code = this.safeCurrencyCode (this.safeString (currency, 'code')); const precision = this.safeInteger (currency, 'precision'); - const fee = this.safeFloat (currency, 'withdrawal_fee_const'); // todo: redesign + const fee = this.safeNumber (currency, 'withdrawal_fee_const'); // todo: redesign const active = this.safeValue (currency, 'active', true); result[code] = { 'id': id, @@ -266,11 +268,11 @@ module.exports = class stex extends Exchange { 'price': { 'min': Math.pow (10, -precision), 'max': undefined }, 'cost': { 'min': undefined, 'max': undefined }, 'deposit': { - 'min': this.safeFloat (currency, 'minimum_deposit_amount'), + 'min': this.safeNumber (currency, 'minimum_deposit_amount'), 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minimum_withdrawal_amount'), + 'min': this.safeNumber (currency, 'minimum_withdrawal_amount'), 'max': undefined, }, }, @@ -331,11 +333,11 @@ module.exports = class stex extends Exchange { 'price': this.safeInteger (market, 'market_precision'), }; const active = this.safeValue (market, 'active'); - const minBuyPrice = this.safeFloat (market, 'min_buy_price'); - const minSellPrice = this.safeFloat (market, 'min_sell_price'); + const minBuyPrice = this.safeNumber (market, 'min_buy_price'); + const minSellPrice = this.safeNumber (market, 'min_sell_price'); const minPrice = Math.max (minBuyPrice, minSellPrice); - const buyFee = this.safeFloat (market, 'buy_fee_percent') / 100; - const sellFee = this.safeFloat (market, 'sell_fee_percent') / 100; + const buyFee = this.safeNumber (market, 'buy_fee_percent') / 100; + const sellFee = this.safeNumber (market, 'sell_fee_percent') / 100; const fee = Math.max (buyFee, sellFee); result.push ({ 'id': id, @@ -354,7 +356,7 @@ module.exports = class stex extends Exchange { 'precision': precision, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'min_order_amount'), + 'min': this.safeNumber (market, 'min_order_amount'), 'max': undefined, }, 'price': { 'min': minPrice, 'max': undefined }, @@ -518,8 +520,8 @@ module.exports = class stex extends Exchange { const timestamp = this.safeInteger (ticker, 'timestamp'); const marketId = this.safeString2 (ticker, 'id', 'symbol'); const symbol = this.safeSymbol (marketId, market, '_'); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let percentage = undefined; if (last !== undefined) { @@ -532,11 +534,11 @@ module.exports = class stex extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -546,20 +548,12 @@ module.exports = class stex extends Exchange { 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volumeQuote'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volumeQuote'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } - parseTickers (tickers, symbols = undefined) { - const result = []; - for (let i = 0; i < tickers.length; i++) { - result.push (this.parseTicker (tickers[i])); - } - return this.filterByArray (result, 'symbol', symbols); - } - async fetchTickers (symbols = undefined, params = {}) { await this.loadMarkets (); const response = await this.publicGetTicker (params); @@ -625,11 +619,11 @@ module.exports = class stex extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -704,12 +698,11 @@ module.exports = class stex extends Exchange { // const id = this.safeString (trade, 'id'); const timestamp = this.safeTimestamp (trade, 'timestamp'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let symbol = undefined; if ((symbol === undefined) && (market !== undefined)) { symbol = market['symbol']; @@ -822,11 +815,11 @@ module.exports = class stex extends Exchange { const balance = balances[i]; const code = this.safeCurrencyCode (this.safeString (balance, 'currency_id')); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'frozen_balance'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'frozen_balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOrderStatus (status) { @@ -885,9 +878,9 @@ module.exports = class stex extends Exchange { const marketId = this.safeString2 (order, 'currency_pair_id', 'currency_pair_name'); const symbol = this.safeSymbol (marketId, market, '_'); const timestamp = this.safeTimestamp (order, 'timestamp'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'initial_amount'); - const filled = this.safeFloat (order, 'processed_amount'); + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'initial_amount'); + const filled = this.safeNumber (order, 'processed_amount'); let remaining = undefined; let cost = undefined; if (filled !== undefined) { @@ -917,7 +910,7 @@ module.exports = class stex extends Exchange { 'order': id, }); } - const stopPrice = this.safeFloat (order, 'trigger_price'); + const stopPrice = this.safeNumber (order, 'trigger_price'); const result = { 'info': order, 'id': id, @@ -948,7 +941,7 @@ module.exports = class stex extends Exchange { if (numFees > 0) { result['fees'] = []; for (let i = 0; i < fees.length; i++) { - const feeCost = this.safeFloat (fees[i], 'amount'); + const feeCost = this.safeNumber (fees[i], 'amount'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (fees[i], 'currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1532,13 +1525,13 @@ module.exports = class stex extends Exchange { code = currency['code']; } const type = ('deposit_status_id' in transaction) ? 'deposit' : 'withdrawal'; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeStringLower (transaction, 'status')); const timestamp = this.safeTimestamp2 (transaction, 'timestamp', 'created_ts'); const updated = this.safeTimestamp (transaction, 'updated_ts'); const txid = this.safeString (transaction, 'txid'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (transaction, 'fee_currency_id', 'deposit_fee_currency_id'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -1774,8 +1767,8 @@ module.exports = class stex extends Exchange { for (let i = 0; i < data.length; i++) { const id = this.safeString (data[i], 'id'); const code = this.safeCurrencyCode (id); - withdrawFees[code] = this.safeFloat (data[i], 'withdrawal_fee_const'); - depositFees[code] = this.safeFloat (data[i], 'deposit_fee_const'); + withdrawFees[code] = this.safeNumber (data[i], 'withdrawal_fee_const'); + depositFees[code] = this.safeNumber (data[i], 'deposit_fee_const'); } return { 'withdraw': withdrawFees, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/Exchange/test.ticker.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/Exchange/test.ticker.js index 7d91ea0ba..201873531 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/Exchange/test.ticker.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/Exchange/test.ticker.js @@ -74,6 +74,7 @@ module.exports = (exchange, ticker, method, symbol) => { if (![ + 'bybit', 'coinmarketcap', 'xbtce', 'coss', diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/functions/test.number.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/functions/test.number.js index f2e5eedd3..23e9f7926 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/functions/test.number.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/functions/test.number.js @@ -1,6 +1,7 @@ 'use strict' const { numberToString, decimalToPrecision, ROUND, TRUNCATE, DECIMAL_PLACES, TICK_SIZE, PAD_WITH_ZERO, SIGNIFICANT_DIGITS, toWei, fromWei } = require ('../../../../ccxt'); +const Precise = require ('../../../base/Precise') const assert = require ('assert'); // ---------------------------------------------------------------------------- @@ -287,3 +288,58 @@ assert (decimalToPrecision ('1602000000000000000000', TRUNCATE, 3, SIGNIFICANT_D // throws (() => // decimalToPrecision ('0.01', TRUNCATE, -1, TICK_SIZE), // "TICK_SIZE cant be used with negative numPrecisionDigits") + +// ---------------------------------------------------------------------------- + +const w = '-1.123e-6'; +const x = '0.00000002'; +const y = '69696900000'; +const z = '0'; +const a = '1e8'; + +assert (Precise.stringMul (x, y) === '1393.938'); +assert (Precise.stringMul (y, x) === '1393.938'); +assert (Precise.stringAdd (x, y) === '69696900000.00000002'); +assert (Precise.stringAdd (y, x) === '69696900000.00000002'); +assert (Precise.stringSub (x, y) === '-69696899999.99999998'); +assert (Precise.stringSub (y, x) === '69696899999.99999998'); +assert (Precise.stringDiv (x, y, 1) === '0'); +assert (Precise.stringDiv (x, y) === '0'); +assert (Precise.stringDiv (x, y, 19) === '0.0000000000000000002'); +assert (Precise.stringDiv (x, y, 20) === '0.00000000000000000028'); +assert (Precise.stringDiv (x, y, 21) === '0.000000000000000000286'); +assert (Precise.stringDiv (x, y, 22) === '0.0000000000000000002869'); +assert (Precise.stringDiv (y, x) === '3484845000000000000'); + +assert (Precise.stringMul (x, w) === '-0.00000000000002246'); +assert (Precise.stringMul (w, x) === '-0.00000000000002246'); +assert (Precise.stringAdd (x, w) === '-0.000001103'); +assert (Precise.stringAdd (w, x) === '-0.000001103'); +assert (Precise.stringSub (x, w) === '0.000001143'); +assert (Precise.stringSub (w, x) === '-0.000001143'); +assert (Precise.stringDiv (x, w) === '-0.017809439002671415'); +assert (Precise.stringDiv (w, x) === '-56.15'); + +assert (Precise.stringMul (z, w) === '0'); +assert (Precise.stringMul (z, x) === '0'); +assert (Precise.stringMul (z, y) === '0'); +assert (Precise.stringMul (w, z) === '0'); +assert (Precise.stringMul (x, z) === '0'); +assert (Precise.stringMul (y, z) === '0'); +assert (Precise.stringAdd (z, w) === '-0.000001123'); +assert (Precise.stringAdd (z, x) === '0.00000002'); +assert (Precise.stringAdd (z, y) === '69696900000'); +assert (Precise.stringAdd (w, z) === '-0.000001123'); +assert (Precise.stringAdd (x, z) === '0.00000002'); +assert (Precise.stringAdd (y, z) === '69696900000'); + +assert (Precise.stringMul (x, a) === '2'); +assert (Precise.stringMul (a, x) === '2'); +assert (Precise.stringMul (y, a) === '6969690000000000000'); +assert (Precise.stringMul (a, y) === '6969690000000000000'); +assert (Precise.stringDiv (y, a) === '696.969'); +assert (Precise.stringDiv (y, a, -1) === '690'); +assert (Precise.stringDiv (y, a, 0) === '696'); +assert (Precise.stringDiv (y, a, 1) === '696.9'); +assert (Precise.stringDiv (y, a, 2) === '696.96'); +assert (Precise.stringDiv (a, y) === '0.001434784043479695'); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/test.base.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/test.base.js index 0eb7fcffa..6068fa10a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/test.base.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/test/base/test.base.js @@ -167,7 +167,7 @@ describe ('ccxt base code', () => { const exchange = new Exchange ({ 'id': 'mock' }) const propsSeenBefore = index ( - ["isNode", "empty", "keys", "values", "extend", "clone", "index", "ordered", "unique", "keysort", "indexBy", "groupBy", "filterBy", "sortBy", "flatten", "pluck", "omit", "sum", "deepExtend", "uuid", "unCamelCase", "capitalize", "isNumber", "isArray", "isObject", "isString", "isStringCoercible", "isDictionary", "hasProps", "prop", "asFloat", "asInteger", "safeFloat", "safeInteger", "safeValue", "safeString", "decimal", "toFixed", "truncate", "truncateToString", "precisionFromString", "stringToBinary", "stringToBase64", "base64ToBinary", "base64ToString", "binaryToString", "binaryConcat", "urlencode", "rawencode", "urlencodeBase64", "hash", "hmac", "jwt", "time", "setTimeout_safe", "sleep", "TimedOut", "timeout", "throttle", "json", "unjson", "aggregate", "is_node", "index_by", "group_by", "filter_by", "sort_by", "deep_extend", "un_camel_case", "is_number", "is_array", "is_object", "is_string", "is_string_coercible", "is_dictionary", "has_props", "as_float", "as_integer", "safe_float", "safe_integer", "safe_value", "safe_string", "to_fixed", "truncate_to_string", "precision_from_string", "string_to_binary", "string_to_base64", "utf16To_base64", "base64To_binary", "base64To_string", "binary_to_string", "binary_concat", "urlencode_base64", "set_timeout_safe", "Timed_out", "encode", "decode", "userAgents", "headers", "proxy", "origin", "iso8601", "parse8601", "milliseconds", "microseconds", "seconds", "id", "enableRateLimit", "rateLimit", "parseJsonResponse", "substituteCommonCurrencyCodes", "parseBalanceFromOpenOrders", "verbose", "debug", "journal", "userAgent", "twofa", "timeframes", "hasPublicAPI", "hasPrivateAPI", "hasCORS", "hasDeposit", "hasFetchBalance", "hasFetchClosedOrders", "hasFetchCurrencies", "hasFetchMyTrades", "hasFetchOHLCV", "hasFetchOpenOrders", "hasFetchOrder", "hasFetchOrderBook", "hasFetchOrders", "hasFetchTicker", "hasFetchTickers", "hasFetchBidsAsks", "hasFetchTrades", "hasWithdraw", "hasCreateOrder", "hasCancelOrder", "apiKey", "secret", "uid", "login", "password", "requiredCredentials", "exceptions", "balance", "orderbooks", "tickers", "fees", "orders", "trades", "currencies", "last_http_response", "last_json_response", "arrayConcat", "market_id", "market_ids", "array_concat", "implode_params", "extract_params", "fetch_balance", "fetch_free_balance", "fetch_used_balance","fetch_total_balance", "fetch_l2_order_book", "fetch_order_book", "fetch_bids_asks", "fetch_tickers", "fetch_ticker", "fetch_trades", "fetch_order", "fetch_orders", "fetch_open_orders", "fetch_closed_orders", "fetch_order_status", "fetch_markets", "load_markets", "set_markets", "parse_balance", "parse_bid_ask", "parse_bids_asks", "parse_order_book", "parse_trades", "parse_orders", "parse_ohlcv", "parse_ohlcvs", "edit_limit_buy_order", "edit_limit_sell_order", "edit_limit_order", "edit_order", "create_limit_buy_order", "create_limit_sell_order", "create_market_buy_order", "create_market_sell_order", "create_order", "calculate_fee", "common_currency_code", "price_to_precision", "amount_to_precision", "amount_to_string", "fee_to_precision", "cost_to_precision", "constructor", "getMarket", "describe", "defaults", "nonce", "encodeURIComponent", "checkRequiredCredentials", "initRestRateLimiter", "defineRestApi", "fetch", "fetch2", "request", "handleErrors", "defaultErrorHandler", "handleRestErrors", "handleRestResponse", "setMarkets", "loadMarkets", "fetchBidsAsks", "fetchTickers", "fetchOrder", "fetchOrders", "fetchOpenOrders", "fetchClosedOrders", "fetchMyTrades", "fetchCurrencies", "fetchMarkets", "fetchOrderStatus", "account", "commonCurrencyCode", "currency", "market", "marketId", "marketIds", "symbol", "extractParams", "implodeParams", "url", "parseBidAsk", "parseBidsAsks", "fetchL2OrderBook", "parseOrderBook", "parseBalance", "fetchPartialBalance", "fetchFreeBalance", "fetchUsedBalance", "fetchTotalBalance", "filterBySinceLimit", "parseTrades", "parseOrders", "filterOrdersBySymbol", "parseOHLCV", "parseOHLCVs", "editLimitBuyOrder", "editLimitSellOrder", "editLimitOrder", "editOrder", "createLimitBuyOrder", "createLimitSellOrder", "createMarketBuyOrder", "createMarketSellOrder", "costToPrecision", "priceToPrecision", "amountToPrecision", "amountToLots", "feeToPrecision", "calculateFee", "Ymd", "YmdHMS"] + ["isNode", "empty", "keys", "values", "extend", "clone", "index", "ordered", "unique", "keysort", "indexBy", "groupBy", "filterBy", "sortBy", "flatten", "pluck", "omit", "sum", "deepExtend", "uuid", "unCamelCase", "capitalize", "isNumber", "isArray", "isObject", "isString", "isStringCoercible", "isDictionary", "hasProps", "prop", "asFloat", "asInteger", "safeFloat", "safeInteger", "safeValue", "safeString", "decimal", "toFixed", "truncate", "truncateToString", "precisionFromString", "stringToBinary", "stringToBase64", "base64ToBinary", "base64ToString", "binaryToString", "binaryConcat", "urlencode", "rawencode", "urlencodeBase64", "hash", "hmac", "jwt", "time", "setTimeout_safe", "sleep", "TimedOut", "timeout", "throttle", "json", "aggregate", "is_node", "index_by", "group_by", "filter_by", "sort_by", "deep_extend", "un_camel_case", "is_number", "is_array", "is_object", "is_string", "is_string_coercible", "is_dictionary", "has_props", "as_float", "as_integer", "safe_float", "safe_integer", "safe_value", "safe_string", "to_fixed", "truncate_to_string", "precision_from_string", "string_to_binary", "string_to_base64", "utf16To_base64", "base64To_binary", "base64To_string", "binary_to_string", "binary_concat", "urlencode_base64", "set_timeout_safe", "Timed_out", "encode", "decode", "userAgents", "headers", "proxy", "origin", "iso8601", "parse8601", "milliseconds", "microseconds", "seconds", "id", "enableRateLimit", "rateLimit", "parseJsonResponse", "substituteCommonCurrencyCodes", "parseBalanceFromOpenOrders", "verbose", "debug", "journal", "userAgent", "twofa", "timeframes", "hasPublicAPI", "hasPrivateAPI", "hasCORS", "hasDeposit", "hasFetchBalance", "hasFetchClosedOrders", "hasFetchCurrencies", "hasFetchMyTrades", "hasFetchOHLCV", "hasFetchOpenOrders", "hasFetchOrder", "hasFetchOrderBook", "hasFetchOrders", "hasFetchTicker", "hasFetchTickers", "hasFetchBidsAsks", "hasFetchTrades", "hasWithdraw", "hasCreateOrder", "hasCancelOrder", "apiKey", "secret", "uid", "login", "password", "requiredCredentials", "exceptions", "balance", "orderbooks", "tickers", "fees", "orders", "trades", "currencies", "last_http_response", "last_json_response", "arrayConcat", "market_id", "market_ids", "array_concat", "implode_params", "extract_params", "fetch_balance", "fetch_free_balance", "fetch_used_balance","fetch_total_balance", "fetch_l2_order_book", "fetch_order_book", "fetch_bids_asks", "fetch_tickers", "fetch_ticker", "fetch_trades", "fetch_order", "fetch_orders", "fetch_open_orders", "fetch_closed_orders", "fetch_order_status", "fetch_markets", "load_markets", "set_markets", "parse_balance", "parse_bid_ask", "parse_bids_asks", "parse_order_book", "parse_trades", "parse_orders", "parse_ohlcv", "parse_ohlcvs", "edit_limit_buy_order", "edit_limit_sell_order", "edit_limit_order", "edit_order", "create_limit_buy_order", "create_limit_sell_order", "create_market_buy_order", "create_market_sell_order", "create_order", "calculate_fee", "common_currency_code", "price_to_precision", "amount_to_precision", "amount_to_string", "fee_to_precision", "cost_to_precision", "constructor", "getMarket", "describe", "defaults", "nonce", "encodeURIComponent", "checkRequiredCredentials", "initRestRateLimiter", "defineRestApi", "fetch", "fetch2", "request", "handleErrors", "defaultErrorHandler", "handleRestErrors", "handleRestResponse", "setMarkets", "loadMarkets", "fetchBidsAsks", "fetchTickers", "fetchOrder", "fetchOrders", "fetchOpenOrders", "fetchClosedOrders", "fetchMyTrades", "fetchCurrencies", "fetchMarkets", "fetchOrderStatus", "account", "commonCurrencyCode", "currency", "market", "marketId", "marketIds", "symbol", "extractParams", "implodeParams", "url", "parseBidAsk", "parseBidsAsks", "fetchL2OrderBook", "parseOrderBook", "parseBalance", "fetchPartialBalance", "fetchFreeBalance", "fetchUsedBalance", "fetchTotalBalance", "filterBySinceLimit", "parseTrades", "parseOrders", "filterOrdersBySymbol", "parseOHLCV", "parseOHLCVs", "editLimitBuyOrder", "editLimitSellOrder", "editLimitOrder", "editOrder", "createLimitBuyOrder", "createLimitSellOrder", "createMarketBuyOrder", "createMarketSellOrder", "costToPrecision", "priceToPrecision", "amountToPrecision", "amountToLots", "feeToPrecision", "calculateFee", "Ymd", "YmdHMS"] ) const props = index (Object.getOwnPropertyNames (exchange).concat ( diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/therock.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/therock.js index 12217e2b2..88ccb385d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/therock.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/therock.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, OrderNotFound, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -171,8 +172,8 @@ module.exports = class therock extends Exchange { const base = this.safeCurrencyCode (baseId); const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; - const buy_fee = this.safeFloat (market, 'buy_fee'); - const sell_fee = this.safeFloat (market, 'sell_fee'); + const buy_fee = this.safeNumber (market, 'buy_fee'); + const sell_fee = this.safeNumber (market, 'sell_fee'); let taker = Math.max (buy_fee, sell_fee); taker = taker / 100; const maker = taker; @@ -193,11 +194,11 @@ module.exports = class therock extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minimum_quantity_offer'), + 'min': this.safeNumber (market, 'minimum_quantity_offer'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'minimum_price_offer'), + 'min': this.safeNumber (market, 'minimum_price_offer'), 'max': undefined, }, 'cost': { @@ -221,11 +222,11 @@ module.exports = class therock extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'trading_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'trading_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -244,27 +245,27 @@ module.exports = class therock extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, - 'previousClose': this.safeFloat (ticker, 'close'), // previous day close, if any + 'previousClose': this.safeNumber (ticker, 'close'), // previous day close, if any 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume_traded'), - 'quoteVolume': this.safeFloat (ticker, 'volume'), + 'baseVolume': this.safeNumber (ticker, 'volume_traded'), + 'quoteVolume': this.safeNumber (ticker, 'volume'), 'info': ticker, }; } @@ -339,14 +340,11 @@ module.exports = class therock extends Exchange { const id = this.safeString (trade, 'id'); const orderId = this.safeString (trade, 'order_id'); const side = this.safeString (trade, 'side'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; let feeCost = undefined; const transactions = this.safeValue (trade, 'transactions', []); @@ -356,7 +354,7 @@ module.exports = class therock extends Exchange { if (feeCost === undefined) { feeCost = 0; } - feeCost = this.sum (feeCost, this.safeFloat (feeTransactions[i], 'price')); + feeCost = this.sum (feeCost, this.safeNumber (feeTransactions[i], 'price')); } if (feeCost !== undefined) { fee = { @@ -511,7 +509,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (item, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (item, 'price'); + const amount = this.safeNumber (item, 'price'); const timestamp = this.parse8601 (this.safeString (item, 'date')); const status = 'ok'; return { @@ -743,7 +741,7 @@ module.exports = class therock extends Exchange { } const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); - const amount = this.safeFloat (transaction, 'price'); + const amount = this.safeNumber (transaction, 'price'); const timestamp = this.parse8601 (this.safeString (transaction, 'date')); const status = 'ok'; // todo parse tags @@ -918,15 +916,15 @@ module.exports = class therock extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'date')); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'side'); - const amount = this.safeFloat (order, 'amount'); - const remaining = this.safeFloat (order, 'amount_unfilled'); + const amount = this.safeNumber (order, 'amount'); + const remaining = this.safeNumber (order, 'amount_unfilled'); let filled = undefined; if (amount !== undefined) { if (remaining !== undefined) { filled = amount - remaining; } } - const price = this.safeFloat (order, 'price'); + const price = this.safeNumber (order, 'price'); let trades = this.safeValue (order, 'trades'); let cost = undefined; let average = undefined; @@ -953,7 +951,7 @@ module.exports = class therock extends Exchange { cost = 0; } } - const stopPrice = this.safeFloat (order, 'conditional_price'); + const stopPrice = this.safeNumber (order, 'conditional_price'); return { 'id': id, 'clientOrderId': undefined, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidebit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidebit.js index acf65de25..05efc673a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidebit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidebit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, InsufficientFunds, OrderNotFound, ArgumentsRequired } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -182,11 +183,11 @@ module.exports = class tidebit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -211,15 +212,15 @@ module.exports = class tidebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), - 'ask': this.safeFloat (ticker, 'sell'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), + 'ask': this.safeNumber (ticker, 'sell'), 'bidVolume': undefined, 'askVolume': undefined, 'vwap': undefined, @@ -230,7 +231,7 @@ module.exports = class tidebit extends Exchange { 'percentage': undefined, 'previousClose': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; @@ -264,9 +265,14 @@ module.exports = class tidebit extends Exchange { parseTrade (trade, market = undefined) { const timestamp = this.parse8601 (this.safeString (trade, 'created_at')); const id = this.safeString (trade, 'id'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'volume'); - const cost = this.safeFloat (trade, 'funds'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber (trade, 'funds'); + if (cost === undefined) { + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + } let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -311,11 +317,11 @@ module.exports = class tidebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), - this.safeFloat (ohlcv, 1), - this.safeFloat (ohlcv, 2), - this.safeFloat (ohlcv, 3), - this.safeFloat (ohlcv, 4), - this.safeFloat (ohlcv, 5), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), ]; } @@ -401,18 +407,12 @@ module.exports = class tidebit extends Exchange { const id = this.safeString (order, 'id'); const type = this.safeString (order, 'ord_type'); const side = this.safeString (order, 'side'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const filled = this.safeFloat (order, 'executed_volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - let cost = undefined; - if (price !== undefined) { - if (filled !== undefined) { - cost = price * filled; - } - } - const average = this.safeFloat (order, 'avg_price'); - return { + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const filled = this.safeNumber (order, 'executed_volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const average = this.safeNumber (order, 'avg_price'); + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -429,12 +429,12 @@ module.exports = class tidebit extends Exchange { 'amount': amount, 'filled': filled, 'remaining': remaining, - 'cost': cost, + 'cost': undefined, 'trades': undefined, 'fee': undefined, 'info': order, 'average': average, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidex.js index 0988a4ad1..65c0e6d9e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/tidex.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class tidex extends Exchange { describe () { @@ -83,6 +84,7 @@ module.exports = class tidex extends Exchange { }, 'fees': { 'trading': { + 'feeSide': 'get', 'tierBased': false, 'percentage': true, 'taker': 0.1 / 100, @@ -127,19 +129,48 @@ module.exports = class tidex extends Exchange { async fetchCurrencies (params = {}) { const response = await this.webGetCurrency (params); + // + // [ + // { + // "id":2, + // "symbol":"BTC", + // "type":2, + // "name":"Bitcoin", + // "amountPoint":8, + // "depositEnable":true, + // "depositMinAmount":0.0005, + // "withdrawEnable":true, + // "withdrawFee":0.0004, + // "withdrawMinAmount":0.0005, + // "settings":{ + // "Blockchain":"https://blockchair.com/bitcoin/", + // "TxUrl":"https://blockchair.com/bitcoin/transaction/{0}", + // "AddrUrl":"https://blockchair.com/bitcoin/address/{0}", + // "ConfirmationCount":3, + // "NeedMemo":false + // }, + // "visible":true, + // "isDelisted":false + // } + // ] + // const result = {}; for (let i = 0; i < response.length; i++) { const currency = response[i]; const id = this.safeString (currency, 'symbol'); - const precision = currency['amountPoint']; + const precision = this.safeInteger (currency, 'amountPoint'); const code = this.safeCurrencyCode (id); - let active = currency['visible'] === true; - const canWithdraw = currency['withdrawEnable'] === true; - const canDeposit = currency['depositEnable'] === true; + const visible = this.safeValue (currency, 'visible'); + let active = visible === true; + const withdrawEnable = this.safeValue (currency, 'withdrawEnable'); + const depositEnable = this.safeValue (currency, 'depositEnable'); + const canWithdraw = withdrawEnable === true; + const canDeposit = depositEnable === true; if (!canWithdraw || !canDeposit) { active = false; } const name = this.safeString (currency, 'name'); + const fee = this.safeNumber (currency, 'withdrawFee'); result[code] = { 'id': id, 'code': code, @@ -149,7 +180,7 @@ module.exports = class tidex extends Exchange { 'funding': { 'withdraw': { 'active': canWithdraw, - 'fee': currency['withdrawFee'], + 'fee': fee, }, 'deposit': { 'active': canDeposit, @@ -170,11 +201,11 @@ module.exports = class tidex extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'withdrawMinAmount'), + 'min': this.safeNumber (currency, 'withdrawMinAmount'), 'max': undefined, }, 'deposit': { - 'min': this.safeFloat (currency, 'depositMinAmount'), + 'min': this.safeNumber (currency, 'depositMinAmount'), 'max': undefined, }, }, @@ -184,26 +215,25 @@ module.exports = class tidex extends Exchange { return result; } - calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) { - const market = this.markets[symbol]; - let key = 'quote'; - const rate = market[takerOrMaker]; - let cost = parseFloat (this.costToPrecision (symbol, amount * rate)); - if (side === 'sell') { - cost *= price; - } else { - key = 'base'; - } - return { - 'type': takerOrMaker, - 'currency': market[key], - 'rate': rate, - 'cost': cost, - }; - } - async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615861869, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":3.0, + // "min_amount":0.001, + // "max_amount":1000000.0, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.1, + // }, + // }, + // } + // const markets = response['pairs']; const keys = Object.keys (markets); const result = []; @@ -220,19 +250,20 @@ module.exports = class tidex extends Exchange { }; const limits = { 'amount': { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }, 'price': { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }, 'cost': { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }, }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -241,7 +272,7 @@ module.exports = class tidex extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -262,11 +293,11 @@ module.exports = class tidex extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (funds, currencyId, {}); const account = this.account (); - account['free'] = this.safeFloat (balance, 'value'); - account['used'] = this.safeFloat (balance, 'inOrders'); + account['free'] = this.safeString (balance, 'value'); + account['used'] = this.safeString (balance, 'inOrders'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -338,16 +369,16 @@ module.exports = class tidex extends Exchange { timestamp = undefined; } } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -356,9 +387,9 @@ module.exports = class tidex extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -406,16 +437,19 @@ module.exports = class tidex extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const orderId = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const type = 'limit'; // all trades are still limit trades let takerOrMaker = undefined; let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -434,12 +468,6 @@ module.exports = class tidex extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, takerOrMaker); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': orderId, @@ -495,17 +523,18 @@ module.exports = class tidex extends Exchange { let status = 'open'; let filled = 0.0; let remaining = amount; - if ('return' in response) { - id = this.safeString (response['return'], 'order_id'); + const returnResult = this.safeValue (response, 'return'); + if (returnResult !== undefined) { + id = this.safeString (returnResult, 'order_id'); if (id === '0') { - id = this.safeString (response['return'], 'init_order_id'); + id = this.safeString (returnResult, 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (returnResult, 'received', filled); + remaining = this.safeNumber (returnResult, 'remains', amount); } const timestamp = this.milliseconds (); - return { + return this.safeOrder ({ 'id': id, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), @@ -515,7 +544,7 @@ module.exports = class tidex extends Exchange { 'type': type, 'side': side, 'price': price, - 'cost': price * filled, + 'cost': undefined, 'amount': amount, 'remaining': remaining, 'filled': filled, @@ -525,7 +554,7 @@ module.exports = class tidex extends Exchange { 'clientOrderId': undefined, 'average': undefined, 'trades': undefined, - }; + }); } async cancelOrder (id, symbol = undefined, params = {}) { @@ -554,23 +583,15 @@ module.exports = class tidex extends Exchange { const symbol = this.safeSymbol (marketId, market); let remaining = undefined; let amount = undefined; - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; + const price = this.safeNumber (order, 'rate'); if ('start_amount' in order) { - amount = this.safeFloat (order, 'start_amount'); - remaining = this.safeFloat (order, 'amount'); + amount = this.safeNumber (order, 'start_amount'); + remaining = this.safeNumber (order, 'amount'); } else { - remaining = this.safeFloat (order, 'amount'); - } - if (amount !== undefined) { - if (remaining !== undefined) { - filled = amount - remaining; - cost = price * filled; - } + remaining = this.safeNumber (order, 'amount'); } const fee = undefined; - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -584,15 +605,15 @@ module.exports = class tidex extends Exchange { 'side': this.safeString (order, 'type'), 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/timex.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/timex.js index 4c71ac4ff..227f97553 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/timex.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/timex.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, PermissionDenied, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, RateLimitExceeded, NotSupported, BadRequest, AuthenticationError } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class timex extends Exchange { describe () { @@ -450,11 +451,11 @@ module.exports = class timex extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['total'] = this.safeFloat (balance, 'totalBalance'); - account['used'] = this.safeFloat (balance, 'lockedBalance'); + account['total'] = this.safeString (balance, 'totalBalance'); + account['used'] = this.safeString (balance, 'lockedBalance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -815,7 +816,7 @@ module.exports = class timex extends Exchange { const result = this.safeValue (response, 0, {}); return { 'info': response, - 'maker': this.safeFloat (result, 'fee'), + 'maker': this.safeNumber (result, 'fee'), 'taker': undefined, }; } @@ -852,18 +853,18 @@ module.exports = class timex extends Exchange { 'amount': this.precisionFromString (this.safeString (market, 'quantityIncrement')), 'price': this.precisionFromString (this.safeString (market, 'tickSize')), }; - const amountIncrement = this.safeFloat (market, 'quantityIncrement'); - const minBase = this.safeFloat (market, 'baseMinSize'); + const amountIncrement = this.safeNumber (market, 'quantityIncrement'); + const minBase = this.safeNumber (market, 'baseMinSize'); const minAmount = Math.max (amountIncrement, minBase); - const priceIncrement = this.safeFloat (market, 'tickSize'); - const minCost = this.safeFloat (market, 'quoteMinSize'); + const priceIncrement = this.safeNumber (market, 'tickSize'); + const minCost = this.safeNumber (market, 'quoteMinSize'); const limits = { 'amount': { 'min': minAmount, 'max': undefined }, 'price': { 'min': priceIncrement, 'max': undefined }, 'cost': { 'min': Math.max (minCost, minAmount * priceIncrement), 'max': undefined }, }; - const taker = this.safeFloat (market, 'takerFee'); - const maker = this.safeFloat (market, 'makerFee'); + const taker = this.safeNumber (market, 'takerFee'); + const maker = this.safeNumber (market, 'makerFee'); return { 'id': id, 'symbol': symbol, @@ -924,7 +925,7 @@ module.exports = class timex extends Exchange { const name = this.safeString (currency, 'name'); const precision = this.safeInteger (currency, 'decimals'); const active = this.safeValue (currency, 'active'); - // const fee = this.safeFloat (currency, 'withdrawalFee'); + // const fee = this.safeNumber (currency, 'withdrawalFee'); const feeString = this.safeString (currency, 'withdrawalFee'); const tradeDecimals = this.safeInteger (currency, 'tradeDecimals'); let fee = undefined; @@ -961,14 +962,6 @@ module.exports = class timex extends Exchange { }; } - parseTickers (rawTickers, symbols = undefined) { - const tickers = []; - for (let i = 0; i < rawTickers.length; i++) { - tickers.push (this.parseTicker (rawTickers[i])); - } - return this.filterByArray (tickers, 'symbol', symbols); - } - parseTicker (ticker, market = undefined) { // // { @@ -988,8 +981,8 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (ticker, 'market'); const symbol = this.safeSymbol (marketId, market, '/'); const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp')); - const last = this.safeFloat (ticker, 'last'); - const open = this.safeFloat (ticker, 'open'); + const last = this.safeNumber (ticker, 'last'); + const open = this.safeNumber (ticker, 'open'); let change = undefined; let average = undefined; if (last !== undefined && open !== undefined) { @@ -1005,11 +998,11 @@ module.exports = class timex extends Exchange { 'info': ticker, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -1019,8 +1012,8 @@ module.exports = class timex extends Exchange { 'change': change, 'percentage': percentage, 'average': average, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'volumeQuote'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'volumeQuote'), }; } @@ -1039,23 +1032,27 @@ module.exports = class timex extends Exchange { // fetchMyTrades, fetchOrder (private) // // { - // "fee": "0.3", - // "id": 100, - // "makerOrTaker": "MAKER", - // "makerOrderId": "string", - // "price": "0.017", - // "quantity": "0.3", + // "id": "7613414", + // "makerOrderId": "0x8420af060722f560098f786a2894d4358079b6ea5d14b395969ed77bc87a623a", + // "takerOrderId": "0x1235ef158a361815b54c9988b6241c85aedcbc1fe81caf8df8587d5ab0373d1a", + // "symbol": "LTCUSDT", // "side": "BUY", - // "symbol": "TIMEETH", - // "takerOrderId": "string", - // "timestamp": "2019-12-08T04:54:11.171Z" - // } + // "quantity": "0.2", + // "fee": "0.22685", + // "feeToken": "USDT", + // "price": "226.85", + // "makerOrTaker": "TAKER", + // "timestamp": "2021-04-09T15:39:45.608" + // } // const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (trade, 'timestamp')); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'quantity'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const id = this.safeString (trade, 'id'); const side = this.safeStringLower2 (trade, 'direction', 'side'); const takerOrMaker = this.safeStringLower (trade, 'makerOrTaker'); @@ -1064,18 +1061,14 @@ module.exports = class timex extends Exchange { orderId = this.safeString (trade, takerOrMaker + 'OrderId'); } let fee = undefined; - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); + const feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'feeToken')); if (feeCost !== undefined) { - const feeCurrency = (market === undefined) ? undefined : market['quote']; fee = { 'cost': feeCost, 'currency': feeCurrency, }; } - let cost = undefined; - if ((price !== undefined) && (amount !== undefined)) { - cost = this.costToPrecision (symbol, amount * price); - } return { 'info': trade, 'id': id, @@ -1107,11 +1100,11 @@ module.exports = class timex extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'timestamp')), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -1142,14 +1135,12 @@ module.exports = class timex extends Exchange { const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); const timestamp = this.parse8601 (this.safeString (order, 'createdAt')); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'quantity'); - const filled = this.safeFloat (order, 'filledQuantity'); - const canceledQuantity = this.safeFloat (order, 'cancelledQuantity'); - let remaining = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'filledQuantity'); + const canceledQuantity = this.safeNumber (order, 'cancelledQuantity'); let status = undefined; if ((amount !== undefined) && (filled !== undefined)) { - remaining = Math.max (amount - filled, 0.0); if (filled >= amount) { status = 'closed'; } else if ((canceledQuantity !== undefined) && (canceledQuantity > 0)) { @@ -1158,30 +1149,19 @@ module.exports = class timex extends Exchange { status = 'open'; } } - const cost = parseFloat (this.costToPrecision (symbol, price * filled)); - const fee = undefined; - let lastTradeTimestamp = undefined; - let trades = undefined; - const rawTrades = this.safeValue (order, 'trades'); - if (rawTrades !== undefined) { - trades = this.parseTrades (rawTrades, market, undefined, undefined, { - 'order': id, - }); - } - if (trades !== undefined) { - const numTrades = trades.length; - if (numTrades > 0) { - lastTradeTimestamp = trades[numTrades - 1]['timestamp']; - } - } + const rawTrades = this.safeValue (order, 'trades', []); + const trades = this.parseTrades (rawTrades, market, undefined, undefined, { + 'order': id, + 'type': type, + }); const clientOrderId = this.safeString (order, 'clientOrderId'); - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': clientOrderId, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'lastTradeTimestamp': lastTradeTimestamp, + 'lastTradeTimestamp': undefined, 'symbol': symbol, 'type': type, 'timeInForce': undefined, @@ -1190,14 +1170,14 @@ module.exports = class timex extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, - 'fee': fee, + 'fee': undefined, 'trades': trades, - }; + }); } sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/upbit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/upbit.js index 829aa6586..890c30126 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/upbit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/upbit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest, AuthenticationError, InvalidOrder, InsufficientFunds, OrderNotFound, PermissionDenied, AddressPending } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -229,9 +230,9 @@ module.exports = class upbit extends Exchange { } else if ((locked !== undefined) && locked) { active = false; } - const maxOnetimeWithdrawal = this.safeFloat (withdrawLimits, 'onetime'); - const maxDailyWithdrawal = this.safeFloat (withdrawLimits, 'daily', maxOnetimeWithdrawal); - const remainingDailyWithdrawal = this.safeFloat (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); + const maxOnetimeWithdrawal = this.safeNumber (withdrawLimits, 'onetime'); + const maxDailyWithdrawal = this.safeNumber (withdrawLimits, 'daily', maxOnetimeWithdrawal); + const remainingDailyWithdrawal = this.safeNumber (withdrawLimits, 'remaining_daily', maxDailyWithdrawal); let maxWithdrawLimit = undefined; if (remainingDailyWithdrawal > 0) { maxWithdrawLimit = remainingDailyWithdrawal; @@ -247,11 +248,11 @@ module.exports = class upbit extends Exchange { 'code': code, 'name': code, 'active': active, - 'fee': this.safeFloat (currencyInfo, 'withdraw_fee'), + 'fee': this.safeNumber (currencyInfo, 'withdraw_fee'), 'precision': precision, 'limits': { 'withdraw': { - 'min': this.safeFloat (withdrawLimits, 'minimum'), + 'min': this.safeNumber (withdrawLimits, 'minimum'), 'max': maxWithdrawLimit, }, }, @@ -314,8 +315,8 @@ module.exports = class upbit extends Exchange { }; const state = this.safeString (marketInfo, 'state'); const active = (state === 'active'); - const bidFee = this.safeFloat (response, 'bid_fee'); - const askFee = this.safeFloat (response, 'ask_fee'); + const bidFee = this.safeNumber (response, 'bid_fee'); + const askFee = this.safeNumber (response, 'ask_fee'); const fee = Math.max (bidFee, askFee); return { 'info': response, @@ -331,7 +332,7 @@ module.exports = class upbit extends Exchange { 'taker': fee, 'limits': { 'amount': { - 'min': this.safeFloat (ask, 'min_total'), + 'min': this.safeNumber (ask, 'min_total'), 'max': undefined, }, 'price': { @@ -339,8 +340,8 @@ module.exports = class upbit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (bid, 'min_total'), - 'max': this.safeFloat (marketInfo, 'max_total'), + 'min': this.safeNumber (bid, 'min_total'), + 'max': this.safeNumber (marketInfo, 'max_total'), }, }, }; @@ -379,8 +380,8 @@ module.exports = class upbit extends Exchange { 'price': 8, }; const active = true; - const makerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); - const takerFee = this.safeFloat (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); + const makerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['maker']); + const takerFee = this.safeNumber (this.options['tradingFeesByQuoteCurrency'], quote, this.fees['trading']['taker']); result.push ({ 'id': id, 'symbol': symbol, @@ -433,11 +434,11 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'balance'); - account['used'] = this.safeFloat (balance, 'locked'); + account['free'] = this.safeString (balance, 'balance'); + account['used'] = this.safeString (balance, 'locked'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBooks (symbols = undefined, limit = undefined, params = {}) { @@ -540,30 +541,30 @@ module.exports = class upbit extends Exchange { const timestamp = this.safeInteger (ticker, 'trade_timestamp'); const marketId = this.safeString2 (ticker, 'market', 'code'); const symbol = this.safeSymbol (marketId, market, '-'); - const previous = this.safeFloat (ticker, 'prev_closing_price'); - const last = this.safeFloat (ticker, 'trade_price'); - const change = this.safeFloat (ticker, 'signed_change_price'); - const percentage = this.safeFloat (ticker, 'signed_change_rate'); + const previous = this.safeNumber (ticker, 'prev_closing_price'); + const last = this.safeNumber (ticker, 'trade_price'); + const change = this.safeNumber (ticker, 'signed_change_price'); + const percentage = this.safeNumber (ticker, 'signed_change_rate'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high_price'), - 'low': this.safeFloat (ticker, 'low_price'), + 'high': this.safeNumber (ticker, 'high_price'), + 'low': this.safeNumber (ticker, 'low_price'), 'bid': undefined, 'bidVolume': undefined, 'ask': undefined, 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'opening_price'), + 'open': this.safeNumber (ticker, 'opening_price'), 'close': last, 'last': last, 'previousClose': previous, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'acc_trade_volume_24h'), - 'quoteVolume': this.safeFloat (ticker, 'acc_trade_price_24h'), + 'baseVolume': this.safeNumber (ticker, 'acc_trade_volume_24h'), + 'quoteVolume': this.safeNumber (ticker, 'acc_trade_price_24h'), 'info': ticker, }; } @@ -670,15 +671,13 @@ module.exports = class upbit extends Exchange { } else if (askOrBid === 'bid') { side = 'buy'; } - let cost = this.safeFloat (trade, 'funds'); - const price = this.safeFloat2 (trade, 'trade_price', 'price'); - const amount = this.safeFloat2 (trade, 'trade_volume', 'volume'); + let cost = this.safeNumber (trade, 'funds'); + const priceString = this.safeString2 (trade, 'trade_price', 'price'); + const amountString = this.safeString2 (trade, 'trade_volume', 'volume'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); if (cost === undefined) { - if (amount !== undefined) { - if (price !== undefined) { - cost = price * amount; - } - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const marketId = this.safeString2 (trade, 'market', 'code'); market = this.safeMarket (marketId, market); @@ -773,11 +772,11 @@ module.exports = class upbit extends Exchange { // return [ this.parse8601 (this.safeString (ohlcv, 'candle_date_time_utc')), - this.safeFloat (ohlcv, 'opening_price'), - this.safeFloat (ohlcv, 'high_price'), - this.safeFloat (ohlcv, 'low_price'), - this.safeFloat (ohlcv, 'trade_price'), - this.safeFloat (ohlcv, 'candle_acc_trade_volume'), // base volume + this.safeNumber (ohlcv, 'opening_price'), + this.safeNumber (ohlcv, 'high_price'), + this.safeNumber (ohlcv, 'low_price'), + this.safeNumber (ohlcv, 'trade_price'), + this.safeNumber (ohlcv, 'candle_acc_trade_volume'), // base volume ]; } @@ -1046,7 +1045,7 @@ module.exports = class upbit extends Exchange { // } // const id = this.safeString (transaction, 'uuid'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const address = undefined; // not present in the data structure received from the exchange const tag = undefined; // not present in the data structure received from the exchange const txid = this.safeString (transaction, 'txid'); @@ -1059,7 +1058,7 @@ module.exports = class upbit extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId); const status = this.parseTransactionStatus (this.safeString (transaction, 'state')); - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); return { 'info': transaction, 'id': id, @@ -1144,10 +1143,10 @@ module.exports = class upbit extends Exchange { const timestamp = this.parse8601 (this.safeString (order, 'created_at')); const status = this.parseOrderStatus (this.safeString (order, 'state')); let lastTradeTimestamp = undefined; - let price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'volume'); - const remaining = this.safeFloat (order, 'remaining_volume'); - const filled = this.safeFloat (order, 'executed_volume'); + let price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'volume'); + const remaining = this.safeNumber (order, 'remaining_volume'); + const filled = this.safeNumber (order, 'executed_volume'); let cost = undefined; if (type === 'price') { type = 'market'; @@ -1156,7 +1155,7 @@ module.exports = class upbit extends Exchange { } let average = undefined; let fee = undefined; - let feeCost = this.safeFloat (order, 'paid_fee'); + let feeCost = this.safeNumber (order, 'paid_fee'); const marketId = this.safeString (order, 'market'); market = this.safeMarket (marketId, market); let trades = this.safeValue (order, 'trades', []); @@ -1179,7 +1178,7 @@ module.exports = class upbit extends Exchange { cost = this.sum (cost, trade['cost']); if (getFeesFromTrades) { const tradeFee = this.safeValue (trades[i], 'fee', {}); - const tradeFeeCost = this.safeFloat (tradeFee, 'cost'); + const tradeFeeCost = this.safeNumber (tradeFee, 'cost'); if (tradeFeeCost !== undefined) { feeCost = this.sum (feeCost, tradeFeeCost); } @@ -1321,16 +1320,6 @@ module.exports = class upbit extends Exchange { return this.parseOrder (response); } - parseDepositAddresses (addresses) { - const result = {}; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - const code = address['currency']; - result[code] = address; - } - return result; - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetDepositsCoinAddresses (params); diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vaultoro.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vaultoro.js deleted file mode 100644 index abc1ba387..000000000 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vaultoro.js +++ /dev/null @@ -1,203 +0,0 @@ -'use strict'; - -// --------------------------------------------------------------------------- - -const Exchange = require ('./base/Exchange'); - -// --------------------------------------------------------------------------- - -module.exports = class vaultoro extends Exchange { - describe () { - return this.deepExtend (super.describe (), { - 'id': 'vaultoro', - 'name': 'Vaultoro', - 'countries': [ 'CH' ], - 'rateLimit': 1000, - 'version': '1', - 'has': { - 'CORS': true, - 'fetchMarkets': true, - 'fetchOrderBook': true, - 'fetchBalance': true, - 'createOrder': true, - 'cancelOrder': true, - 'fetchTrades': true, - 'fetchTicker': false, - }, - 'urls': { - 'logo': 'https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg', - 'api': 'https://api.vaultoro.com', - 'www': 'https://www.vaultoro.com', - 'doc': 'https://api.vaultoro.com', - }, - 'commonCurrencies': { - 'GLD': 'Gold', - }, - 'api': { - 'public': { - 'get': [ - 'bidandask', - 'buyorders', - 'latest', - 'latesttrades', - 'markets', - 'orderbook', - 'sellorders', - 'transactions/day', - 'transactions/hour', - 'transactions/month', - ], - }, - 'private': { - 'get': [ - 'balance', - 'mytrades', - 'orders', - ], - 'post': [ - 'buy/{symbol}/{type}', - 'cancel/{id}', - 'sell/{symbol}/{type}', - 'withdraw', - ], - }, - }, - }); - } - - async fetchMarkets (params = {}) { - const result = []; - const response = await this.publicGetMarkets (params); - const market = this.safeValue (response, 'data'); - const baseId = this.safeString (market, 'MarketCurrency'); - const quoteId = this.safeString (market, 'BaseCurrency'); - const base = this.safeCurrencyCode (baseId); - const quote = this.safeCurrencyCode (quoteId); - const symbol = base + '/' + quote; - const id = this.safeString (market, 'MarketName'); - result.push ({ - 'id': id, - 'symbol': symbol, - 'base': base, - 'quote': quote, - 'baseId': baseId, - 'quoteId': quoteId, - 'info': market, - 'active': undefined, - 'precision': this.precision, - 'limits': this.limits, - }); - return result; - } - - async fetchBalance (params = {}) { - await this.loadMarkets (); - const response = await this.privateGetBalance (params); - const balances = this.safeValue (response, 'data'); - const result = { 'info': balances }; - for (let i = 0; i < balances.length; i++) { - const balance = balances[i]; - const currencyId = this.safeString (balance, 'currency_code'); - const code = this.safeCurrencyCode (currencyId); - const account = this.account (); - account['free'] = this.safeFloat (balance, 'cash'); - account['used'] = this.safeFloat (balance, 'reserved'); - result[code] = account; - } - return this.parseBalance (result); - } - - async fetchOrderBook (symbol, limit = undefined, params = {}) { - await this.loadMarkets (); - const response = await this.publicGetOrderbook (params); - const orderbook = { - 'bids': response['data'][0]['b'], - 'asks': response['data'][1]['s'], - }; - return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'Gold_Price', 'Gold_Amount'); - } - - parseTrade (trade, market = undefined) { - const timestamp = this.parse8601 (this.safeString (trade, 'Time')); - let symbol = undefined; - if (market !== undefined) { - symbol = market['symbol']; - } - const price = this.safeFloat (trade, 'Gold_Price'); - const amount = this.safeFloat (trade, 'Gold_Amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } - return { - 'id': undefined, - 'info': trade, - 'timestamp': timestamp, - 'datetime': this.iso8601 (timestamp), - 'symbol': symbol, - 'order': undefined, - 'type': undefined, - 'side': undefined, - 'takerOrMaker': undefined, - 'price': price, - 'amount': amount, - 'cost': cost, - 'fee': undefined, - }; - } - - async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const response = await this.publicGetTransactionsDay (params); - return this.parseTrades (response, market, since, limit); - } - - async createOrder (symbol, type, side, amount, price = undefined, params = {}) { - await this.loadMarkets (); - const market = this.market (symbol); - const method = 'privatePost' + this.capitalize (side) + 'SymbolType'; - const request = { - 'symbol': market['quoteId'].toLowerCase (), - 'type': type, - 'gld': amount, - 'price': price || 1, - }; - const response = await this[method] (this.extend (request, params)); - return { - 'info': response, - 'id': response['data']['Order_ID'], - }; - } - - async cancelOrder (id, symbol = undefined, params = {}) { - await this.loadMarkets (); - const request = { - 'id': id, - }; - return await this.privatePostCancelId (this.extend (request, params)); - } - - sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let url = this.urls['api'] + '/'; - if (api === 'public') { - url += path; - } else { - this.checkRequiredCredentials (); - const nonce = this.nonce (); - url += this.version + '/' + this.implodeParams (path, params); - const query = this.extend ({ - 'nonce': nonce, - 'apikey': this.apiKey, - }, this.omit (params, this.extractParams (path))); - url += '?' + this.urlencode (query); - headers = { - 'Content-Type': 'application/json', - 'X-Signature': this.hmac (this.encode (url), this.encode (this.secret)), - }; - } - return { 'url': url, 'method': method, 'body': body, 'headers': headers }; - } -}; diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vcc.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vcc.js index bd3a9602d..5b182adcb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vcc.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/vcc.js @@ -5,6 +5,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, OrderNotFound, InvalidOrder, BadRequest, AuthenticationError, RateLimitExceeded, RequestTimeout, BadSymbol, AddressPending, PermissionDenied, InsufficientFunds } = require ('./base/errors'); const { ROUND } = require ('./base/functions/number'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -196,15 +197,15 @@ module.exports = class vcc extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (amountLimits, 'min'), + 'min': this.safeNumber (amountLimits, 'min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (priceLimits, 'min'), + 'min': this.safeNumber (priceLimits, 'min'), 'max': undefined, }, 'cost': { - 'min': this.safeFloat (costLimits, 'min'), + 'min': this.safeNumber (costLimits, 'min'), 'max': undefined, }, }, @@ -251,12 +252,12 @@ module.exports = class vcc extends Exchange { 'code': code, 'name': this.safeString (currency, 'name'), 'active': active, - 'fee': this.safeFloat (currency, 'withdrawal_fee'), + 'fee': this.safeNumber (currency, 'withdrawal_fee'), 'precision': this.safeInteger (currency, 'decimal'), 'limits': { 'withdraw': { - 'min': this.safeFloat (currency, 'min_withdraw'), - 'max': this.safeFloat (currency, 'max_withdraw'), + 'min': this.safeNumber (currency, 'min_withdraw'), + 'max': this.safeNumber (currency, 'max_withdraw'), }, }, }; @@ -279,8 +280,8 @@ module.exports = class vcc extends Exchange { // return { 'info': response, - 'maker': this.safeFloat (response, 'provideLiquidityRate'), - 'taker': this.safeFloat (response, 'takeLiquidityRate'), + 'maker': this.safeNumber (response, 'provideLiquidityRate'), + 'taker': this.safeNumber (response, 'takeLiquidityRate'), }; } @@ -306,11 +307,11 @@ module.exports = class vcc extends Exchange { const code = this.safeCurrencyCode (currencyId); const balance = this.safeValue (data, currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available_balance'); - account['total'] = this.safeFloat (balance, 'balance'); + account['free'] = this.safeString (balance, 'available_balance'); + account['total'] = this.safeString (balance, 'balance'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseOHLCV (ohlcv, market = undefined) { @@ -328,11 +329,11 @@ module.exports = class vcc extends Exchange { // return [ this.safeInteger (ohlcv, 'time'), - this.safeFloat (ohlcv, 'open'), - this.safeFloat (ohlcv, 'high'), - this.safeFloat (ohlcv, 'low'), - this.safeFloat (ohlcv, 'close'), - this.safeFloat (ohlcv, 'volume'), + this.safeNumber (ohlcv, 'open'), + this.safeNumber (ohlcv, 'high'), + this.safeNumber (ohlcv, 'low'), + this.safeNumber (ohlcv, 'close'), + this.safeNumber (ohlcv, 'volume'), ]; } @@ -421,10 +422,10 @@ module.exports = class vcc extends Exchange { // } // const timestamp = this.milliseconds (); - const baseVolume = this.safeFloat (ticker, 'base_volume'); - const quoteVolume = this.safeFloat (ticker, 'quote_volume'); - const open = this.safeFloat (ticker, 'open_price'); - const last = this.safeFloat (ticker, 'last_price'); + const baseVolume = this.safeNumber (ticker, 'base_volume'); + const quoteVolume = this.safeNumber (ticker, 'quote_volume'); + const open = this.safeNumber (ticker, 'open_price'); + const last = this.safeNumber (ticker, 'last_price'); let change = undefined; let percentage = undefined; let average = undefined; @@ -441,11 +442,11 @@ module.exports = class vcc extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'max_price'), - 'low': this.safeFloat (ticker, 'min_price'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'max_price'), + 'low': this.safeNumber (ticker, 'min_price'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': open, @@ -559,17 +560,17 @@ module.exports = class vcc extends Exchange { } market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'base_volume', 'quantity'); - let cost = this.safeFloat2 (trade, 'quote_volume', 'amount'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'base_volume', 'quantity'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + let cost = this.safeNumber2 (trade, 'quote_volume', 'amount'); if (cost === undefined) { - if ((price !== undefined) && (amount !== undefined)) { - cost = price * amount; - } + cost = this.parseNumber (Precise.stringMul (priceString, amountString)); } const side = this.safeString2 (trade, 'type', 'trade_type'); const id = this.safeString2 (trade, 'trade_id', 'id'); - const feeCost = this.safeFloat (trade, 'fee'); + const feeCost = this.safeNumber (trade, 'fee'); let fee = undefined; if (feeCost !== undefined) { fee = { @@ -754,7 +755,7 @@ module.exports = class vcc extends Exchange { const currencyId = this.safeString (transaction, 'currency'); const code = this.safeCurrencyCode (currencyId, currency); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); - let amount = this.safeFloat (transaction, 'amount'); + let amount = this.safeNumber (transaction, 'amount'); if (amount !== undefined) { amount = Math.abs (amount); } @@ -762,7 +763,7 @@ module.exports = class vcc extends Exchange { const txid = this.safeString (transaction, 'transaction_id'); const tag = this.safeString (transaction, 'destination_tag'); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fee'); + const feeCost = this.safeNumber (transaction, 'fee'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -1007,46 +1008,27 @@ module.exports = class vcc extends Exchange { const marketId = baseId + '_' + quoteId; market = this.safeMarket (marketId, market, '_'); const symbol = market['symbol']; - const amount = this.safeFloat (order, 'quantity'); - let filled = this.safeFloat (order, 'executed_quantity'); + const amount = this.safeNumber (order, 'quantity'); + const filled = this.safeNumber (order, 'executed_quantity'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - let cost = this.safeFloat (order, 'ceiling'); + const cost = this.safeNumber (order, 'ceiling'); const id = this.safeString (order, 'id'); - let average = undefined; - let price = this.safeFloat (order, 'price'); - // in case of market order - if (!price) { - price = this.safeFloat (order, 'executed_price'); - average = price; - } - let remaining = this.safeFloat (order, 'remaining'); - if ((filled === undefined) && (amount !== undefined) && (remaining !== undefined)) { - filled = Math.max (0, amount - remaining); - } - if (filled !== undefined) { - if ((amount !== undefined) && (remaining === undefined)) { - remaining = Math.max (0, amount - filled); - } - if ((price !== undefined) && (cost === undefined)) { - cost = filled * price; - } - if ((average === undefined) && (cost !== undefined) && (filled > 0)) { - average = cost / filled; - } - } + const price = this.safeNumber (order, 'price'); + const average = this.safeNumber (order, 'executed_price'); + const remaining = this.safeNumber (order, 'remaining'); const type = this.safeString (order, 'type'); const side = this.safeString (order, 'trade_type'); const fee = { 'currency': market['quote'], - 'cost': this.safeFloat (order, 'fee'), - 'rate': this.safeFloat (order, 'fee_rate'), + 'cost': this.safeNumber (order, 'fee'), + 'rate': this.safeNumber (order, 'fee_rate'), }; let lastTradeTimestamp = undefined; if (updated !== created) { lastTradeTimestamp = updated; } - const stopPrice = this.safeFloat (order, 'stopPrice'); - return { + const stopPrice = this.safeNumber (order, 'stopPrice'); + return this.safeOrder ({ 'id': id, 'clientOrderId': id, 'timestamp': created, @@ -1068,7 +1050,7 @@ module.exports = class vcc extends Exchange { 'fee': fee, 'trades': undefined, 'info': order, - }; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/wavesexchange.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/wavesexchange.js index 139780062..bd422c073 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/wavesexchange.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/wavesexchange.js @@ -565,13 +565,13 @@ module.exports = class wavesexchange extends Exchange { symbol = market['symbol']; } const data = this.safeValue (ticker, 'data', {}); - const last = this.safeFloat (data, 'lastPrice'); - const low = this.safeFloat (data, 'low'); - const high = this.safeFloat (data, 'high'); - const vwap = this.safeFloat (data, 'weightedAveragePrice'); - const baseVolume = this.safeFloat (data, 'volume'); - const quoteVolume = this.safeFloat (data, 'quoteVolume'); - const open = this.safeValue (data, 'firstPrice'); + const last = this.safeNumber (data, 'lastPrice'); + const low = this.safeNumber (data, 'low'); + const high = this.safeNumber (data, 'high'); + const vwap = this.safeNumber (data, 'weightedAveragePrice'); + const baseVolume = this.safeNumber (data, 'volume'); + const quoteVolume = this.safeNumber (data, 'quoteVolume'); + const open = this.safeNumber (data, 'firstPrice'); let change = undefined; let average = undefined; let percentage = undefined; @@ -725,11 +725,11 @@ module.exports = class wavesexchange extends Exchange { const data = this.safeValue (ohlcv, 'data', {}); return [ this.parse8601 (this.safeString (data, 'time')), - this.safeFloat (data, 'open'), - this.safeFloat (data, 'high'), - this.safeFloat (data, 'low'), - this.safeFloat (data, 'close'), - this.safeFloat (data, 'volume', 0), + this.safeNumber (data, 'open'), + this.safeNumber (data, 'high'), + this.safeNumber (data, 'low'), + this.safeNumber (data, 'close'), + this.safeNumber (data, 'volume', 0), ]; } @@ -944,7 +944,7 @@ module.exports = class wavesexchange extends Exchange { } if (matcherFee === undefined) { const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8); - const rate = this.safeFloat (rates, matcherFeeAssetId); + const rate = this.safeNumber (rates, matcherFeeAssetId); const code = this.safeCurrencyCode (matcherFeeAssetId); const currency = this.currency (code); const newPrecison = Math.pow (10, wavesPrecision - currency['precision']); @@ -1354,7 +1354,7 @@ module.exports = class wavesexchange extends Exchange { const issueTransaction = this.safeValue (entry, 'issueTransaction'); const decimals = this.safeInteger (issueTransaction, 'decimals'); const currencyId = this.safeString (entry, 'assetId'); - const balance = this.safeFloat (entry, 'balance'); + const balance = this.safeNumber (entry, 'balance'); let code = undefined; if (currencyId in this.currencies_by_id) { code = this.safeCurrencyCode (currencyId); @@ -1384,7 +1384,7 @@ module.exports = class wavesexchange extends Exchange { if (!(code in result)) { result[code] = this.account (); } - const amount = this.safeFloat (reservedBalance, currencyId); + const amount = this.safeNumber (reservedBalance, currencyId); result[code]['used'] = this.currencyFromPrecision (code, amount); } const wavesRequest = { @@ -1397,7 +1397,7 @@ module.exports = class wavesexchange extends Exchange { // "balance": 909085978 // } result['WAVES'] = this.safeValue (result, 'WAVES', {}); - result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeFloat (wavesTotal, 'balance')); + result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeNumber (wavesTotal, 'balance')); const codes = Object.keys (result); for (let i = 0; i < codes.length; i++) { const code = codes[i]; @@ -1489,8 +1489,8 @@ module.exports = class wavesexchange extends Exchange { const datetime = this.safeString (data, 'timestamp'); const timestamp = this.parse8601 (datetime); const id = this.safeString (data, 'id'); - const price = this.safeFloat (data, 'price'); - const amount = this.safeFloat (data, 'amount'); + const price = this.safeNumber (data, 'price'); + const amount = this.safeNumber (data, 'amount'); const order1 = this.safeValue (data, 'order1'); const order2 = this.safeValue (data, 'order2'); let order = undefined; @@ -1514,7 +1514,7 @@ module.exports = class wavesexchange extends Exchange { cost = price * amount; } const fee = { - 'cost': this.safeFloat (data, 'fee'), + 'cost': this.safeNumber (data, 'fee'), 'currency': this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES')), }; return { @@ -1596,7 +1596,7 @@ module.exports = class wavesexchange extends Exchange { const withdrawAddress = await this.privateGetWithdrawAddressesCurrencyAddress (withdrawAddressRequest); const currency = this.safeValue (withdrawAddress, 'currency'); const allowedAmount = this.safeValue (currency, 'allowed_amount'); - const minimum = this.safeFloat (allowedAmount, 'min'); + const minimum = this.safeNumber (allowedAmount, 'min'); if (amount <= minimum) { throw new BadRequest (this.id + ' ' + code + ' withdraw failed, amount ' + amount.toString () + ' must be greater than the minimum allowed amount of ' + minimum.toString ()); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/whitebit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/whitebit.js index 9e4418141..769cd5b8b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/whitebit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/whitebit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeNotAvailable, ExchangeError, DDoSProtection, BadSymbol } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -164,7 +165,7 @@ module.exports = class whitebit extends Exchange { }, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'minAmount'), + 'min': this.safeNumber (market, 'minAmount'), 'max': undefined, }, 'price': { @@ -172,7 +173,7 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'cost': { - 'min': this.safeFloat (market, 'minTotal'), + 'min': this.safeNumber (market, 'minTotal'), 'max': undefined, }, }, @@ -237,8 +238,8 @@ module.exports = class whitebit extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (currency, 'minWithdrawal'), - 'max': this.safeFloat (currency, 'maxWithdrawal'), + 'min': this.safeNumber (currency, 'minWithdrawal'), + 'max': this.safeNumber (currency, 'maxWithdrawal'), }, }, }; @@ -250,8 +251,8 @@ module.exports = class whitebit extends Exchange { const response = await this.publicV2GetFee (params); const fees = this.safeValue (response, 'result'); return { - 'maker': this.safeFloat (fees, 'makerFee'), - 'taker': this.safeFloat (fees, 'takerFee'), + 'maker': this.safeNumber (fees, 'makerFee'), + 'taker': this.safeNumber (fees, 'takerFee'), }; } @@ -321,8 +322,8 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); - const percentage = this.safeFloat (ticker, 'change'); + const last = this.safeNumber (ticker, 'last'); + const percentage = this.safeNumber (ticker, 'change'); let change = undefined; if (percentage !== undefined) { change = this.numberToString (percentage * 0.01); @@ -331,22 +332,22 @@ module.exports = class whitebit extends Exchange { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, - 'open': this.safeFloat (ticker, 'open'), + 'open': this.safeNumber (ticker, 'open'), 'close': last, 'last': last, 'previousClose': undefined, 'change': change, 'percentage': percentage, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'volume'), - 'quoteVolume': this.safeFloat (ticker, 'deal'), + 'baseVolume': this.safeNumber (ticker, 'volume'), + 'quoteVolume': this.safeNumber (ticker, 'deal'), 'info': ticker, }; } @@ -514,8 +515,11 @@ module.exports = class whitebit extends Exchange { } else { timestamp = parseInt (timestamp * 1000); } - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat2 (trade, 'amount', 'volume'); + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString2 (trade, 'amount', 'volume'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const id = this.safeString2 (trade, 'id', 'tradeId'); let side = this.safeString (trade, 'type'); if (side === undefined) { @@ -526,10 +530,6 @@ module.exports = class whitebit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - let cost = undefined; - if (amount !== undefined && price !== undefined) { - cost = amount * price; - } return { 'info': trade, 'timestamp': timestamp, @@ -599,11 +599,11 @@ module.exports = class whitebit extends Exchange { // return [ this.safeTimestamp (ohlcv, 0), // timestamp - this.safeFloat (ohlcv, 1), // open - this.safeFloat (ohlcv, 3), // high - this.safeFloat (ohlcv, 4), // low - this.safeFloat (ohlcv, 2), // close - this.safeFloat (ohlcv, 5), // volume + this.safeNumber (ohlcv, 1), // open + this.safeNumber (ohlcv, 3), // high + this.safeNumber (ohlcv, 4), // low + this.safeNumber (ohlcv, 2), // close + this.safeNumber (ohlcv, 5), // volume ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xbtce.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xbtce.js index e0d137f67..c8cabae42 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xbtce.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xbtce.js @@ -152,14 +152,13 @@ module.exports = class xbtce extends Exchange { const balance = balances[i]; const currencyId = this.safeString (balance, 'Currency'); const code = this.safeCurrencyCode (currencyId); - const account = { - 'free': this.safeFloat (balance, 'FreeAmount'), - 'used': this.safeFloat (balance, 'LockedAmount'), - 'total': this.safeFloat (balance, 'Amount'), - }; + const account = this.account (); + account['free'] = this.safeString (balance, 'FreeAmount'); + account['used'] = this.safeString (balance, 'LockedAmount'); + account['total'] = this.safeString (balance, 'Amount'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchOrderBook (symbol, limit = undefined, params = {}) { @@ -271,11 +270,11 @@ module.exports = class xbtce extends Exchange { parseOHLCV (ohlcv, market = undefined) { return [ this.safeInteger (ohlcv, 'Timestamp'), - this.safeFloat (ohlcv, 'Open'), - this.safeFloat (ohlcv, 'High'), - this.safeFloat (ohlcv, 'Low'), - this.safeFloat (ohlcv, 'Close'), - this.safeFloat (ohlcv, 'Volume'), + this.safeNumber (ohlcv, 'Open'), + this.safeNumber (ohlcv, 'High'), + this.safeNumber (ohlcv, 'Low'), + this.safeNumber (ohlcv, 'Close'), + this.safeNumber (ohlcv, 'Volume'), ]; } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xena.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xena.js index 2facd429b..e55a5332b 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xena.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/xena.js @@ -2,6 +2,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, BadRequest, InsufficientFunds, InvalidAddress, BadSymbol, InvalidOrder } = require ('./base/errors'); +const Precise = require ('./base/Precise'); module.exports = class xena extends Exchange { describe () { @@ -277,8 +278,8 @@ module.exports = class xena extends Exchange { 'price': pricePrecision, 'amount': 0, }; - const maxCost = this.safeFloat (market, 'maxOrderQty'); - const minCost = this.safeFloat (market, 'minOrderQuantity'); + const maxCost = this.safeNumber (market, 'maxOrderQty'); + const minCost = this.safeNumber (market, 'minOrderQuantity'); const limits = { 'amount': { 'min': undefined, @@ -363,7 +364,7 @@ module.exports = class xena extends Exchange { 'info': currency, 'name': name, 'active': active, - 'fee': this.safeFloat (withdraw, 'commission'), + 'fee': this.safeNumber (withdraw, 'commission'), 'precision': precision, 'limits': { 'amount': { @@ -379,7 +380,7 @@ module.exports = class xena extends Exchange { 'max': undefined, }, 'withdraw': { - 'min': this.safeFloat (withdraw, 'minAmount'), + 'min': this.safeNumber (withdraw, 'minAmount'), 'max': undefined, }, }, @@ -407,8 +408,8 @@ module.exports = class xena extends Exchange { const timestamp = this.milliseconds (); const marketId = this.safeString (ticker, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const last = this.safeFloat (ticker, 'lastPx'); - const open = this.safeFloat (ticker, 'firstPx'); + const last = this.safeNumber (ticker, 'lastPx'); + const open = this.safeNumber (ticker, 'firstPx'); let percentage = undefined; let change = undefined; let average = undefined; @@ -419,18 +420,18 @@ module.exports = class xena extends Exchange { percentage = change / open * 100; } } - const buyVolume = this.safeFloat (ticker, 'buyVolume'); - const sellVolume = this.safeFloat (ticker, 'sellVolume'); + const buyVolume = this.safeNumber (ticker, 'buyVolume'); + const sellVolume = this.safeNumber (ticker, 'sellVolume'); const baseVolume = this.sum (buyVolume, sellVolume); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'highPx'), - 'low': this.safeFloat (ticker, 'lowPx'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'highPx'), + 'low': this.safeNumber (ticker, 'lowPx'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': undefined, 'open': open, @@ -607,11 +608,11 @@ module.exports = class xena extends Exchange { const currencyId = this.safeString (balance, 'currency'); const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'onHold'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'onHold'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseTrade (trade, market = undefined) { @@ -665,20 +666,17 @@ module.exports = class xena extends Exchange { const orderId = this.safeString (trade, 'orderId'); const marketId = this.safeString (trade, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat2 (trade, 'lastPx', 'mdEntryPx'); - const amount = this.safeFloat2 (trade, 'lastQty', 'mdEntrySize'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString2 (trade, 'lastPx', 'mdEntryPx'); + const amountString = this.safeString2 (trade, 'lastQty', 'mdEntrySize'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); - const feeRate = this.safeFloat (trade, 'commRate'); + const feeRate = this.safeNumber (trade, 'commRate'); fee = { 'cost': feeCost, 'rate': feeRate, @@ -793,15 +791,15 @@ module.exports = class xena extends Exchange { // const transactTime = this.safeInteger (ohlcv, 'transactTime'); const timestamp = parseInt (transactTime / 1000000); - const buyVolume = this.safeFloat (ohlcv, 'buyVolume'); - const sellVolume = this.safeFloat (ohlcv, 'sellVolume'); + const buyVolume = this.safeNumber (ohlcv, 'buyVolume'); + const sellVolume = this.safeNumber (ohlcv, 'sellVolume'); const volume = this.sum (buyVolume, sellVolume); return [ timestamp, - this.safeFloat (ohlcv, 'firstPx'), - this.safeFloat (ohlcv, 'highPx'), - this.safeFloat (ohlcv, 'lowPx'), - this.safeFloat (ohlcv, 'lastPx'), + this.safeNumber (ohlcv, 'firstPx'), + this.safeNumber (ohlcv, 'highPx'), + this.safeNumber (ohlcv, 'lowPx'), + this.safeNumber (ohlcv, 'lastPx'), volume, ]; } @@ -926,11 +924,10 @@ module.exports = class xena extends Exchange { const status = this.parseOrderStatus (this.safeString (order, 'ordStatus')); const marketId = this.safeString (order, 'symbol'); const symbol = this.safeSymbol (marketId, market); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'orderQty'); - const filled = this.safeFloat (order, 'cumQty'); - const remaining = this.safeFloat (order, 'leavesQty'); - let cost = undefined; + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'orderQty'); + const filled = this.safeNumber (order, 'cumQty'); + const remaining = this.safeNumber (order, 'leavesQty'); let side = this.safeStringLower (order, 'side'); if (side === '1') { side = 'buy'; @@ -947,12 +944,7 @@ module.exports = class xena extends Exchange { } else if (type === '4') { type = 'stop-limit'; } - if (cost === undefined) { - if ((price !== undefined) && (filled !== undefined)) { - cost = price * filled; - } - } - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': clientOrderId, 'info': order, @@ -967,14 +959,14 @@ module.exports = class xena extends Exchange { 'price': price, 'stopPrice': undefined, 'amount': amount, - 'cost': cost, + 'cost': undefined, 'average': undefined, 'filled': filled, 'remaining': remaining, 'status': status, 'fee': undefined, 'trades': undefined, - }; + }); } async createOrder (symbol, type, side, amount, price = undefined, params = {}) { @@ -1027,7 +1019,7 @@ module.exports = class xena extends Exchange { request['price'] = this.priceToPrecision (symbol, price); } if ((type === 'stop') || (type === 'stop-limit')) { - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx === undefined) { throw new InvalidOrder (this.id + ' createOrder() requires a stopPx param for order type ' + type); } @@ -1106,12 +1098,12 @@ module.exports = class xena extends Exchange { if (price !== undefined) { request['price'] = this.priceToPrecision (symbol, price); } - const stopPx = this.safeFloat (params, 'stopPx'); + const stopPx = this.safeNumber (params, 'stopPx'); if (stopPx !== undefined) { request['stopPx'] = this.priceToPrecision (symbol, stopPx); params = this.omit (params, 'stopPx'); } - const capPrice = this.safeFloat (params, 'capPrice'); + const capPrice = this.safeNumber (params, 'capPrice'); if (capPrice !== undefined) { request['capPrice'] = this.priceToPrecision (symbol, capPrice); params = this.omit (params, 'capPrice'); @@ -1466,7 +1458,7 @@ module.exports = class xena extends Exchange { const address = this.safeString (transaction, 'address'); const addressFrom = undefined; const addressTo = address; - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); const fee = undefined; return { @@ -1563,7 +1555,7 @@ module.exports = class xena extends Exchange { const referenceAccount = undefined; const type = this.parseLedgerEntryType (this.safeString (item, 'kind')); const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency); - let amount = this.safeFloat (item, 'amount'); + let amount = this.safeNumber (item, 'amount'); if (amount < 0) { direction = 'out'; amount = Math.abs (amount); @@ -1575,11 +1567,11 @@ module.exports = class xena extends Exchange { timestamp = parseInt (timestamp / 1000000); } const fee = { - 'cost': this.safeFloat (item, 'commission'), + 'cost': this.safeNumber (item, 'commission'), 'currency': code, }; const before = undefined; - const after = this.safeFloat (item, 'balance'); + const after = this.safeNumber (item, 'balance'); const status = 'ok'; return { 'info': item, diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/yobit.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/yobit.js index 0ab100f68..82d86ea71 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/yobit.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/yobit.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, ArgumentsRequired, ExchangeNotAvailable, InvalidNonce, InsufficientFunds, OrderNotFound, DDoSProtection, InvalidOrder, AuthenticationError, RateLimitExceeded } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -138,6 +139,7 @@ module.exports = class yobit extends Exchange { 'NAV': 'NavajoCoin', 'NBT': 'NiceBytes', 'OMG': 'OMGame', + 'ONX': 'Onix', 'PAC': '$PAC', 'PLAY': 'PlayCoin', 'PIVX': 'Darknet', @@ -236,15 +238,33 @@ module.exports = class yobit extends Exchange { const currencyId = currencyIds[i]; const code = this.safeCurrencyCode (currencyId); const account = this.account (); - account['free'] = this.safeFloat (free, currencyId); - account['total'] = this.safeFloat (total, currencyId); + account['free'] = this.safeString (free, currencyId); + account['total'] = this.safeString (total, currencyId); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } async fetchMarkets (params = {}) { const response = await this.publicGetInfo (params); + // + // { + // "server_time":1615856752, + // "pairs":{ + // "ltc_btc":{ + // "decimal_places":8, + // "min_price":0.00000001, + // "max_price":10000, + // "min_amount":0.0001, + // "min_total":0.0001, + // "hidden":0, + // "fee":0.2, + // "fee_buyer":0.2, + // "fee_seller":0.2 + // }, + // }, + // } + // const markets = this.safeValue (response, 'pairs'); const keys = Object.keys (markets); const result = []; @@ -262,15 +282,15 @@ module.exports = class yobit extends Exchange { 'price': this.safeInteger (market, 'decimal_places'), }; const amountLimits = { - 'min': this.safeFloat (market, 'min_amount'), - 'max': this.safeFloat (market, 'max_amount'), + 'min': this.safeNumber (market, 'min_amount'), + 'max': this.safeNumber (market, 'max_amount'), }; const priceLimits = { - 'min': this.safeFloat (market, 'min_price'), - 'max': this.safeFloat (market, 'max_price'), + 'min': this.safeNumber (market, 'min_price'), + 'max': this.safeNumber (market, 'max_price'), }; const costLimits = { - 'min': this.safeFloat (market, 'min_total'), + 'min': this.safeNumber (market, 'min_total'), }; const limits = { 'amount': amountLimits, @@ -279,6 +299,7 @@ module.exports = class yobit extends Exchange { }; const hidden = this.safeInteger (market, 'hidden'); const active = (hidden === 0); + const takerFee = this.safeNumber (market, 'fee'); result.push ({ 'id': id, 'symbol': symbol, @@ -287,7 +308,7 @@ module.exports = class yobit extends Exchange { 'baseId': baseId, 'quoteId': quoteId, 'active': active, - 'taker': market['fee'] / 100, + 'taker': takerFee / 100, 'precision': precision, 'limits': limits, 'info': market, @@ -363,16 +384,16 @@ module.exports = class yobit extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -381,9 +402,9 @@ module.exports = class yobit extends Exchange { 'previousClose': undefined, 'change': undefined, 'percentage': undefined, - 'average': this.safeFloat (ticker, 'avg'), - 'baseVolume': this.safeFloat (ticker, 'vol_cur'), - 'quoteVolume': this.safeFloat (ticker, 'vol'), + 'average': this.safeNumber (ticker, 'avg'), + 'baseVolume': this.safeNumber (ticker, 'vol_cur'), + 'quoteVolume': this.safeNumber (ticker, 'vol'), 'info': ticker, }; } @@ -432,15 +453,18 @@ module.exports = class yobit extends Exchange { } else if (side === 'bid') { side = 'buy'; } - const price = this.safeFloat2 (trade, 'rate', 'price'); + const priceString = this.safeString2 (trade, 'rate', 'price'); const id = this.safeString2 (trade, 'trade_id', 'tid'); const order = this.safeString (trade, 'order_id'); const marketId = this.safeString (trade, 'pair'); const symbol = this.safeSymbol (marketId, market); - const amount = this.safeFloat (trade, 'amount'); + const amountString = this.safeString (trade, 'amount'); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); const type = 'limit'; // all trades are still limit trades let fee = undefined; - const feeCost = this.safeFloat (trade, 'commission'); + const feeCost = this.safeNumber (trade, 'commission'); if (feeCost !== undefined) { const feeCurrencyId = this.safeString (trade, 'commissionCurrency'); const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId); @@ -455,12 +479,6 @@ module.exports = class yobit extends Exchange { fee = this.calculateFee (symbol, type, side, amount, price, 'taker'); } } - let cost = undefined; - if (amount !== undefined) { - if (price !== undefined) { - cost = amount * price; - } - } return { 'id': id, 'order': order, @@ -522,8 +540,8 @@ module.exports = class yobit extends Exchange { id = this.safeString (response['return'], 'init_order_id'); status = 'closed'; } - filled = this.safeFloat (response['return'], 'received', 0.0); - remaining = this.safeFloat (response['return'], 'remains', amount); + filled = this.safeNumber (response['return'], 'received', 0.0); + remaining = this.safeNumber (response['return'], 'remains', amount); } const timestamp = this.milliseconds (); return { @@ -573,21 +591,13 @@ module.exports = class yobit extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp_created'); const marketId = this.safeString (order, 'pair'); const symbol = this.safeSymbol (marketId, market); - const remaining = this.safeFloat (order, 'amount'); - const amount = this.safeFloat (order, 'start_amount'); - const price = this.safeFloat (order, 'rate'); - let filled = undefined; - let cost = undefined; - if (amount !== undefined) { - if (remaining !== undefined) { - filled = Math.max (0, amount - remaining); - cost = price * filled; - } - } + const remaining = this.safeNumber (order, 'amount'); + const amount = this.safeNumber (order, 'start_amount'); + const price = this.safeNumber (order, 'rate'); const fee = undefined; const type = 'limit'; const side = this.safeString (order, 'type'); - const result = { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -601,16 +611,15 @@ module.exports = class yobit extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'remaining': remaining, - 'filled': filled, + 'filled': undefined, 'status': status, 'fee': fee, 'average': undefined, 'trades': undefined, - }; - return result; + }); } async fetchOrder (id, symbol = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zaif.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zaif.js index 2c6454a05..a94f9dddb 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zaif.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zaif.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { ExchangeError, BadRequest } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -127,6 +128,27 @@ module.exports = class zaif extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetCurrencyPairsAll (params); + // + // [ + // { + // "aux_unit_point": 0, + // "item_japanese": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3", + // "aux_unit_step": 5.0, + // "description": "\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3\u30fb\u65e5\u672c\u5186\u306e\u53d6\u5f15\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059", + // "item_unit_min": 0.001, + // "event_number": 0, + // "currency_pair": "btc_jpy", + // "is_token": false, + // "aux_unit_min": 5.0, + // "aux_japanese": "\u65e5\u672c\u5186", + // "id": 1, + // "item_unit_step": 0.0001, + // "name": "BTC/JPY", + // "seq": 0, + // "title": "BTC/JPY" + // } + // ] + // const result = []; for (let i = 0; i < markets.length; i++) { const market = markets[i]; @@ -137,8 +159,8 @@ module.exports = class zaif extends Exchange { const quote = this.safeCurrencyCode (quoteId); const symbol = base + '/' + quote; const precision = { - 'amount': -Math.log10 (market['item_unit_step']), - 'price': market['aux_unit_point'], + 'amount': -Math.log10 (this.safeNumber (market, 'item_unit_step')), + 'price': this.safeInteger (market, 'aux_unit_point'), }; const fees = this.safeValue (this.options['fees'], symbol, this.fees['trading']); const taker = fees['taker']; @@ -156,11 +178,11 @@ module.exports = class zaif extends Exchange { 'maker': maker, 'limits': { 'amount': { - 'min': this.safeFloat (market, 'item_unit_min'), + 'min': this.safeNumber (market, 'item_unit_min'), 'max': undefined, }, 'price': { - 'min': this.safeFloat (market, 'aux_unit_min'), + 'min': this.safeNumber (market, 'aux_unit_min'), 'max': undefined, }, 'cost': { @@ -192,7 +214,7 @@ module.exports = class zaif extends Exchange { }; if ('deposit' in balances) { if (currencyId in balances['deposit']) { - account['total'] = this.safeFloat (balances['deposit'], currencyId); + account['total'] = this.safeNumber (balances['deposit'], currencyId); account['used'] = account['total'] - account['free']; } } @@ -217,22 +239,22 @@ module.exports = class zaif extends Exchange { }; const ticker = await this.publicGetTickerPair (this.extend (request, params)); const timestamp = this.milliseconds (); - const vwap = this.safeFloat (ticker, 'vwap'); - const baseVolume = this.safeFloat (ticker, 'volume'); + const vwap = this.safeNumber (ticker, 'vwap'); + const baseVolume = this.safeNumber (ticker, 'volume'); let quoteVolume = undefined; if (baseVolume !== undefined && vwap !== undefined) { quoteVolume = baseVolume * vwap; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'bid'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'bid'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'ask'), + 'ask': this.safeNumber (ticker, 'ask'), 'askVolume': undefined, 'vwap': vwap, 'open': undefined, @@ -253,14 +275,11 @@ module.exports = class zaif extends Exchange { side = (side === 'bid') ? 'buy' : 'sell'; const timestamp = this.safeTimestamp (trade, 'date'); const id = this.safeString2 (trade, 'id', 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = amount * price; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (Precise.stringMul (priceString, amountString)); const marketId = this.safeString (trade, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); return { @@ -338,16 +357,10 @@ module.exports = class zaif extends Exchange { const timestamp = this.safeTimestamp (order, 'timestamp'); const marketId = this.safeString (order, 'currency_pair'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const amount = this.safeFloat (order, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const price = this.safeNumber (order, 'price'); + const amount = this.safeNumber (order, 'amount'); const id = this.safeString (order, 'id'); - return { + return this.safeOrder ({ 'id': id, 'clientOrderId': undefined, 'timestamp': timestamp, @@ -361,7 +374,7 @@ module.exports = class zaif extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'cost': cost, + 'cost': undefined, 'amount': amount, 'filled': undefined, 'remaining': undefined, @@ -369,7 +382,7 @@ module.exports = class zaif extends Exchange { 'fee': undefined, 'info': order, 'average': undefined, - }; + }); } async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zb.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zb.js index 1f8f61cdf..29bea651d 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zb.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/js/zb.js @@ -4,6 +4,7 @@ const Exchange = require ('./base/Exchange'); const { BadRequest, ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, OrderNotFound, ExchangeNotAvailable, DDoSProtection, InvalidOrder, InvalidAddress } = require ('./base/errors'); +const Precise = require ('./base/Precise'); // --------------------------------------------------------------------------- @@ -89,8 +90,8 @@ module.exports = class zb extends Exchange { 'urls': { 'logo': 'https://user-images.githubusercontent.com/1294454/32859187-cd5214f0-ca5e-11e7-967d-96568e2e2bd1.jpg', 'api': { - 'public': 'http://api.zb.cn/data', // no https for public API - 'private': 'https://trade.zb.cn/api', + 'public': 'https://api.zb.today/data', + 'private': 'https://trade.zb.today/api', }, 'www': 'https://www.zb.com', 'doc': 'https://www.zb.com/i/developer', @@ -205,6 +206,16 @@ module.exports = class zb extends Exchange { async fetchMarkets (params = {}) { const markets = await this.publicGetMarkets (params); + // + // { + // "zb_qc":{ + // "amountScale":2, + // "minAmount":0.01, + // "minSize":5, + // "priceScale":4, + // }, + // } + // const keys = Object.keys (markets); const result = []; for (let i = 0; i < keys.length; i++) { @@ -268,11 +279,11 @@ module.exports = class zb extends Exchange { const account = this.account (); const currencyId = this.safeString (balance, 'key'); const code = this.safeCurrencyCode (currencyId); - account['free'] = this.safeFloat (balance, 'available'); - account['used'] = this.safeFloat (balance, 'freez'); + account['free'] = this.safeString (balance, 'available'); + account['used'] = this.safeString (balance, 'freez'); result[code] = account; } - return this.parseBalance (result); + return this.parseBalance (result, false); } parseDepositAddress (depositAddress, currency = undefined) { @@ -321,18 +332,6 @@ module.exports = class zb extends Exchange { }; } - parseDepositAddresses (addresses, codes = undefined) { - let result = []; - for (let i = 0; i < addresses.length; i++) { - const address = this.parseDepositAddress (addresses[i]); - result.push (address); - } - if (codes) { - result = this.filterByArray (result, 'currency', codes); - } - return this.indexBy (result, 'currency'); - } - async fetchDepositAddresses (codes = undefined, params = {}) { await this.loadMarkets (); const response = await this.privateGetGetPayinAddress (params); @@ -439,16 +438,16 @@ module.exports = class zb extends Exchange { if (market !== undefined) { symbol = market['symbol']; } - const last = this.safeFloat (ticker, 'last'); + const last = this.safeNumber (ticker, 'last'); return { 'symbol': symbol, 'timestamp': timestamp, 'datetime': this.iso8601 (timestamp), - 'high': this.safeFloat (ticker, 'high'), - 'low': this.safeFloat (ticker, 'low'), - 'bid': this.safeFloat (ticker, 'buy'), + 'high': this.safeNumber (ticker, 'high'), + 'low': this.safeNumber (ticker, 'low'), + 'bid': this.safeNumber (ticker, 'buy'), 'bidVolume': undefined, - 'ask': this.safeFloat (ticker, 'sell'), + 'ask': this.safeNumber (ticker, 'sell'), 'askVolume': undefined, 'vwap': undefined, 'open': undefined, @@ -458,12 +457,23 @@ module.exports = class zb extends Exchange { 'change': undefined, 'percentage': undefined, 'average': undefined, - 'baseVolume': this.safeFloat (ticker, 'vol'), + 'baseVolume': this.safeNumber (ticker, 'vol'), 'quoteVolume': undefined, 'info': ticker, }; } + parseOHLCV (ohlcv, market = undefined) { + return [ + this.safeInteger (ohlcv, 0), + this.safeNumber (ohlcv, 1), + this.safeNumber (ohlcv, 2), + this.safeNumber (ohlcv, 3), + this.safeNumber (ohlcv, 4), + this.safeNumber (ohlcv, 5), + ]; + } + async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const market = this.market (symbol); @@ -488,14 +498,12 @@ module.exports = class zb extends Exchange { let side = this.safeString (trade, 'trade_type'); side = (side === 'bid') ? 'buy' : 'sell'; const id = this.safeString (trade, 'tid'); - const price = this.safeFloat (trade, 'price'); - const amount = this.safeFloat (trade, 'amount'); - let cost = undefined; - if (price !== undefined) { - if (amount !== undefined) { - cost = price * amount; - } - } + const priceString = this.safeString (trade, 'price'); + const amountString = this.safeString (trade, 'amount'); + const costString = Precise.stringMul (priceString, amountString); + const price = this.parseNumber (priceString); + const amount = this.parseNumber (amountString); + const cost = this.parseNumber (costString); let symbol = undefined; if (market !== undefined) { symbol = market['symbol']; @@ -674,23 +682,13 @@ module.exports = class zb extends Exchange { const timestamp = this.safeInteger (order, 'trade_date'); const marketId = this.safeString (order, 'currency'); const symbol = this.safeSymbol (marketId, market, '_'); - const price = this.safeFloat (order, 'price'); - const filled = this.safeFloat (order, 'trade_amount'); - const amount = this.safeFloat (order, 'total_amount'); - let remaining = undefined; - if (amount !== undefined) { - if (filled !== undefined) { - remaining = amount - filled; - } - } - const cost = this.safeFloat (order, 'trade_money'); - let average = undefined; + const price = this.safeNumber (order, 'price'); + const filled = this.safeNumber (order, 'trade_amount'); + const amount = this.safeNumber (order, 'total_amount'); + const cost = this.safeNumber (order, 'trade_money'); const status = this.parseOrderStatus (this.safeString (order, 'status')); - if ((cost !== undefined) && (filled !== undefined) && (filled > 0)) { - average = cost / filled; - } const id = this.safeString (order, 'id'); - const feeCost = this.safeFloat (order, 'fees'); + const feeCost = this.safeNumber (order, 'fees'); let fee = undefined; if (feeCost !== undefined) { let feeCurrency = undefined; @@ -705,7 +703,7 @@ module.exports = class zb extends Exchange { 'currency': feeCurrency, }; } - return { + return this.safeOrder ({ 'info': order, 'id': id, 'clientOrderId': undefined, @@ -719,15 +717,15 @@ module.exports = class zb extends Exchange { 'side': side, 'price': price, 'stopPrice': undefined, - 'average': average, + 'average': undefined, 'cost': cost, 'amount': amount, 'filled': filled, - 'remaining': remaining, + 'remaining': undefined, 'status': status, 'fee': fee, 'trades': undefined, - }; + }); } parseOrderStatus (status) { @@ -790,7 +788,7 @@ module.exports = class zb extends Exchange { // const id = this.safeString (transaction, 'id'); const txid = this.safeString (transaction, 'hash'); - const amount = this.safeFloat (transaction, 'amount'); + const amount = this.safeNumber (transaction, 'amount'); let timestamp = this.parse8601 (this.safeString (transaction, 'submit_time')); timestamp = this.safeInteger (transaction, 'submitTime', timestamp); let address = this.safeString2 (transaction, 'toAddress', 'address'); @@ -810,7 +808,7 @@ module.exports = class zb extends Exchange { } const status = this.parseTransactionStatus (this.safeString (transaction, 'status')); let fee = undefined; - const feeCost = this.safeFloat (transaction, 'fees'); + const feeCost = this.safeNumber (transaction, 'fees'); if (feeCost !== undefined) { fee = { 'cost': feeCost, @@ -843,7 +841,7 @@ module.exports = class zb extends Exchange { if (password === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires exchange.password or a safePwd parameter'); } - const fees = this.safeFloat (params, 'fees'); + const fees = this.safeNumber (params, 'fees'); if (fees === undefined) { throw new ArgumentsRequired (this.id + ' withdraw() requires a fees parameter'); } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/package.json b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/package.json index 1521ec10e..fa1f929a7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/package.json +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/node_modules/ccxt/package.json @@ -1,27 +1,27 @@ { - "_from": "ccxt@1.42.77", - "_id": "ccxt@1.42.77", + "_from": "ccxt@1.47.49", + "_id": "ccxt@1.47.49", "_inBundle": false, - "_integrity": "sha512-vPaw8G3hr9iq1iJ59EHuA6iqjufgK6dNC7MjT3qV8YQbpEJoD2ynoFwfl1hbuvlyKlFjiOa3gHwhRV64UacBDQ==", + "_integrity": "sha512-aGjOGKX/wfStwD24dH7FweP2ktdbZBjhgLxkipFVaewnjsftyiuzCCikMS7IvSRON/aAMG0oqKUdVHL382BFMA==", "_location": "/ccxt", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "ccxt@1.42.77", + "raw": "ccxt@1.47.49", "name": "ccxt", "escapedName": "ccxt", - "rawSpec": "1.42.77", + "rawSpec": "1.47.49", "saveSpec": null, - "fetchSpec": "1.42.77" + "fetchSpec": "1.47.49" }, "_requiredBy": [ "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.42.77.tgz", - "_shasum": "8ab5f8e7190854e163da6d4fcf44530794d0a21c", - "_spec": "ccxt@1.42.77", + "_resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.47.49.tgz", + "_shasum": "ef9c41b5573b85d3b83cf1292d0aa891c4d5b6bc", + "_spec": "ccxt@1.47.49", "_where": "C:\\Superalgos\\Projects\\Superalgos\\TS\\Bot-Modules\\Trading-Bot\\Low-Frequency-Trading\\APIs", "author": { "name": "Igor Kroitor", @@ -543,7 +543,9 @@ "equos.io", "EQUOS", "ndax.io", - "NDAX" + "NDAX", + "ascendex.com", + "AscendEX" ], "license": "MIT", "main": "./ccxt.js", @@ -587,5 +589,5 @@ }, "types": "./ccxt.d.ts", "unpkg": "dist/ccxt.browser.js", - "version": "1.42.77" + "version": "1.47.49" } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/package-lock.json b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/package-lock.json index 976144cc2..cd3bb8d9e 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/package-lock.json +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/APIs/package-lock.json @@ -3,9 +3,9 @@ "lockfileVersion": 1, "dependencies": { "ccxt": { - "version": "1.42.77", - "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.42.77.tgz", - "integrity": "sha512-vPaw8G3hr9iq1iJ59EHuA6iqjufgK6dNC7MjT3qV8YQbpEJoD2ynoFwfl1hbuvlyKlFjiOa3gHwhRV64UacBDQ==" + "version": "1.47.49", + "resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.47.49.tgz", + "integrity": "sha512-aGjOGKX/wfStwD24dH7FweP2ktdbZBjhgLxkipFVaewnjsftyiuzCCikMS7IvSRON/aAMG0oqKUdVHL382BFMA==" } } }