Search the Community
Showing results for tags 'epoch'.
-
Here is helper function for working with bitstamp api. Its actually two functions but one is just to set your keys. It will handle the authentication and should be able to handle any of the other private functions available that use POST. The public GET functions dont require authentication so you dont need this for those. Those could simply use InetRead. I have included some examples that include showing how to use the currency pairs and request parameters so I think how to use all the rest of the api functions should be easy to understand. I found some new short and sweet Epoch \ Unix timestamp functions along the way too that I dont think anyone has posted yet and will just post below for easy copy/paste. Both are standalone and utilize magic number 11644473600. Credits to ward. This uses his curl udf which is a tad bit out of of date and requires the SSL verification to be disabled. Its not that big of a deal since your data is still encrypted, but obviously not preferred so just fyi. Be sure to keep an eye on the halving coming up soon (https://www.bitcoinblockhalf.com) I expect to see a lot of fluctuations and its easy to gain a good amount of bitcoin when the prices fall and rise as much as they do. If you have good luck and these functions helped you - feel free to donate to 1DwAsJ9hNNSwDXSiYyD9EkppuVgcBQMC8q https://www.bitstamp.net/api/ Bitstamp Example: #include <bitstamp.au3> ;Set your secret and api keys _BitstampAU3_SetKeys(" Your secret/private key goes here ", " Your API Key goes here ") ; ;Example getting Balance $json = _BitstampAU3("balance") ConsoleWrite($json & @CRLF) Json_Dump($json) ;Example getting Balance with currency_pair $json = _BitstampAU3("balance/btcusd") ConsoleWrite($json & @CRLF) Json_Dump($json) ;Example getting user_transactions with 3 request parameters $json = _BitstampAU3("user_transactions", "sort=asc&offset=2&limit=5") ConsoleWrite($json & @CRLF) Json_Dump($json) Unix Time Functions: ConsoleWrite(_UnixTime() & @CRLF) ConsoleWrite(_UnixTimeToLocal(_UnixTime()) & @CRLF) ; #FUNCTION# ==================================================================================================================== ; Description ...: Calculates number of seconds/milliseconds that have elapsed since the Unix epoch ; Parameters ....: $bMS - [optional] Set true to return timestamp as milliseconds ; Return values .: UTC/Epoch/Unix timestamp ; Author ........: Brian J Christy (Beege) ; Remarks .......: SystemTimeAsFileTime = number of 100-nanosecond intervals since January 1, 1601 ; 11644473600 = number of seconds between 1/1/1601 - 1/1/1970 ; unixtime = (seconds since January 1, 1601) - 11644473600 ; =============================================================================================================================== Func _UnixTime($bMS = False) Local $iUTC = (DllCall('kernel32.dll', 'none', 'GetSystemTimeAsFileTime', 'uint64*', 0)[1] / 10000000) - 11644473600 Return $bMS ? Floor($iUTC * 1000) : Floor($iUTC) EndFunc ;==>_UnixTime Func _UnixTimeToLocal($iUnixTime) Local $tSys = DllCall("kernel32.dll", "bool", "FileTimeToSystemTime", "uint64*", (($iUnixTime + 11644473600) * 10000000), "struct*", DllStructCreate("word[8]"))[2] Local $tLT = DllCall("kernel32.dll", "bool", "SystemTimeToTzSpecificLocalTime", "ptr", Null, "struct*", $tSys, "struct*", DllStructCreate("word tm[8]"))[3] Return StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $tLT.tm(2), $tLT.tm(4), $tLT.tm(1), $tLT.tm(5), $tLT.tm(6), $tLT.tm(7)) EndFunc ;==>_UnixTimeLocal Bitstamp.zip
-
After Several Minutes searching the forums for a simple solution to calculating for the Unix Time, as required for another project I am working on, I was astonished to not find one clean and universal solution. After looking over the helpfile, I noticed one simple solution given in the example with _DateDiff(). However it did not account for my current timezone or daylight savings time. Without further ado... This is my example of Calculating for a current Unix Time stamp or seconds since Jan, 1st, 1970 00:00:00 GMT. This function will account for your timezone as well as for daylight savings time. Update: v0.3 -Added Function to revert a Unix Time stamp into Date form. -Added parameter to original _GetUnixTime() allowing for a custom date since Jan 1st 1970 to be passed and converted to Unix Time. #include <Date.au3> #include <Array.au3> #include <Constants.au3> Local $iUnixTime1 = _GetUnixTime() MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds Since Jan, 1st, 1970 00:00:00 GMT" & @CRLF & $iUnixTime1) Local $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp in Local Time" & @CRLF & $sUnixDate1) $sUnixDate1 = _GetDate_fromUnixTime($iUnixTime1, False) MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Get Date from Unix Timestamp with $iReturnLocal = False which returns UTC Time" & @CRLF & $sUnixDate1) Local $iUnixTime2 = _GetUnixTime('2013/01/01 00:00:00') MsgBox($MB_SYSTEMMODAL, "Unix Timestamp", "Seconds since 2013/01/01 00:00:00" & @CRLF & $iUnixTime2) ; Get timestamp for input datetime (or current datetime). Func _GetUnixTime($sDate = 0);Date Format: 2013/01/01 00:00:00 ~ Year/Mo/Da Hr:Mi:Se Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $utcTime = "" If Not $sDate Then $sDate = _NowCalc() If Int(StringLeft($sDate, 4)) < 1970 Then Return "" If $aSysTimeInfo[0] = 2 Then ; if daylight saving time is active $utcTime = _DateAdd('n', $aSysTimeInfo[1] + $aSysTimeInfo[7], $sDate) ; account for time zone and daylight saving time Else $utcTime = _DateAdd('n', $aSysTimeInfo[1], $sDate) ; account for time zone EndIf Return _DateDiff('s', "1970/01/01 00:00:00", $utcTime) EndFunc ;==>_GetUnixTime ;$blTrim: Year in short format and no seconds. Func _GetDate_fromUnixTime($iUnixTime, $iReturnLocal = True) Local $aRet = 0, $aDate = 0 Local $aMonthNumberAbbrev[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] Local $timeAdj = 0 If Not $iReturnLocal Then Local $aSysTimeInfo = _Date_Time_GetTimeZoneInformation() Local $timeAdj = $aSysTimeInfo[1] * 60 If $aSysTimeInfo[0] = 2 Then $timeAdj += $aSysTimeInfo[7] * 60 EndIf $aRet = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $iUnixTime + $timeAdj ) If @error Or Not $aRet[0] Then Return "" $aDate = StringSplit(StringTrimRight($aRet[0], 1), " ", 2) Return $aDate[4] & "/" & StringFormat("%.2d", _ArraySearch($aMonthNumberAbbrev, $aDate[1])) & "/" & $aDate[2] & " " & $aDate[3] EndFunc ;==>_GetUnixDate Enjoy! Realm Update: >Added some functionality and a suggestion from FireFox