You are viewing a single comment's thread from:

RE: Cryptocurrency Accounting in Excel

in #howto7 years ago

Yes, you can do the same in OpenOffice as well.

Go to Tools ⇒ Macros ⇒ Organize Macros ⇒ OpenOffice Basic..., create a new module under your current document, and paste the following, slightly modified, version of the code in the newly opened editor window:

Public Function HttpGet(ByVal requestUrl As String) As String
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    With http
        .Open "GET", requestUrl, True
        .Send ""
        .WaitForResponse 10
        HttpGet = .ResponseText
    End With
End Function

Public Function GetCryptoCurrencyPrice(ByVal name As String, ByVal baseCurrency As String, Optional cacheBuster As Variant) As Double
    GetCryptoCurrencyPrice = -1#
    json = HttpGet("https://api.coinmarketcap.com/v1/ticker/" & name & "/?convert=" & baseCurrency)
    
    For Each Line In Split(json)
        If found Then
            GetCryptoCurrencyPrice = CDbl(Mid(Line, 2, Len(Line) - 3))
            Exit Function
        End If
        If Line = """price_" & LCase(baseCurrency) & """:" Then
            found = True
        End If
    Next
End Function