BitShares Forum

Main => Technical Support => Topic started by: sharique-knysys on January 26, 2016, 06:34:51 am

Title: Want to calculate exchange rate of any currency?
Post by: sharique-knysys on January 26, 2016, 06:34:51 am
Hi I want to convert any currency to BTS. I have checked currencies on cryptofresh.com. For example how can I calculate that how many bts equal to $1. Like it is displayed on cryptofresh.com

Exchange rate   0.00327 USD/BTS
Title: Re: Want to calculate exchange rate of any currency?
Post by: abit on January 26, 2016, 08:48:30 am
In wallet, click on the "USD/BTS".
Title: Re: Want to calculate exchange rate of any currency?
Post by: xeroc on January 26, 2016, 08:54:35 am
What abit wants to say is that in the BTS/OL wallet you can flip any market by clicking the market in the top navigation bar or by searching for y:x instead of x:y market
Title: Re: Want to calculate exchange rate of any currency?
Post by: abit on January 26, 2016, 08:59:40 am
What abit wants to say is that in the BTS/OL wallet you can flip any market by clicking the market in the top navigation bar or by searching for y:x instead of x:y market
Thanks for explanation.
But if OP wants to see something different on CryptoFresh, I have no idea..
Title: Re: Want to calculate exchange rate of any currency?
Post by: sharique-knysys on January 26, 2016, 09:23:47 am
I am using following api.

https://bitshares.openledger.info/ws/

I can get this response. How can I calculate exchange rate from this reponse

Code: [Select]
{
  "id": 2,
  "result": [
    {
      "id": "1.3.102",
      "symbol": "KRW",
      "precision": 4,
      "issuer": "1.2.0",
      "options": {
        "max_supply": "1000000000000000",
        "market_fee_percent": 0,
        "max_market_fee": "1000000000000000",
        "issuer_permissions": 511,
        "flags": 128,
        "core_exchange_rate": {
          "base": {
            "amount": 43,
            "asset_id": "1.3.102"
          },
          "quote": {
            "amount": 104,
            "asset_id": "1.3.0"
          }
        },
        "whitelist_authorities": [],
        "blacklist_authorities": [],
        "whitelist_markets": [],
        "blacklist_markets": [],
        "description": "1 South Korean won",
        "extensions": []
      },
      "dynamic_asset_data_id": "2.3.102",
      "bitasset_data_id": "2.4.2"
    }
  ]
}


Title: Re: Want to calculate exchange rate of any currency?
Post by: svk on January 26, 2016, 09:32:07 am
You can use the core_exchange_rate object which defines a price. Since this is a bitasset you can also fetch the bitasset_data_id object which contains a settlement_price which is more precise.
Title: Re: Want to calculate exchange rate of any currency?
Post by: sharique-knysys on January 26, 2016, 09:40:53 am
I tried to calculate from base which has amount 43 and quote has amount 104. I divided base amount/quote amount which means 43/104 = 0.4134. When I checked KRW on cryptofresh.com it showed 4.11 KRW/BTS. So what is the mistake in that? Please point it out. Thanks
Title: Re: Want to calculate exchange rate of any currency?
Post by: xeroc on January 26, 2016, 11:30:30 am
This is what I do:
https://github.com/xeroc/python-graphenelib/blob/master/grapheneexchange/exchange.py#L170-L182
you will need the assets precisions aswell!
The example above derives the price as quote/base .. you may want to have it the other way round depending on your application!