Code: Select all
--These functions return the current Bitcoin Rate from their respective services. The sCurrency parameter should be
--a valid three letter currency code. (i.e. USD,EUR,CNY, etc)
--note: Some of these functions require the three letter currency codes to be capitalized , better to just always capitalize....
--note: BitStampRate() requires no parameters as is is only USD
--Bitpay: The currency codes that can be used with this function are listed here: https://bitpay.com/bitcoin-exchange-rates
function BitPayRate sCurrency
put ("https://bitpay.com/api/rates/"&sCurrency) into tBitPayURL
get url tBitPayURL
put it into tBitPayData
set the itemdelimiter to colon
put item 4 of tBitPayData into tBitPayData
replace "}" with empty in tBitPayData
if tBitPayData is a number then
return sCurrency&&":"&&tBitPayData
else
return "There was a problem with your request."
end if
end BitPayRate
--Coinbase: The supported Currency Codes are available here: https://coinbase.com/api/v1/currencies
function CoinBaseRate sCurrency
put "https://coinbase.com/api/v1/prices/spot_rate?currency="&sCurrency into tCoinbaseURL
get URL tCoinBaseURL
put it into tCoinBaseData
put item 1 of tCoinbaseData into tCoinbaseData
set the itemdelimiter to colon
put item 2 of tCoinBaseData into tCoinBaseData
replace quote with Empty in tCoinBaseData
if tCoinBaseData is a number then
return sCurrency&&":"&& tCoinBaseData
else
else return "There was a problem with your request."
end if
end CoinBaseRate
--Bter: Currently only works with USD or CNY calls.
function BterRate sCurrency
put "http://data.bter.com/api/1/ticker/btc_"&sCurrency into tBterURL
get URL tBterURL
put it into tBterData
put item 2 of tBterData into tBterData
set the itemdelimiter to colon
if item 2 of tBterData is a number then
return sCurrency&&":"&& item 2 of tBterData
else
else return "There was a problem with your request."
end if
end BterRate
--This one requires the three letter currency code be capitalized, and returns the 24 hour Bitcoin Average
--supported currencies: USD,EUR,CNY,GBP,CAD,PLN,RUB,AUD,SEK,BRL,NZD,SGD,ZAR,NOK,ILS,CHF,TRY,HKD,RON,MXN,IDR
function BitCoinAverage sCurrency
put "https://api.bitcoinaverage.com/ticker/global/"&sCurrency&"/" into tBitCoinAverageURL
get URL tBitCoinAverageURL
put it into tBitCoinAverageData
put item 1 of tBitCoinAverageData into tBitCoinAverageData
set the itemdelimiter to colon
replace space with empty in tBitCoinAverageData
if item 2 of tBitCoinAverageData is a number then
return sCurrency&&":"&& item 2 of tBitCoinAverageData
else
else return "There was a problem with your request."
end if
end BitCoinAverage
--BitStamp: this one has no parameters because bitstamp only deals in USD/BTC trades as far as I can tell. Although I think they do have a USD/EUR market as well.
function BitStampRate
get url "https://www.bitstamp.net/api/ticker/"
put it into tBitStampData
put item 2 of tBitStampData into tBitStampData
set the itemdelimiter to colon
put item 2 of tBitStampData into tBitStampData
replace quote with empty in tBitStampData
if tBitStampData is a number then
return "USD :"&& tBitStampData
else
else return "There was a problem with your request."
end if
end BitStampRate
--Sefro