atx-crypto-club / atxcf

atxcf bot
MIT License
6 stars 3 forks source link

Add support for baskets of currencies/assets #5

Open transfix opened 8 years ago

transfix commented 8 years ago

We need to add a feature that makes available a price for a synthetic symbol who's value is calculated by the underlying prices of assets and quantities held in a basket represented by that symbol. This would make it easy to track the net asset value of a hypothetical fund as a symbol as if it is just another trade-able asset known by the PriceNetwork.

They way I imagine it to be implemented would be to add a function to PriceNetwork called set_basket that would take 2 arguments: a basket symbol name and a dictionary of symbols mapped to quantities, e.g.:

pn = PriceNetwork()
pn.set_basket("FUND", {"BTC": 1, "DOGE": 1000000, "LTC": 143})

print(pn.get_symbols()) # prints "FUND" among other symbols
print(pn.get_price("FUND", "USD")) # Returns the USD value of everything in FUND

For completeness we should probably also add a remove_basket():

pn.remove_basket("FUND")
print(pn.get_symbols()) # "FUND" is gone

Finally, we would need to add the functions as commands for slack (not webapi for now since it is read only).

transfix commented 8 years ago

Additionally (and perhaps prior to developing the above), I was thinking of supporting multiple arguments for get_price such that you can input a list of (amount, from_asset) pairs and a final symbol as the base (to_asset), and it will return list of prices for quantities specified in terms of that base symbol along with the sum of all prices.

transfix commented 8 years ago

Let's remove the idea of baskets from PriceNetwork and make an actual PriceSource to handle baskets, then just add them to the network like any other price source.

transfix commented 8 years ago

Actually even better, I forgot about just using the Conversions source for baskets too- let's just write a module to make it easy to specify baskets but have it just define them using the Conversions source.

transfix commented 7 years ago

I still need to remove basket code in PriceNetwork and add it to Conversions...

Note: The expressions in the settings file for each conversion should be well formed python code that could be evaluated at a typical REPL

transfix commented 6 years ago

The latest approach is to use the new account module to define a portfolio held by a "basket" account such as an account for the fund itself.