Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudbuzing committed Nov 1, 2017
1 parent e38c318 commit 6d89da6
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions CoinMarketCap/CoinMarketCap.wl
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
BeginPackage["CoinMarketCap`"]

Ticker::usage = "Ticker[] returns the current ticker values for a range of bitcoin based currencies. Ticker[ currency ] also includes information about traditional currencies";
SingleTicker::usage = "SingleTicker[] returns the current ticker values for the given bitcoin currency. SingleTicker[ currency ] also includes information about traditional currencies";
TickerLimit::usage = "TickerLimit is an option to Ticker which limits the number of results";
TraditionalCurrency::usage = "TraditionalCurrency is an option to Ticker which prompt Ticker to return additional local traditional currency information";
GlobalData::usage = "GlobalData[] returns global information for active currencies and markets";

Begin["`Private`"]

$CoinMarketCapDirectory = DirectoryName[$InputFileName];
Protect[$CoinMarketCapDirectory];

$Currencies = { "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR" };
$TraditionalCurrencies = { "AUD", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PKR", "PLN", "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR" };
$BitCoinCurrencies = {} ;

$CoinMarketCapBaseUrl = "https://api.coinmarketcap.com/v1";

Options[ Ticker ] = { TickerLimit -> None };
Options[ Ticker ] = { TraditionalCurrency -> "USD", TickerLimit -> None };

Ticker[ opts:OptionsPattern[] ] := Ticker[ "USD", opts ];
Ticker[ opts:OptionsPattern[] ] := Module[ { convert, limit, url },
convert = OptionValue[TraditionalCurrency];
limit = OptionValue[TickerLimit];
url = URLBuild[ { $CoinMarketCapBaseUrl, "ticker" }, { "limit" -> limit, "convert" -> convert } ];
Dataset[ Import[ url, "RawJSON"] ]
]

Options[ SingleTicker ] = { TraditionalCurrency -> "USD" };

Ticker[ convert_String, opts:OptionsPattern[] ] := Module[ { tickerlimit, limit, url },
tickerlimit = OptionValue[TickerLimit];
limit = If[ tickerlimit === None , "", ToString[tickerlimit] ];
url = URLBuild[ $CoinMarketCapBaseUrl, { "limit" -> limit, "convert" -> convert } ]
SingleTicker[ id_String, opts:OptionsPattern[] ] := Module[ { convert, url },
convert = OptionValue[TraditionalCurrency];
url = URLBuild[ { $CoinMarketCapBaseUrl, "ticker", id }, { "convert" -> convert } ];
Dataset[ Import[ url, "RawJSON"] ]
]

Options[ GlobalData ] = { TraditionalCurrency -> "USD" };

GlobalData[ opts:OptionsPattern[] ] := Module[ { convert, url },
convert = OptionValue[TraditionalCurrency];
url = URLBuild[ { $CoinMarketCapBaseUrl, "global" }, { "convert" -> convert } ];
Dataset[ Import[ url, "RawJSON"] ]
]

End[]

Expand Down

0 comments on commit 6d89da6

Please sign in to comment.