Skip to content

Commit 2fc45d9

Browse files
committed
added ticker, helper function to convert float balance to int
1 parent 0bae3a8 commit 2fc45d9

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

plot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'ethereum': 'ETH',
1414
'litecoin': 'LTC',
1515
'tezos': 'XTZ',
16+
'ripple': 'XRP'
1617
}
1718

1819

tests/test_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def test_get_denomination_from_coin():
173173
assert hlp.get_denomination_from_coin('ethereum') == 1e9
174174
assert hlp.get_denomination_from_coin('litecoin') == 1e8
175175
assert hlp.get_denomination_from_coin('tezos') == 1e6
176+
assert hlp.get_denomination_from_coin('ripple') == 1e6
176177
assert hlp.get_denomination_from_coin('blahblah') == 1
177178

178179

tokenomics_decentralization/helper.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
from yaml import safe_load
1414
from dateutil.rrule import rrule, MONTHLY, WEEKLY, YEARLY, DAILY
15+
from typing import Union
1516

1617
ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent
1718
MAPPING_INFO_DIR = ROOT_DIR / 'mapping_information'
@@ -410,7 +411,8 @@ def get_denomination_from_coin(ledger):
410411
'cardano': 1e6,
411412
'ethereum': 1e9,
412413
'litecoin': 1e8,
413-
'tezos': 1e6
414+
'tezos': 1e6,
415+
'ripple': 1e6
414416
}
415417
try:
416418
return denominations[ledger]
@@ -643,3 +645,26 @@ def get_concurrency_per_ledger():
643645
'large to load in memory' + ','.join(too_large_ledgers))
644646

645647
return concurrency
648+
649+
650+
def convert_to_atomic_units(coin: str, balance: Union[str, float]) -> int:
651+
"""
652+
Convert a floating balance to its atomic unit representation using the coin's denomination.
653+
654+
Parameters
655+
----------
656+
coin : str
657+
The name of the cryptocurrency (e.g., 'ripple', 'bitcoin', 'ethereum').
658+
balance : str or float
659+
The balance in full coin units (e.g., '17.229982' XRP or 0.001 BTC).
660+
661+
Returns
662+
-------
663+
int
664+
The equivalent balance in atomic units (e.g., drops, satoshis, wei).
665+
"""
666+
try:
667+
denomination = get_denomination_from_coin(coin)
668+
return int(float(balance) * denomination)
669+
except (ValueError, TypeError) as e:
670+
raise ValueError(f"Invalid balance or coin type: {coin}, {balance}") from e

0 commit comments

Comments
 (0)