-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
53 lines (46 loc) · 1.11 KB
/
helpers.php
File metadata and controls
53 lines (46 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
if (!function_exists("getQuery")) {
function getQuery($data)
{
return http_build_query($data, "", "&");
}
}
if (!function_exists("getTimestamp")) {
function getTimestamp()
{
return round(microtime(true) * 1000);
}
}
if (!function_exists("getSignature")) {
function getSignature($data)
{
$data = getQuery($data);
return hash_hmac("sha256", $data, BINANCE_API_SECRET);
}
}
if (!function_exists("toJson")) {
function toJson($data)
{
return json_decode((string) $data->getBody());
}
}
if (!function_exists("toCurrency")) {
function toCurrency($value, $locale = "en-US", $maxFractionDigits = 4)
{
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
$formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $maxFractionDigits);
return $formatter->format($value);
}
}
if (!function_exists("toPercent")) {
function toPercent($value, $maxFractionDigits = 4)
{
return number_format(abs($value), $maxFractionDigits);
}
}
if (!function_exists("isNegative")) {
function isNegative($value)
{
return preg_match("/-/", $value);
}
}