mmnode-ticker: support reverse USD rate in asset specifier

Testing / demo:

    $ test/test.py -e scripts.ticker
This commit is contained in:
The MMGen Project 2022-08-05 11:57:23 +00:00
commit 015de30cdd
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 34 additions and 13 deletions

View file

@ -295,13 +295,18 @@ def make_cfg(cmd_args,cfg_in):
sym,id = (s.split('-')[0],s) if '-' in s else (s,None)
return asset_tuple( sym.upper(), id.lower() if id else None )
def parse_asset_triplet(s):
def parse_asset_triplet(s,reverse_ok=False):
ss = s.split(':')
sym,amt = ( ss[0], Decimal(ss[1]) ) if len(ss) == 2 else ( s, None )
return asset_triplet( *parse_asset_tuple(sym), amt )
return asset_triplet(
*parse_asset_tuple(s if len(ss) == 1 else ss[0]),
(
None if len(ss) == 1 else
1 / Decimal(ss[1][:-1]) if reverse_ok and ss[1].lower().endswith('r') else
Decimal(ss[1])
))
def parse_usr_asset_arg(s):
return tuple(parse_asset_triplet(ss) for ss in s.split(',')) if s else ()
return tuple(parse_asset_triplet(ss,reverse_ok=True) for ss in s.split(',')) if s else ()
def parse_query_arg(s):
ss = s.split(':')

View file

@ -1 +1 @@
3.1.dev4
3.1.dev5

View file

@ -76,11 +76,13 @@ ambiguous, the full ID must be used. Examples:
ASSET SPECIFIERS consist of an ASSET followed by an optional colon and USD
rate. If the asset is not in the source data (see --list-ids), the label
part of the ID may be arbitrarily chosen by the user. Examples:
part of the ID may be arbitrarily chosen by the user. When the letter r
is appended to the USD rate, the rate is reversed, i.e. treated as USD per
asset instead of asset per USD. Asset specifier examples:
inr:79.5 - INR is not in the source data, so supply USD rate
inr-indian-rupee:79.5 - same as above, but add an arbitrary label
ada-cardano:0.51 - ADA is in the source data, so use the listed ID
omr-omani-rial:2.59r - OMR is pegged to USD with fixed value of 2.59 USD
A TRADE_SPECIFIER is a single argument in the format:
@ -121,9 +123,9 @@ configured cache directory, and run the script with the --cached-data option.
To protect user privacy, all filtering and processing of data is performed
client side so that the remote server does not know which assets are being
examined. This means that data for ALL available assets (currently over 4000)
is fetched with each invocation of the script. A rate limit of {ratelimit} seconds
between calls is thus imposed to prevent abuse of the remote server. When the
--btc option is in effect, this limit is reduced to 10 seconds. To bypass the
is fetched with each invocation of the script. A rate limit of {L} seconds
between calls is thus imposed to prevent abuse of the remote server. When the
--btc option is in effect, this limit is reduced to {B} seconds. To bypass the
rate limit entirely, use --cached-data.
@ -135,8 +137,9 @@ $ mmnode-ticker
# Display BTC price only:
$ mmnode-ticker --btc
# Wide display, add EUR and INR columns, INR rate, extra precision and proxy:
$ mmnode-ticker -w -c eur,inr-indian-rupee:79.5 -e2 -x http://vpnhost:8118
# Wide display, add EUR and OMR columns, OMRUSD rate, extra precision and
# proxy:
$ mmnode-ticker -w -c eur,omr-omani-rial:2.59r -e2 -x http://vpnhost:8118
# Wide display, use cached data from previous network query, show portfolio
# (see above), pipe output to pager, add DOGE row:
@ -177,7 +180,8 @@ To add a portfolio, edit the file
pf_cfg = os.path.relpath(cfg_in.portfolio_file,start=homedir),
api_host = api_host,
api_url = api_url,
ratelimit = ratelimit,
L = ratelimit,
B = btc_ratelimit,
)
}
}

View file

@ -85,6 +85,7 @@ class TestSuiteScripts(TestSuiteBase):
('ticker13', 'ticker [--cached-data --wide --elapsed -c inr-indian-rupee:79.5 inr:200000:btc:0.1]'),
('ticker14', 'ticker [--cached-data --wide --btc]'),
('ticker15', 'ticker [--cached-data --wide --btc btc:2:usd:45000]'),
('ticker16', 'ticker [--cached-data --wide --elapsed -c eur,omr-omani-rial:2.59r'),
)
}
@ -271,3 +272,14 @@ class TestSuiteScripts(TestSuiteBase):
'BITCOIN 2.00000000 1.92563954 33 hours, 2 minutes ago ' +
'US DOLLAR 46,737.71911598 45,000.00000000 33 hours, 2 minutes ago',
])
def ticker16(self):
return self.ticker(
['--wide','--elapsed','-c','eur,omr-omani-rial:2.59r'],
[
r'EUR \(EURO TOKEN\) = 1.0186 USD ' +
r'OMR \(OMANI RIAL\) = 2.5900 USD',
'USD EUR OMR BTC CHG_7d CHG_24h UPDATED',
'BITCOIN',
'OMANI RIAL 2.59 2.5428 1.0000 0.00011139 -- -- just now'
])