Skip to content

Commit

Permalink
[Automated changes] PHP files
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 24, 2025
1 parent 0c7d23e commit 0a98b9c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions php/Exchange.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions php/async/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,12 @@ public function is_round_number(float $value) {
return $res === 0;
}

public function safe_number_omit_zero(array $obj, int|string $key, ?float $defaultValue = null) {
$value = $this->safe_string($obj, $key);
$final = $this->parse_number($this->omit_zero($value));
return ($final === null) ? $defaultValue : $final;
}

public function safe_integer_omit_zero(array $obj, int|string $key, ?int $defaultValue = null) {
$timestamp = $this->safe_integer($obj, $key, $defaultValue);
if ($timestamp === null || $timestamp === 0) {
Expand Down
3 changes: 1 addition & 2 deletions php/async/binance.php
Original file line number Diff line number Diff line change
Expand Up @@ -4500,12 +4500,11 @@ public function parse_last_price($entry, ?array $market = null) {
$type = ($timestamp === null) ? 'spot' : 'swap';
$marketId = $this->safe_string($entry, 'symbol');
$market = $this->safe_market($marketId, $market, null, $type);
$price = $this->safe_number($entry, 'price');
return array(
'symbol' => $market['symbol'],
'timestamp' => $timestamp,
'datetime' => $this->iso8601($timestamp),
'price' => $price,
'price' => $this->safe_number_omit_zero($entry, 'price'),
'side' => null,
'info' => $entry,
);
Expand Down
3 changes: 1 addition & 2 deletions php/binance.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions php/test/base/test_safe_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function test_safe_methods() {
),
'str' => 'heLlo',
'strNumber' => '3',
'zeroNumeric' => 0,
'zeroString' => '0',
'undefined' => null,
'emptyString' => '',
'floatNumeric' => 0.123,
'floatString' => '0.123',
);
$input_list = ['Hi', 2];
$compare_dict = array(
Expand Down Expand Up @@ -248,4 +254,11 @@ function test_safe_methods() {
// safeBoolN
assert($exchange->safe_bool_n($input_dict, ['a', 'b', 'bool']) === true);
assert($exchange->safe_bool_n($input_list, [3, 2, 1]) === null);
// safeNumberOmitZero
assert($exchange->safe_number_omit_zero($input_dict, 'zeroNumeric') === null);
assert($exchange->safe_number_omit_zero($input_dict, 'zeroString') === null);
assert($exchange->safe_number_omit_zero($input_dict, 'undefined') === null);
assert($exchange->safe_number_omit_zero($input_dict, 'emptyString') === null);
assert($exchange->safe_number_omit_zero($input_dict, 'floatNumeric') !== null);
assert($exchange->safe_number_omit_zero($input_dict, 'floatString') !== null);
}
3 changes: 3 additions & 0 deletions php/test/exchange/async/test_fetch_last_prices.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ function test_fetch_last_prices($exchange, $skipped_properties, $symbol) {
assert(is_array($response), $exchange->id . ' ' . $method . ' ' . $checked_symbol . ' must return an object. ' . $exchange->json($response));
$values = is_array($response) ? array_values($response) : array();
assert_non_emtpy_array($exchange, $skipped_properties, $method, $values, $checked_symbol);
$at_least_one_passed = false;
for ($i = 0; $i < count($values); $i++) {
// todo: symbol check here
test_last_price($exchange, $skipped_properties, $method, $values[$i], $checked_symbol);
$at_least_one_passed = $at_least_one_passed || ($exchange->safe_number($values[$i], 'price') > 0);
}
assert($at_least_one_passed, $exchange->id . ' ' . $method . ' ' . $checked_symbol . ' at least one symbol should pass the test');
}) ();
}
2 changes: 1 addition & 1 deletion php/test/exchange/base/test_last_price.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function test_last_price($exchange, $skipped_properties, $method, $entry, $symbo
'price' => $exchange->parse_number('1.234'),
'side' => 'buy',
);
$empty_allowed_for = ['timestamp', 'datetime', 'side'];
$empty_allowed_for = ['timestamp', 'datetime', 'side', 'price']; // binance sometimes provides empty prices for old pairs
assert_structure($exchange, $skipped_properties, $method, $entry, $format, $empty_allowed_for);
assert_timestamp_and_datetime($exchange, $skipped_properties, $method, $entry);
//
Expand Down
3 changes: 3 additions & 0 deletions php/test/exchange/sync/test_fetch_last_prices.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ function test_fetch_last_prices($exchange, $skipped_properties, $symbol) {
assert(is_array($response), $exchange->id . ' ' . $method . ' ' . $checked_symbol . ' must return an object. ' . $exchange->json($response));
$values = is_array($response) ? array_values($response) : array();
assert_non_emtpy_array($exchange, $skipped_properties, $method, $values, $checked_symbol);
$at_least_one_passed = false;
for ($i = 0; $i < count($values); $i++) {
// todo: symbol check here
test_last_price($exchange, $skipped_properties, $method, $values[$i], $checked_symbol);
$at_least_one_passed = $at_least_one_passed || ($exchange->safe_number($values[$i], 'price') > 0);
}
assert($at_least_one_passed, $exchange->id . ' ' . $method . ' ' . $checked_symbol . ' at least one symbol should pass the test');
}

0 comments on commit 0a98b9c

Please sign in to comment.