Code: Select all
Public Sub Main()
Dim vNew As Variant
Dim sNew As String
Shell "wget -O - https://poloniex.com/public?command=returnTicker" To sNew
vNew = Json.decode(sNew) ''Requires component 'gb.web'
Print vNew["BTC_BCN"]["last"]
Stop
End
Code: Select all
Public Sub Main()
Dim vNew As Variant
Dim sNew As String
Shell "wget -O - https://poloniex.com/public?command=returnTicker" To sNew
vNew = Json.decode(sNew) ''Requires component 'gb.web'
Print vNew["BTC_BCN"]["last"]
Stop
End
Code: Select all
Public Sub Main()
Dim vNew As Variant
Dim sNew As String
Dim cBitcoin As Collection
Dim ciBitcoin As Collection
Shell "wget -O - https://poloniex.com/public?command=returnTicker" To sNew
vNew = Json.decode(sNew) ''Requires component 'gb.web'
cBitcoin = vNew
' Print cBitcoin.Length
For Each ciBitcoin In cBitcoin
Print cBitcoin.Key, cBitcoin[cBitcoin.Key]["last"]
Next
Stop
End
Code: Select all
cBitcoin[cBitcoin.Key]["last"]
Code: Select all
strKeyName = cBitcoin[2].Name
Code: Select all
cBitcoin[cBitcoin.Key]["high24hr"]
Code: Select all
For Each ciBitcoin In cBitcoin
If InStr(cBitcoin.Key, "ETH") > 0 Then
Print cBitcoin.Key, cBitcoin[cBitcoin.Key]["last"], cBitcoin[cBitcoin.Key]["high24hr"]
Endif
Next
I think that should be pretty easy actually. A recursive function to do the data extraction, and start it with a test like this:http://gambaswiki.org/wiki/lang/isAs an additional exercise, I spent an hour or two this morning trying to do the same thing with:
"https://www.cryptocompare.com/api/data/coinlist/"
This collection includes a mixture of strings and collections, and I can't think how to deal with this.
Public Sub GetCollectionData(Col as Collection)
Dim v as Variant
For Each v In Col
If v Is Collection Then
GetCollectionData(v)
Else
Print("Key: " & Col.Key & " Value: " & v
End If
End Sub
Code: Select all
Shell "wget -O - https://www.cryptocompare.com/api/data/coinlist/" To sNew
cBitcoin = Json.decode(sNew, True)
For Each ciBitcoin In cBitcoin["Data"]
strCrypto.Resize(intCoinCount + 1)
strCrypto.Add(ciBitcoin["Name"] & ":" & ciBitcoin["CoinName"])
Inc intCoinCount
Next
strCrypto.Sort 'sort them in alpha order
For index = 0 To strCrypto.Count - 1
Print strCrypto[index]
Next
Print "Total:", intCoinCount
Take a look at this For Each...In... example:-cogier wrote: ↑Thursday 14th September 2017 4:16pm ...Your solution worked but confused me as I have only ever enumerated with the variable after 'Each' not with the variable after 'In'
e.g.
For Each ciBitcoin In cBitcoin
Print ciBitcoin.Key
Next
But you worked with ciBitcoin, it works but I can't work out the logic here.
For Each ciBitcoin In cBitcoin
Print cBitcoin.Key
Next
Code: Select all
Public Sub Main()
Dim Cars As New Collection
Dim Make As String
Cars["Ford"] = 2
Cars["Audi"] = 1
Cars["Jaguar"] = 4
Cars["Lada"] = 3
For Each Make In Cars
Print Make;
Next
End
Code: Select all
Print Cars["Lada"]
Code: Select all
For Each ciBitcoin In cBitcoin
Public Sub Main()
Dim vNew As Variant
Dim sNew As String
Dim cCol, cCol1 As Collection
Shell "wget -O - https://poloniex.com/public?command=returnTicker" To sNew
vNew = Json.decode(sNew) ''Requires component 'gb.web'
cCol = vNew
For Each cCol1 In cCol
GetCollectionData(cCol1)
Next
End
Public Sub GetCollectionData(Col As Collection)
Dim v As Variant
For Each v In Col
If v Is Collection Then ''Error here 'Wanted object got integer instead'
GetCollectionData(v)
Else
Print "Key: " & Col.Key & " Value: " & v
End If
Next
Catch
Print "Key: " & Col.Key & " Value: " & v
End
This got me: -He'll need lots of these then "{}{}{}{}{}{}{}".I discussed it with #3 son last night (he is doing Computer Science at Uni, but does not code in Gambas)