{"id":22903981,"url":"https://github.com/json2d/exchange-ledger","last_synced_at":"2025-08-09T14:06:41.152Z","repository":{"id":95070179,"uuid":"85143696","full_name":"json2d/exchange-ledger","owner":"json2d","description":"a class for creating ledgers to manage exchange trading of currencies and other arbitrary exchangeable entities","archived":false,"fork":false,"pushed_at":"2017-03-16T02:32:54.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T05:51:23.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/json2d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-16T02:32:45.000Z","updated_at":"2017-03-25T03:47:00.000Z","dependencies_parsed_at":"2023-03-13T16:54:09.730Z","dependency_job_id":null,"html_url":"https://github.com/json2d/exchange-ledger","commit_stats":null,"previous_names":["bitstrider/exchange-ledger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/json2d/exchange-ledger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/json2d%2Fexchange-ledger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/json2d%2Fexchange-ledger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/json2d%2Fexchange-ledger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/json2d%2Fexchange-ledger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/json2d","download_url":"https://codeload.github.com/json2d/exchange-ledger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/json2d%2Fexchange-ledger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269586128,"owners_count":24442505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T02:39:40.150Z","updated_at":"2025-08-09T14:06:41.101Z","avatar_url":"https://github.com/json2d.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExchangeLedger\na class for creating ledgers to manage exchange trading of currencies and other arbitrary exchangeable entities\n\n## :star: Getting Started\nInstall as a dependency:\n```\n$ npm install exchange-ledger\n```\n\nInitialize a ledger with a starting balance:\n```javascript\nvar ExchangeLedger = require('exchange-ledger')\n\nvar ledger = new ExchangeLedger({\n    balance: {\n      'usd': 100,\n      'cny': 100\n    }\n})\n\n```\n---\n### :money_with_wings: Trading\nCommit a trade from one currency to another, specifying the conversion rate and the amount to be converted:\n```javascript\nledger.trade({\n  from: 'usd',\n  to: 'cny',\n  rate: 7,\n  amount: 50 // trading 50 USD for 350 CNY\n})\n```\n\n_(Optional)_ Apply a percent-based transaction fee to the trade, taken out of the currency being traded to:\n```javascript\nledger.trade({\n  from: 'usd',\n  to: 'cny',\n  fee: .25, // woah, 25% is alot!\n  rate: 7,\n  amount: 50\n})\n```\n\nTrades can safely be made to currencies not yet specified on the balance:\n```javascript\nledger.trade({\n  from: 'cny',\n  to: 'jpy', // an entry be auto generated on the balance\n  rate: 16.4,\n  amount: 100\n})\n```\n\nThe trade history will be stored on the ledger as an array:\n```javascript\nledger.trades\n// [ { from: 'usd', to: 'cny', rate: 7, amount: 50},\n// { from: 'cny', to: 'jpy', rate: 16.4, amount: 100 } ]\n\n```\n\nThere's also easy access to the last trade committed:\n```javascript\nledger.lastTrade()\n// { from: 'cny', to: 'jpy', rate: 16.4, amount: 100 }\n\n```\n---\n### :book: Balance and Liquidation\nCheck what the current balance for all specified currencies:\n```javascript\nledger.balance\n// { 'usd': 0, 'cny': 512.5, 'jpy': 1640 }\n\nledger.balance.usd\n// 0\n```\n\nUse `getLiquidatedTo` to check the liquidated value of the balance for a specific currency, by specifying the associated conversion rate(s) _(and optionally the transaction fee(s))_:  \n```javascript\nvar currentUSD = ledger.getLiquidatedTo('usd', {\n    'cny': {rate: 1},\n    'jpy': {rate: 1, fee: .5}\n})\n// currentUSD == 1332.5\n// NOTE: This command will not affect the ledger.\n```\n\nSimilarly, use `liquidateTo` to actually convert the balance on the ledger to a specific currency:\n```javascript\nledger.liquidateTo('usd', {\n    'cny': {rate: 1},\n    'jpy': {rate: 1, fee: .5}\n})\n\nvar currentUSD = ledger.balance.usd\n// currentUSD == 1332.5\n```\n\n### Testing\n`mocha` is used for unit-testing in `test.js`.  To run these test, simply:\n```\n$ npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjson2d%2Fexchange-ledger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjson2d%2Fexchange-ledger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjson2d%2Fexchange-ledger/lists"}