G
Gwadro
unregistriert
Thread Starter
- Dabei seit
- 05.06.2012
- Beiträge
- 1.585
- Reaktionspunkte
- 860
Hallo zusammen,
Ich möchte über die API der Börse Bitstamp.net die Kurse abfragen und in eine Tabelle bei Numbers eintragen.
Die Funktion als solche habe ich im Netz gefunden https://discussions.apple.com/thread/7611695?start=0&tstart=0 und das funktioniert auch. Allerdings nutzt das Script die Cryptonator API
Okay, also bauen wir es für Bitstamp.net um. Leichter gesagt als getan.
Ich habe keine richtige Ahnung von dem ganzen, bin aber durchaus in der Lage mir etwas Wissen herauszulesen und mit try and error voran zu kommen.
Jetzt habe ich die API von Bitstamp erfolgreich abgefragt und das funktioniert auch:
Auf den Screenshot ist der aktuelle Stand der Dinge und ich komme nicht weiter. Siehe Error
Ich habe mal die numbers und die drei Scripte in der zip abgelegt. Einmal das Original , mein Bitstamp-Script und das einfache Script für Bitstamp. https://www.dropbox.com/s/uvmvmw4mnl06wet/Zip-Bitstamp.zip?dl=0
Wenn da mal drüber schauen würde der mehr Ahnung als ich davon hat.
EDIT:
Die App "JSON Helper for AppleScript" aus den App Store wird benötigt. https://itunes.apple.com/de/app/json-helper-for-applescript/id453114608?mt=12
Ich möchte über die API der Börse Bitstamp.net die Kurse abfragen und in eine Tabelle bei Numbers eintragen.
Die Funktion als solche habe ich im Netz gefunden https://discussions.apple.com/thread/7611695?start=0&tstart=0 und das funktioniert auch. Allerdings nutzt das Script die Cryptonator API
Okay, also bauen wir es für Bitstamp.net um. Leichter gesagt als getan.
Ich habe keine richtige Ahnung von dem ganzen, bin aber durchaus in der Lage mir etwas Wissen herauszulesen und mit try and error voran zu kommen.
Jetzt habe ich die API von Bitstamp erfolgreich abgefragt und das funktioniert auch:
Code:
set json to (do shell script "curl https://www.bitstamp.net/api/v2/ticker/etheur")
tell application "JSON Helper"
set result to read JSON from json
set price to |last| of result
end tell
set result_string to "$" & price & ""
Code:
validate_sheet()
set coins to {}
-- retrieve the list of coins from number
tell application "Numbers"
tell table 1 of sheet 1 of document 1
set cntRow to count row
set cntCol to count column
repeat with curRow from 1 to cntRow
if curRow mod 2 is not 0 then
set tmpVal to value of cell curRow of column 1
set the end of the coins to {|name|:tmpVal, price:null}
end if
end repeat --curRow
end tell --document
end tell -- application
-- get the value for each coin
repeat with coin in coins
set BASE_URL to "https://www.bitstamp.net/api/v2/ticker/"
set BASE_CURRENCY to "usd"
set coinUrl to BASE_URL & (|name| of coin) & BASE_CURRENCY
set json to (do shell script "curl " & coinUrl)
tell application "JSON Helper"
set result to fetch JSON from json
set coinPrice to |last| of result
end tell
# tell application "JSON Helper"
# set response to fetch JSON from coinUrl
# end tell
# if success of response is not false then
# set coinPrice to |last| of result
# else
# set coinPrice to "error"
# end if
set price of coin to coinPrice
end repeat
-- update values in numbers
tell application "Numbers"
tell table 1 of sheet 1 of document 1
set cntRow to count row
set cntCol to count column
repeat with curRow from 1 to cntRow
set coinName to value of cell curRow of column 1
repeat with coin in coins
if |name| of coin is equal to coinName then
if price of coin is not equal to "error" then
set value of cell curRow of column 2 to price of coin
set value of cell curRow of column 3 to (get current date)
end if
end if
end repeat
end repeat --curRow
end tell --document
end tell -- application
return
on validate_sheet()
tell application "Numbers"
if not (exists document 1) then error number 1000
-- validate sheet
set curSheet to sheet 1 of document 1
set curSheetName to curSheet's name
if curSheetName is not "Overview_All" then
error "Incorrect Sheet: " & curSheetName
end if
-- validate table
set curTable to table 1 of curSheet
set curTableName to curTable's name
if curTableName is not "Coin Values (USD)" then
error "Incorrect Table: " & curTableName
end if
end tell
end validate_sheet
Ich habe mal die numbers und die drei Scripte in der zip abgelegt. Einmal das Original , mein Bitstamp-Script und das einfache Script für Bitstamp. https://www.dropbox.com/s/uvmvmw4mnl06wet/Zip-Bitstamp.zip?dl=0
Wenn da mal drüber schauen würde der mehr Ahnung als ich davon hat.
EDIT:
Die App "JSON Helper for AppleScript" aus den App Store wird benötigt. https://itunes.apple.com/de/app/json-helper-for-applescript/id453114608?mt=12
Anhänge
Zuletzt bearbeitet: