diff --git a/ModExchBittrex.bas b/ModExchBittrex.bas index 7081a79..a5c2ed5 100644 --- a/ModExchBittrex.bas +++ b/ModExchBittrex.bas @@ -33,17 +33,12 @@ End Sub Function PublicBittrex(Method As String, Optional MethodOptions As String) As String 'https://bittrex.com/home/api +Dim Url As String PublicApiSite = "https://bittrex.com" urlPath = "/api/v1.1/public/" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicBittrex = objHTTP.ResponseText -Set objHTTP = Nothing +PublicBittrex = GetDataFromURL(Url, "GET") End Function Function PrivateBittrex(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -60,11 +55,11 @@ APIsign = ComputeHash_C("SHA512", TradeApiSite & postdata, secretkey, "STRHEX") ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -Debug.Print "POST: " & TradeApiSite & postdata +'Debug.Print "POST: " & TradeApiSite & postdata objHTTP.Open "POST", TradeApiSite & postdata, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" -objHTTP.SetRequestHeader "apisign", APIsign +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +objHTTP.setRequestHeader "apisign", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModExchCoinone.bas b/ModExchCoinone.bas index 9f575bc..ff0488c 100644 --- a/ModExchCoinone.bas +++ b/ModExchCoinone.bas @@ -33,17 +33,12 @@ End Sub Function PublicCoinone(Method As String, Optional MethodOptions As String) As String 'https://Coinone.com/home/api +Dim Url As String PublicApiSite = "https://api.coinone.co.kr/" urlPath = Method & "/" & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicCoinone = objHTTP.ResponseText -Set objHTTP = Nothing +PublicCoinone = GetDataFromURL(Url, "GET") End Function Function PrivateCoinone(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -73,9 +68,9 @@ APIsign = ComputeHash_C("SHA512", Base64Encode(postdata_json_txt), secretkey, "S '' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", Url, False -objHTTP.SetRequestHeader "Content-Type", "application/json" -objHTTP.SetRequestHeader "X-COINONE-PAYLOAD", postdata64 -objHTTP.SetRequestHeader "X-COINONE-SIGNATURE", APIsign +objHTTP.setRequestHeader "Content-Type", "application/json" +objHTTP.setRequestHeader "X-COINONE-PAYLOAD", postdata64 +objHTTP.setRequestHeader "X-COINONE-SIGNATURE", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModExchCryptopia.bas b/ModExchCryptopia.bas index 760d8cd..f79d305 100644 --- a/ModExchCryptopia.bas +++ b/ModExchCryptopia.bas @@ -33,18 +33,12 @@ End Sub Function PublicCryptopia(Method As String, Optional MethodOptions As String) As String 'https://www.cryptopia.co.nz/forum/Thread/255 - +Dim Url As String PublicApiSite = "https://www.cryptopia.co.nz" urlPath = "/api/" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicCryptopia = objHTTP.ResponseText -Set objHTTP = Nothing +PublicCryptopia = GetDataFromURL(Url, "GET") End Function Function PrivateCryptopia(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -76,9 +70,9 @@ HeaderValue = "amx " & apikey & ":" & hmacSignature & ":" & NonceUnique ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", Url, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/json" -objHTTP.SetRequestHeader "Authorization", HeaderValue +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/json" +objHTTP.setRequestHeader "Authorization", HeaderValue objHTTP.Send (postdataJsonTxt) objHTTP.WaitForResponse diff --git a/ModExchKraken.bas b/ModExchKraken.bas index 920548e..942e1d2 100644 --- a/ModExchKraken.bas +++ b/ModExchKraken.bas @@ -35,18 +35,12 @@ End Sub Function PublicKraken(Method As String, Optional MethodOptions As String) As String 'https://www.kraken.com/en-us/help/api#public-market-data - +Dim Url As String PublicApiSite = "https://api.kraken.com" urlPath = "/0/public/" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicKraken = objHTTP.ResponseText -Set objHTTP = Nothing +PublicKraken = GetDataFromURL(Url, "GET") End Function Function PrivateKraken(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -70,10 +64,10 @@ APIsign = ComputeHash_C("SHA512", urlPath & ComputeHash_C("SHA256", NonceUnique ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", Url, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" -objHTTP.SetRequestHeader "API-Key", apikey -objHTTP.SetRequestHeader "API-Sign", APIsign +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +objHTTP.setRequestHeader "API-Key", apikey +objHTTP.setRequestHeader "API-Sign", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModExchLiqui.bas b/ModExchLiqui.bas index 5d8c011..ef157e5 100644 --- a/ModExchLiqui.bas +++ b/ModExchLiqui.bas @@ -34,18 +34,12 @@ End Sub Function PublicLiqui(Method As String, Optional MethodOptions As String) As String 'https://www.Liqui.com/en-us/help/api#public-market-data - +Dim Url As String PublicApiSite = "https://api.liqui.io" urlPath = "/api/3/" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicLiqui = objHTTP.ResponseText -Set objHTTP = Nothing +PublicLiqui = GetDataFromURL(Url, "GET") End Function Function PrivateLiqui(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -64,18 +58,18 @@ urlPath = "/tapi/" postdata = "method=" & Method & MethodOptions & "&nonce=" & NonceUnique Url = TradeApiSite & urlPath APIsign = ComputeHash_C("SHA512", postdata, secretkey, "STRHEX") -Debug.Print postdata -Debug.Print Url -Debug.Print apikey -Debug.Print APIsign +'Debug.Print postdata +'Debug.Print Url +'Debug.Print apikey +'Debug.Print APIsign ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", Url, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" -objHTTP.SetRequestHeader "Key", apikey -objHTTP.SetRequestHeader "Sign", APIsign +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +objHTTP.setRequestHeader "Key", apikey +objHTTP.setRequestHeader "Sign", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModExchPoloniex.bas b/ModExchPoloniex.bas index 1afbe79..42e2800 100644 --- a/ModExchPoloniex.bas +++ b/ModExchPoloniex.bas @@ -34,18 +34,12 @@ End Sub Function PublicPoloniex(Method As String, Optional MethodOptions As String) As String 'https://poloniex.com/support/api/ - +Dim Url As String PublicApiSite = "https://poloniex.com" urlPath = "/public?command=" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicPoloniex = objHTTP.ResponseText -Set objHTTP = Nothing +PublicPoloniex = GetDataFromURL(Url, "GET") End Function Function PrivatePoloniex(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String @@ -66,10 +60,10 @@ APIsign = ComputeHash_C("SHA512", postdata, secretkey, "STRHEX") ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", Url, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" -objHTTP.SetRequestHeader "Key", apikey -objHTTP.SetRequestHeader "Sign", APIsign +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +objHTTP.setRequestHeader "Key", apikey +objHTTP.setRequestHeader "Sign", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModExchWEXnz.bas b/ModExchWEXnz.bas index a02cbf7..791003c 100644 --- a/ModExchWEXnz.bas +++ b/ModExchWEXnz.bas @@ -24,7 +24,7 @@ Debug.Print PublicWEXnz("ticker", "/ltc_btc-btc_eur") t1 = DateToUnixTime("1/1/2014") t2 = DateToUnixTime("1/1/2018") -Debug.Print t1, t2 +'Debug.Print t1, t2 Debug.Print PrivateWEXnz("getInfo", apikey, secretkey) '{"success":1,"return":{"funds":{"usd":0,"btc":0.14,"ltc":0,"nmc":0, etc... Debug.Print PrivateWEXnz("TradeHistory", apikey, secretkey, "&since=" & t1 & "&end=" & t2) @@ -34,24 +34,18 @@ End Sub Function PublicWEXnz(Method As String, Optional MethodOptions As String) As String -'https://btc-e.com/api/3/docs - +'https://wex.nz/api/3/docs +Dim Url As String PublicApiSite = "https://wex.nz" urlPath = "/api/3/" & Method & MethodOptions Url = PublicApiSite & urlPath -' Instantiate a WinHttpRequest object and open it -Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") -objHTTP.Open "GET", Url -objHTTP.Send -objHTTP.WaitForResponse -PublicWEXnz = objHTTP.ResponseText -Set objHTTP = Nothing +PublicWEXnz = GetDataFromURL(Url, "GET") End Function Function PrivateWEXnz(Method As String, apikey As String, secretkey As String, Optional MethodOptions As String) As String -'https://btc-e.com/tapi/docs +'https://wex.nz/tapi/docs Dim NonceUnique As String 'BTC-e wants a 10-digit Nonce @@ -64,10 +58,10 @@ APIsign = ComputeHash_C("SHA512", postdata, secretkey, "STRHEX") ' Instantiate a WinHttpRequest object and open it Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") objHTTP.Open "POST", TradeApiSite, False -objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" -objHTTP.SetRequestHeader "Key", apikey -objHTTP.SetRequestHeader "Sign", APIsign +objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +objHTTP.setRequestHeader "Key", apikey +objHTTP.setRequestHeader "Sign", APIsign objHTTP.Send (postdata) objHTTP.WaitForResponse diff --git a/ModFunctions.bas b/ModFunctions.bas index 75907e8..d2941b0 100644 --- a/ModFunctions.bas +++ b/ModFunctions.bas @@ -1,4 +1,42 @@ Attribute VB_Name = "ModFunctions" +'Functions in module: +'DateToUnixTime - retuns the UnixTime of a date/time +'UnixTimeToDate - returns the date/time of a UnixTime +'TransposeArr - Custom transpose function, worksheetfunction.transpose won't handle long strings +'URLEncode - especially for Excel 2013 and before, afterwards it's a standard function +'Source: https://github.com/krijnsent/crypto_vba +Sub TestFunctions() + +Debug.Print DateToUnixTime(#4/26/2017#) +'1493164800 +Debug.Print DateToUnixTime(Now) +'e.g. 1511958343 +Debug.Print UnixTimeToDate(1493164800) +'26-4-2017 +Debug.Print UnixTimeToDate(1511958343) +'29-11-2017 12:25:43 + +' Declare a two dimensional array +' Fill the array with text made up of i and j values +Dim TestArr(1 To 3, 1 To 2) As Variant +Dim i As Long, j As Long +For i = LBound(TestArr) To UBound(TestArr) + For j = LBound(TestArr, 2) To UBound(TestArr, 2) + TestArr(i, j) = CStr(i) & ":" & CStr(j) + Next j +Next i +FlipArr = TransposeArr(TestArr) +Debug.Print TestArr(1, 2) +Debug.Print FlipArr(2, 1) + + +Debug.Print URLEncode("http://www.github.com/") +'http%3A%2F%2Fwww.github.com%2F +Debug.Print URLEncode("https://github.com/search?q=crypto_vba&type=") +'https%3A%2F%2Fgithub.com%2Fsearch%3Fq%3Dcrypto_vba%26type%3D + +End Sub + Function DateToUnixTime(dt) As Long DateToUnixTime = DateDiff("s", "1/1/1970", dt) End Function diff --git a/ModHash.bas b/ModHash.bas index f0e1810..53f424c 100644 --- a/ModHash.bas +++ b/ModHash.bas @@ -52,7 +52,7 @@ Function ComputeHash_C(Meth As String, ByVal clearText As String, ByVal Key As S ElseIf Meth = "SHA256" Then Set SHAhasher = CreateObject("System.Security.Cryptography.SHA256Managed") ElseIf Meth = "SHA384" Then - Set SHAhasher = CreateObject("System.Security.Cryptography.SHA256Managed") + Set SHAhasher = CreateObject("System.Security.Cryptography.SHA384Managed") ElseIf Meth = "MD5" Then Set SHAhasher = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider") Else diff --git a/ModJSON.bas b/ModJSON.bas index 72d5787..77c0225 100644 --- a/ModJSON.bas +++ b/ModJSON.bas @@ -124,7 +124,6 @@ Next '4 -- 3 -- 1 -- 1924,41 -- VAL '4 -- 4 -- 1 -- 1924,41522 -- VAL - End Sub Sub TestArrayTable() @@ -182,16 +181,17 @@ Debug.Print Tbl(4, 4) '1924,41 'Sht.Range("B21").Resize(UBound(Tbl, 2), UBound(Tbl, 1)) = WorksheetFunction.Transpose(Tbl) - -'Poloniex deposit/withdrawal +'Poloniex deposit/withdrawal, no header output JsonResponse = "{""deposits"":[{""currency"":""BTC"",""address"":""DEP1"",""amount"":""0.01006132"",""confirmations"":10,""txid"":""17f819a91369a9ff6c4a34216d434597cfc1b4a3d0489b46bd6f924137a47701"",""timestamp"":1399305798,""status"":""COMPLETE""},{""currency"":""BTC"",""address"":""DEP2"",""amount"":""0.00404104"",""confirmations"":10,""txid"":""7acb90965b252e55a894b535ef0b0b65f45821f2899e4a379d3e43799604695c"",""timestamp"":1399245916,""status"":""COMPLETE""}],""withdrawals"":[{""withdrawalNumber"":134933,""currency"":""BTC"",""address"":""1N2i5n8DwTGzUq2Vmn9TUL8J1vdr1XBDFg"",""amount"":""5.00010000"", ""timestamp"":1399267904,""status"":""COMPLETE: 36e483efa6aff9fd53a235177579d98451c4eb237c210e66cd2b9a2d4a988f8e"",""ipAddress"":""IP192""}]}" Set Json = JsonConverter.ParseJson(JsonResponse) ResArr = JsonToArray(Json) Tbl = ArrayTable(ResArr, False) Debug.Print Tbl(1, 2) Debug.Print Tbl(4, 2) +'deposits +'DEP2 -'Remove last element +'Test no header reply JsonResponse = "{""error"":[],""result"":{""XXBTZEUR"":[[1492606800,""1121.990"",""1124.912"",""1119.680"",""1124.912"",""1122.345"",""352.76808800"",602],[1492610400,""1124.499"",""1124.980"",""1119.680"",""1122.000"",""1122.194"",""218.62127780"",713],[1492614000,""1121.311"",""1122.900"",""1120.501"",""1122.899"",""1122.266"",""445.46426003"",851],[1492617600,""1122.894"",""1124.499"",""1120.710"",""1123.291"",""1123.068"",""253.55336370"",860],[1492621200,""1124.406"",""1126.000"",""1123.017"",""1125.990"",""1124.775"",""234.27612705"",918],[1492624800,""1125.610"",""1126.231"",""1123.010"",""1126.229"",""1125.453"",""243.42246123"",772]],""last"":1495191600}}" Set Json = JsonConverter.ParseJson(JsonResponse) Set JsonRes = Json("result") @@ -199,7 +199,28 @@ ResArr = JsonToArray(Json) Tbl = ArrayTable(ResArr, False) Debug.Print Tbl(1, 2) Debug.Print Tbl(4, 4) +'result +'1492617600 +'Empty data set returned 1 +JsonResponse = "{""success"":true,""message"":"""",""result"":[]}" +Set Json = JsonConverter.ParseJson(JsonResponse) +ResArr = JsonToArray(Json) +Tbl = ArrayTable(ResArr, True) +Debug.Print Tbl(1, 2) +Debug.Print Tbl(3, 2) +'Waar +'0 + +'Empty data set returned 2 +JsonResponse = "{""success"":false,""message"":""APISIGN_NOT_PROVIDED"",""result"":null}" +Set Json = JsonConverter.ParseJson(JsonResponse) +ResArr = JsonToArray(Json) +Tbl = ArrayTable(ResArr, True) +Debug.Print Tbl(1, 2) +Debug.Print Tbl(2, 2) +'Onwaar +'APISIGN_NOT_PROVIDED End Sub @@ -367,7 +388,8 @@ For rw = LBound(ArrIn, 2) To UBound(ArrIn, 2) Lvl = Val(ArrIn(1, rw)) If Lvl < MaxD And Lvl > 0 Then TblHeaders.Add "GROUP_" & Lvl, "GROUP_" & Lvl - ElseIf Lvl = MaxD And ArrIn(5, rw) = "VAL" Then + 'ElseIf Lvl = MaxD And ArrIn(5, rw) = "VAL" Then + ElseIf Lvl = MaxD Then If Val(ArrIn(3, rw)) > 0 Then TblHeaders.Add "VAL_" & ArrIn(3, rw), "VAL_" & ArrIn(3, rw) Else diff --git a/ModWeb.bas b/ModWeb.bas new file mode 100644 index 0000000..a393bcf --- /dev/null +++ b/ModWeb.bas @@ -0,0 +1,108 @@ +Attribute VB_Name = "ModWeb" +'Source: https://github.com/krijnsent/crypto_vba +'Remember to create a new API key for excel/VBA +'Based on http://www.808.dk/?code-simplewinhttprequest + +Sub TestGetData() + +'Testing error catching and replies +Debug.Print GetDataFromURL("myURL", "myMethod") +'{"error_nr":27,"error_txt":"invalid method for GetDataFromURL"} +Debug.Print GetDataFromURL("myURL", "GET") +'{"error_nr":-2147012796,"error_txt":"VBA-WinHttp.WinHttpRequest etc. +Debug.Print GetDataFromURL("https://github.com/empty_url_not_there", "GET") +'{"error_nr":404,"error_txt":"HTTP-Not Found"} + +Debug.Print GetDataFromURL("https://api.kraken.com/0/public/Time", "GET") +'{"error":[],"result":{"unixtime":1511954132,"rfc1123":"Wed, 29 Nov 17 11:15:32 +0000"}} + +End Sub + +Function GetDataFromURL(strURL As String, strMethod As String, Optional strPostData As String) As String + +' Instantiate a WinHttpRequest object and open it +ErrResp = "{""error_nr"":ERR_NR,""error_txt"":""ERR_TXT""}" +Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") +If strMethod = "GET" Then + On Error Resume Next + objHTTP.Open "GET", strURL + objHTTP.Send + If Err.Number = 0 Then + If objHTTP.Status = "200" Then + objHTTP.WaitForResponse + GetDataFromURL = objHTTP.ResponseText + Else + GetDataFromURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText) + End If + Else + 'Unknown error, probably no internet connection, answer in JSON + GetDataFromURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description) + End If + On Error GoTo 0 +ElseIf strMethod = "POST" Then +' Not implemented, work in progress +' objHTTP.Open "POST", Url, False +' objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" +' objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" +' objHTTP.setRequestHeader "Key", apikey +' objHTTP.setRequestHeader "Sign", APIsign +' objHTTP.Send (postdata) +Else + GetDataFromURL = Replace(Replace(ErrResp, "ERR_NR", 27), "ERR_TXT", "invalid method for GetDataFromURL") +End If +Set objHTTP = Nothing + +End Function + +Function GetDataFromURL_COPY_PASTED(strURL, strMethod, strPostData) + Dim lngTimeout + Dim strUserAgentString + Dim intSslErrorIgnoreFlags + Dim blnEnableRedirects + Dim blnEnableHttpsToHttpRedirects + Dim strHostOverride + Dim strLogin + Dim strPassword + Dim strResponseText + Dim objWinHttp + lngTimeout = 59000 + strUserAgentString = "http_requester/0.1" + intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err + blnEnableRedirects = True + blnEnableHttpsToHttpRedirects = True + strHostOverride = "" + strLogin = "" + strPassword = "" + Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") + objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout + objWinHttp.Open strMethod, strURL + If strMethod = "POST" Then + objWinHttp.setRequestHeader "Content-type", _ + "application/x-www-form-urlencoded" + End If + If strHostOverride <> "" Then + objWinHttp.setRequestHeader "Host", strHostOverride + End If + objWinHttp.Option(0) = strUserAgentString + objWinHttp.Option(4) = intSslErrorIgnoreFlags + objWinHttp.Option(6) = blnEnableRedirects + objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects + If (strLogin <> "") And (strPassword <> "") Then + objWinHttp.SetCredentials strLogin, strPassword, 0 + End If + On Error Resume Next + objWinHttp.Send (strPostData) + If Err.Number = 0 Then + If objWinHttp.Status = "200" Then + GetDataFromURL = objWinHttp.ResponseText + Else + GetDataFromURL = "HTTP " & objWinHttp.Status & " " & _ + objWinHttp.StatusText + End If + Else + GetDataFromURL = "Error " & Err.Number & " " & Err.Source & " " & _ + Err.Description + End If + On Error GoTo 0 + Set objWinHttp = Nothing +End Function diff --git a/crypto_vba_example.xlsm b/crypto_vba_example.xlsm index d74b933..a7f7381 100644 Binary files a/crypto_vba_example.xlsm and b/crypto_vba_example.xlsm differ