Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

minor market rounding errors still present #923

Closed
vikramrajkumar opened this issue Nov 5, 2014 · 9 comments
Closed

minor market rounding errors still present #923

vikramrajkumar opened this issue Nov 5, 2014 · 9 comments

Comments

@vikramrajkumar
Copy link
Contributor

(wallet closed) >>> info
{
  "blockchain_head_block_num": 933230,
  "blockchain_head_block_age": "7 seconds old",
  "blockchain_head_block_timestamp": "2014-11-05T22:24:10",
  "blockchain_average_delegate_participation": "100.00 %",
  "blockchain_confirmation_requirement": 1,
  "blockchain_share_supply": "1,999,898,982.95555 BTS",
  "blockchain_blocks_left_in_round": 10,
  "blockchain_next_round_time": "at least 2 minutes in the future",
  "blockchain_next_round_timestamp": "2014-11-05T22:25:50",
  "blockchain_random_seed": "47106985daa718994aa0e7a43dabf208c618101e",
  "client_data_dir": "/Users/vikram/Library/Application Support/BitShares",
  "client_version": "v0.4.23.1-217-g911a507",
  "network_num_connections": 22,
  "network_num_connections_max": 200,
  "network_chain_downloader_running": false,
  "network_chain_downloader_blocks_remaining": null,
  "ntp_time": "2014-11-05T22:24:17",
  "ntp_time_error": -0.013939999999999999,
  "wallet_open": false,
  "wallet_unlocked": null,
  "wallet_unlocked_until": null,
  "wallet_unlocked_until_timestamp": null,
  "wallet_last_scanned_block_timestamp": null,
  "wallet_scan_progress": null,
  "wallet_block_production_enabled": null,
  "wallet_next_block_production_time": null,
  "wallet_next_block_production_timestamp": null
}
(wallet closed) >>> blockchain_calculate_supply BTS
1,999,898,982.75237 BTS
(wallet closed) >>>
@vikramrajkumar vikramrajkumar added this to the v0.4.26 milestone Nov 5, 2014
@drltc drltc added the bug label Nov 10, 2014
@vikramrajkumar vikramrajkumar modified the milestones: v0.4.26, v0.4.27 Dec 3, 2014
@vikramrajkumar vikramrajkumar modified the milestones: v0.4.30, 0.9.0, 0.7.0 Jan 7, 2015
@bytemaster bytemaster modified the milestones: 0.9.0, 0.7.0 Jan 27, 2015
@vikramrajkumar vikramrajkumar modified the milestones: dvs/0.7.0, dvs/0.9.0 Feb 8, 2015
@pmconrad
Copy link
Contributor

pmconrad commented Feb 9, 2015

There's currently a short on the GOLD/BTS market with a limit above the feed. At the current feed price, the remaining collateral is insufficient to cover one GOLDtoshi:

0.000000 GOLD             0.12300 BTS                             0.000000 %
Maximum Short Price: 0.000007555747799828 GOLD / BTS     

{"type":"short_order","market_index":{"order_price":{"ratio":"0.","quote_asset_id":7,"base_asset_id":0},"owner":"BTSJhbGtQ2aqHWHx1h841dTs6gBUshRVNncv"},"state":{"balance":24601,"limit_price":{"ratio":"0.00007886435","quote_asset_id":7,"base_asset_id":0},"last_update":"2015-02-06T15:17:10"},"collateral":24601,"interest_rate":{"ratio":"0.","quote_asset_id":7,"base_asset_id":0},"expiration":null},

(Note that at the slightly higher feed price of .00000813 the collateral would cover 1 GOLDtoshi, but the short limit is below that price.)

I have an ask on the market with a limit below the feed. My ask and the short are matched in every block with a volume of 0:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|2015-02-09T11:38:30 1744173   ASK-a77c8c44        MARKET              0.00000 BTS             fill ask @ 0.0000074801903218 GOLD / BTS    9,072.99635 BTS         0.00000 BTS         VIRTUAL |
|                              ASK-a77c8c44        trader1.pmc         0.000000 GOLD           ask proceeds @ 0.0000074801903218 GOLD /... 0.000000 GOLD                                       |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|2015-02-09T11:38:40 1744174   ASK-a77c8c44        MARKET              0.00000 BTS             fill ask @ 0.0000074801903218 GOLD / BTS    9,072.99635 BTS         0.00000 BTS         VIRTUAL |
|                              ASK-a77c8c44        trader1.pmc         0.000000 GOLD           ask proceeds @ 0.0000074801903218 GOLD /... 0.000000 GOLD                                       |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|2015-02-09T11:38:50 1744175   ASK-a77c8c44        MARKET              0.00000 BTS             fill ask @ 0.0000074801903218 GOLD / BTS    9,072.99635 BTS         0.00000 BTS         VIRTUAL |
|                              ASK-a77c8c44        trader1.pmc         0.000000 GOLD           ask proceeds @ 0.0000074801903218 GOLD /... 0.000000 GOLD                                       |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@vikramrajkumar
Copy link
Contributor Author

Unexpected supply deviations since the last supply repair hardfork:

[998744]: 0.00000014 BTC
[998744]: -0.00014 BTS
[1030884]: 0.00000012 BTC
[1030884]: -0.00012 BTS
[1034473]: 0.00000002 BTC
[1034473]: -0.00002 BTS
[1034487]: 0.00000002 BTC
[1034487]: -0.00002 BTS
[1034585]: 0.00000009 BTC
[1034585]: -0.00009 BTS
[1037558]: 0.000003 GOLD
[1037558]: -0.00003 BTS
[1044544]: 0.0001 USD
[1044544]: -0.00001 BTS
[1105661]: 0.00000001 BTC
[1105661]: -0.00001 BTS
[1109440]: 0.006737 GOLD
[1109440]: -0.06737 BTS
[1109471]: 0.006737 GOLD
[1109471]: -0.06737 BTS
[1135392]: 0.0079 CNY
[1135392]: -0.00079 BTS
[1135513]: 0.00000002 BTC
[1135513]: -0.00002 BTS
[1137509]: 0.0003 USD
[1137509]: -0.00003 BTS
[1137995]: 0.0485 USD
[1137995]: -0.00485 BTS
[1139659]: 0.0001 USD
[1139659]: -0.00001 BTS
[1140861]: 0.00000012 BTC
[1140861]: -0.00012 BTS
[1140874]: 0.000335 GOLD
[1140874]: -0.00335 BTS
[1148424]: 0.00000005 BTC
[1148424]: -0.00005 BTS
[1162138]: 0.0001 USD
[1162138]: -0.00001 BTS
[1162252]: 0.0001 USD
[1162252]: -0.00001 BTS
[1162333]: 0.0004 USD
[1162333]: -0.00004 BTS
[1162343]: 0.0004 USD
[1162343]: -0.00004 BTS
[1162356]: 0.0004 USD
[1162356]: -0.00004 BTS
[1162369]: 0.0004 USD
[1162369]: -0.00004 BTS
[1256355]: 0.0039 MXN
[1256355]: -0.00039 BTS
[1256363]: 0.0453 NZD
[1256363]: -0.00453 BTS
[1256401]: 0.9927 SILVER
[1256401]: -0.09927 BTS
[1273566]: 0.00000004 BTC
[1273566]: -0.00004 BTS
[1286112]: 0.00000018 BTC
[1286112]: -0.00018 BTS
[1286252]: 0.00000001 BTC
[1286252]: -0.00001 BTS
[1290343]: 0.00000018 BTC
[1290343]: -0.00018 BTS
[1306577]: 0.00000016 BTC
[1306577]: -0.00016 BTS
[1319648]: 0.9848 SILVER
[1319648]: -0.09848 BTS
[1340778]: 0.006792 GOLD
[1340778]: -0.06792 BTS
[1345297]: 0.0003 SILVER
[1345297]: -0.00003 BTS
[1349950]: 0.00000003 BTC
[1349950]: -0.00003 BTS
[1364600]: 0.00000017 BTC
[1364600]: -0.00017 BTS
[1364612]: 0.00000019 BTC
[1364612]: -0.00019 BTS
[1364628]: 0.00000018 BTC
[1364628]: -0.00018 BTS
[1366147]: 0.0093 CNY
[1366147]: -0.00093 BTS
[1366161]: 0.0093 CNY
[1366161]: -0.00093 BTS
[1367077]: 0.0005 CNY
[1367077]: -0.00005 BTS
[1369609]: 0.00000001 BTC
[1369609]: -0.00001 BTS
[1375012]: 0.0001 SILVER
[1375012]: -0.00001 BTS
[1406272]: 0.0001 SILVER
[1406272]: -0.00001 BTS
[1440362]: 0.00000005 BTC
[1440362]: -0.00005 BTS
[1460182]: 0.0817 EUR
[1460182]: -0.00817 BTS
[1463907]: 0.00000001 BTC
[1463907]: -0.00001 BTS
[1511667]: 0.0004 EUR
[1511667]: -0.00004 BTS
[1515649]: 0.000027 GOLD
[1515649]: -0.00027 BTS
[1525698]: 0.012980 GOLD
[1525698]: -0.12980 BTS
[1531978]: 0.0004 EUR
[1531978]: -0.00004 BTS
[1533879]: 0.0001 USD
[1533879]: -0.00001 BTS
[1534118]: 0.0144 CNY
[1534118]: -0.00144 BTS
[1536906]: 0.010799 GOLD
[1536906]: -0.10799 BTS
[1537161]: 0.011133 GOLD
[1537161]: -0.11133 BTS
[1544569]: 1.6598 SILVER
[1544569]: -0.16598 BTS
[1544673]: 0.0002 CNY
[1544673]: -0.00002 BTS
[1547771]: 0.0999 USD
[1547771]: -0.00999 BTS
[1550604]: 0.0159 CNY
[1550604]: -0.00159 BTS
[1556275]: 0.0147 CNY
[1556275]: -0.00147 BTS
[1562748]: 0.0944 USD
[1562748]: -0.00944 BTS
[1564660]: 0.0004 CNY
[1564660]: -0.00004 BTS
[1568735]: 0.0151 CNY
[1568735]: -0.00151 BTS
[1571050]: 0.0939 USD
[1571050]: -0.00939 BTS
[1578776]: 0.00000015 BTC
[1578776]: -0.00015 BTS
[1580014]: -0.00001 BTS
[1580014]: 0.0001 USD
[1580036]: 0.0865 USD
[1580036]: -0.00865 BTS
[1584332]: 1.6497 SILVER
[1584332]: -0.16497 BTS
[1586538]: 0.0281 USD
[1586538]: -0.00281 BTS
[1586998]: 0.0137 CNY
[1586998]: -0.00137 BTS
[1587111]: 0.0137 CNY
[1587111]: -0.00137 BTS
[1588508]: 0.0001 CNY
[1588508]: -0.00001 BTS
[1589431]: 0.0133 CNY
[1589431]: -0.00133 BTS
[1589442]: 0.0133 CNY
[1589442]: -0.00133 BTS
[1589460]: 0.0133 CNY
[1589460]: -0.00133 BTS
[1589794]: 0.0122 CNY
[1589794]: -0.00122 BTS
[1590915]: 0.0002 CNY
[1590915]: -0.00002 BTS
[1591471]: 0.010881 GOLD
[1591471]: -0.10881 BTS
[1591575]: 0.00000009 BTC
[1591575]: -0.00009 BTS
[1591860]: 0.0133 CNY
[1591860]: -0.00133 BTS
[1593223]: 0.0001 SILVER
[1593223]: -0.00001 BTS
[1593723]: 0.0821 USD
[1593723]: -0.00821 BTS
[1595015]: 0.0817 USD
[1595015]: -0.00817 BTS
[1595944]: 0.0860 USD
[1595944]: -0.00860 BTS
[1599974]: 0.0004 CNY
[1599974]: -0.00004 BTS
[1600017]: 0.0135 CNY
[1600017]: -0.00135 BTS
[1600032]: 0.0135 CNY
[1600032]: -0.00135 BTS
[1600052]: 0.0135 CNY
[1600052]: -0.00135 BTS
[1600058]: 0.0135 CNY
[1600058]: -0.00135 BTS
[1600072]: 0.0135 CNY
[1600072]: -0.00135 BTS
[1607529]: 0.0001 RUB
[1607529]: -0.00001 BTS
[1609429]: -0.00004 BTS
[1609429]: 0.0004 USD
[1621298]: 0.0129 CNY
[1621298]: -0.00129 BTS
[1621517]: 0.0001 CNY
[1621517]: -0.00001 BTS
[1622916]: 0.00000020 BTC
[1622916]: -0.00020 BTS
[1623497]: 0.0127 CNY
[1623497]: -0.00127 BTS
[1625433]: 0.000001 GOLD
[1625433]: -0.00001 BTS
[1626724]: 1.5499 SILVER
[1626724]: -0.15499 BTS
[1642106]: 1.5852 SILVER
[1642106]: -0.15852 BTS
[1644064]: 0.00000016 BTC
[1644064]: -0.00016 BTS
[1647557]: 0.0949 USD
[1647557]: -0.00949 BTS
[1652265]: 0.000021 GOLD
[1652265]: -0.00021 BTS
[1655004]: 0.00000022 BTC
[1655004]: -0.00022 BTS
[1655809]: 0.00000022 BTC
[1655809]: -0.00022 BTS
[1671971]: 0.000070 GOLD
[1671971]: -0.00070 BTS
[1672928]: 0.000008 GOLD
[1672928]: -0.00008 BTS
[1673004]: 0.000008 GOLD
[1673004]: -0.00008 BTS
[1677394]: 0.012498 GOLD
[1677394]: -0.12498 BTS
[1677535]: 0.000004 GOLD
[1677535]: -0.00004 BTS
[1678174]: 0.012509 GOLD
[1678174]: -0.12509 BTS
[1678379]: 0.012463 GOLD
[1678379]: -0.12463 BTS
[1681327]: 0.0002 CNY
[1681327]: -0.00002 BTS
[1681333]: 0.0002 CNY
[1681333]: -0.00002 BTS
[1682401]: 0.000361 GOLD
[1682401]: -0.00361 BTS
[1693761]: 0.012146 GOLD
[1693761]: -0.12146 BTS
[1695573]: 0.012185 GOLD
[1695573]: -0.12185 BTS
[1697277]: 0.0155 CNY
[1697277]: -0.00155 BTS
[1697471]: 0.012257 GOLD
[1697471]: -0.12257 BTS
[1698499]: 0.0154 CNY
[1698499]: -0.00154 BTS
[1701007]: 0.001402 GOLD
[1701007]: -0.01402 BTS
[1704322]: 0.012467 GOLD
[1704322]: -0.12467 BTS
[1704383]: 0.0003 EUR
[1704383]: -0.00003 BTS
[1704391]: 1.7169 SILVER
[1704391]: -0.17169 BTS
[1704412]: 0.0001 SILVER
[1704412]: -0.00001 BTS
[1706292]: 0.012395 GOLD
[1706292]: -0.12395 BTS
[1713779]: 0.0005 CHF
[1713779]: -0.00005 BTS
[1715538]: 0.0003 CNY
[1715538]: -0.00003 BTS
[1715613]: 0.0002 CNY
[1715613]: -0.00002 BTS
[1720329]: 0.012530 GOLD
[1720329]: -0.12530 BTS
[1720338]: 0.012361 GOLD
[1720338]: -0.12361 BTS
[1730240]: 0.1000 USD
[1730240]: -0.01000 BTS
[1730419]: 0.0001 USD
[1730419]: -0.00001 BTS
[1731472]: 0.012430 GOLD
[1731472]: -0.12430 BTS
[1731700]: 0.0001 CHF
[1731700]: -0.00001 BTS
[1749097]: 0.000023 GOLD
[1749097]: -0.00023 BTS
[1756949]: 0.0001 EUR
[1756949]: -0.00001 BTS
[1756964]: 0.1256 EUR
[1756964]: -0.01256 BTS
[1757054]: 0.013702 GOLD
[1757054]: -0.13702 BTS
[1760285]: 0.0001 SILVER
[1760285]: -0.00001 BTS
[1764846]: 0.003811 GOLD
[1764846]: -0.03811 BTS
[1770168]: 0.0001 USD
[1770168]: -0.00001 BTS
[1774568]: 0.1127 USD
[1774568]: -0.01127 BTS
[1775331]: 0.0002 USD
[1775331]: -0.00002 BTS
[1776521]: 0.1107 USD
[1776521]: -0.01107 BTS
[1781377]: 0.0001 SILVER
[1781377]: -0.00001 BTS
[1784076]: -0.00003 BTS
[1784076]: 0.0003 USD
[1798774]: 0.00000011 BTC
[1798774]: -0.00011 BTS
[1798874]: 0.0002 USD
[1798874]: -0.00002 BTS
[1805928]: 0.1241 USD
[1805928]: -0.01241 BTS
[1805950]: 0.1241 USD
[1805950]: -0.01241 BTS
[1805955]: 0.1241 USD
[1805955]: -0.01241 BTS
[1814560]: 0.0001 USD
[1814560]: -0.00001 BTS
[1817178]: 0.00000002 BTC
[1817178]: -0.00002 BTS
[1819635]: 0.0188 CNY
[1819635]: -0.00188 BTS
[1819770]: 0.0188 CNY
[1819770]: -0.00188 BTS
[1830756]: 0.00000011 BTC
[1830756]: -0.00011 BTS
[1838469]: 0.0189 CNY
[1838469]: -0.00189 BTS
[1839780]: 0.014449 GOLD
[1839780]: -0.14449 BTS
[1839862]: 0.014707 GOLD
[1839862]: -0.14707 BTS
[1845215]: 0.0191 CNY
[1845215]: -0.00191 BTS
[1852209]: 1.9485 SILVER
[1852209]: -0.19485 BTS
[1864767]: 0.00000018 BTC
[1864767]: -0.00018 BTS
[1864986]: 0.00000015 BTC
[1864986]: -0.00015 BTS
[1865340]: 0.00000018 BTC
[1865340]: -0.00018 BTS
[1871022]: 0.00000023 BTC
[1871022]: -0.00023 BTS
[1872964]: 0.000003 GOLD
[1872964]: -0.00003 BTS
[1875264]: 1.6331 SILVER
[1875264]: -0.16331 BTS
[1879389]: 0.0167 CNY
[1879389]: -0.00167 BTS
[1880502]: 0.0003 SILVER
[1880502]: -0.00003 BTS
[1881707]: 0.0168 CNY
[1881707]: -0.00168 BTS
[1881713]: 0.0168 CNY
[1881713]: -0.00168 BTS
[1881718]: 0.0168 CNY
[1881718]: -0.00168 BTS
[1881750]: 0.0004 CNY
[1881750]: -0.00004 BTS
[1881909]: 0.0002 CNY
[1881909]: -0.00002 BTS
[1883217]: 0.00000002 BTC
[1883217]: -0.00002 BTS
[1885503]: 0.0992 USD
[1885503]: -0.00992 BTS
[1889719]: 0.0148 CNY
[1889719]: -0.00148 BTS
[1889728]: 0.0148 CNY
[1889728]: -0.00148 BTS
[1889739]: 0.0151 CNY
[1889739]: -0.00151 BTS
[1889912]: 0.0001 CNY
[1889912]: -0.00001 BTS
[1890704]: 0.00000020 BTC
[1890704]: -0.00020 BTS
[1891937]: 0.00000010 BTC
[1891937]: -0.00010 BTS
[1892074]: 0.011498 GOLD
[1892074]: -0.11498 BTS
[1892391]: 0.000031 GOLD
[1892391]: -0.00031 BTS
[1901627]: -0.00100 BTS
[1904963]: 0.0001 USD
[1904963]: -0.00001 BTS
[1906471]: 0.00000005 BTC
[1906471]: -0.00005 BTS
[1908500]: 0.00000016 BTC
[1908500]: -0.00016 BTS
[1917855]: 0.00000014 BTC
[1917855]: -0.00014 BTS
[1918916]: 1.5865 SILVER
[1918916]: -0.15865 BTS
[1922160]: 0.0954 USD
[1922160]: -0.00954 BTS
[1930138]: -0.00947 BTS
[1930138]: 0.0947 USD
[1938396]: 0.0001 USD
[1938396]: -0.00001 BTS

@pmconrad
Copy link
Contributor

Apparently there's still something wrong: https://bitsharestalk.org/index.php/topic,16035.0.html

@vikramrajkumar
Copy link
Contributor Author

This fix is for shorts matching with asks and does not take effect until the hardfork.

I'm not sure if it will fix the linked issue.

@abitmore
Copy link
Member

abitmore commented May 1, 2015

Test case:

  • Alice places an order: ask alice 100.036 BTS 0.003 USD
    • alice paid 100.036 BTS and has an open order with 100.04 BTS
  • Bob places an order: bid bob 100.036 BTS 0.003 USD
    • Because the precision of USD is 10^4, actually Bob paid this order with round(0.003*100.036,4)=round(0.300108,4)=0.3001 USD,
    • Because the precision of BTS is 10^5, actually the quantity of the order Bob placed was changed to round(0.3001/0.003,5)=round(100.0333333,5)=100.03333 BTS
  • wait for 2 blocks
    • the orders get matched
    • Bob's order is full-filled, all 0.3001 USD is paid to Alice and 100.03333 BTS is sent to Bob
    • Alice's order is partially filled, 100.03333 BTS is paid to Bob and 0.3001 USD is sent to Alice
    • there is still an open order (of Alice) left in the market, quantity = 100.036-100.03333=0.00267 BTS
  • Bob places another order: bid bob 100 BTS 0.003 USD
    • Bob paid 0.3 USD and has an open order with 100 BTS
  • wait for 2 blocks
    • the orders get matched
    • Alice's order is full-filled, will send to Alice 0.00267*0.003=0.00000801 USD, but the quantity is too small, so actually sent 0 USD, and paid 0 BTS to Bob's order in return
    • Bob's order is partially filled, received 0 BTS from Alice's order, so paid 0 USD to Alice and sent 0 BTS to Bob
    • a 0-quantity market transaction generated
  • same matching occurs every block, until one of them get cancelled

@abitmore
Copy link
Member

abitmore commented May 1, 2015

Possible solution:
In the market, when we found an order whose value is less than the minimum positive quantity of one of the trading pair, for example 10^-4 USD or 10^-5 BTS, cancel it automatically and refund to its owner. If the order is a cover_order, cover it with system fee/interest pool.

@pmconrad
Copy link
Contributor

pmconrad commented May 1, 2015

Great analysis!
But I think this cannot happen for covers because a cover always asks for at least 0.0001 USD.

@abitmore
Copy link
Member

abitmore commented May 1, 2015

Let's go back to the time when 1 BTS ~= 0.03 USD ~= 32 KRW. If there was a cover asks for 0.0001 KRW, it's less than 0.00001 BTS and would cause trouble.

@pmconrad
Copy link
Contributor

pmconrad commented May 3, 2015

ACK

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants