Skip to content

Commit

Permalink
Fix getCandles operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Artiom Misiru authored and Artiom Misiru committed Jan 2, 2025
1 parent e386b02 commit 6d8385f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Release Notes

## [6.2.0](https://github.com/timirey/xapi-php/compare/6.0.4..6.0.5) - 2024-12-27
## [6.2.1](https://github.com/timirey/xapi-php/compare/6.2.0..6.2.1) - 2025-01-02

- Add fix for `FetchCandles`.

## [6.2.0](https://github.com/timirey/xapi-php/compare/6.1.0..6.2.0) - 2024-12-27

- Add new `QuoteId` and `MarginMode`.

## [6.1.0](https://github.com/timirey/xapi-php/compare/6.0.4..6.0.5) - 2024-12-27
## [6.1.0](https://github.com/timirey/xapi-php/compare/6.0.5..6.1.0) - 2024-12-27

- Remove timeout for stream connection.

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ $client->fetchBalance(
Subscribes for and unsubscribes from API chart candles. The interval of every candle is 1 minute. A new candle arrives
every minute.

#### Existing issue
The **getCandles** API operation is unstable, often failing to subscribe immediately to the desired symbol.

#### Workaround
The package currently requests the symbol's history before subscribing. See [fetchCandles](https://github.com/timirey/xapi-php/blob/e386b023429c19b0a2700300acc02ed7e211a3aa/src/Client.php#L590) method.

```PHP
use Timirey\XApi\Responses\Data\CandleStreamRecord;
use Timirey\XApi\Responses\FetchCandlesResponse;
Expand Down
13 changes: 12 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Timirey\XApi\Enums\Cmd;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Enums\Level;
use Timirey\XApi\Enums\Period;
use Timirey\XApi\Exceptions\ErrorResponseException;
use Timirey\XApi\Exceptions\InvalidPayloadException;
use Timirey\XApi\Exceptions\InvalidResponseException;
Expand Down Expand Up @@ -574,7 +575,9 @@ final public function fetchBalance(callable $callback): void
}

/**
* Subscribe to candles stream.
* Subscribe to candles stream. This operation is not stable.
*
* @see https://github.com/timirey/xapi-php/compare/6.2.0...6.2.1
*
* @param string $symbol Symbol for which to get the candles.
* @param callable $callback Callback function to handle the response.
Expand All @@ -589,6 +592,14 @@ final public function fetchBalance(callable $callback): void
*/
final public function fetchCandles(string $symbol, callable $callback): void
{
$chartLastInfoRecord = new ChartLastInfoRecord(
period: Period::PERIOD_M1,
start: new DateTime(),
symbol: $symbol,
);

$this->getChartLastRequest($chartLastInfoRecord);

$this->subscribe(
new FetchCandlesPayload($this->streamSessionId, $symbol),
FetchCandlesResponse::class,
Expand Down

0 comments on commit 6d8385f

Please sign in to comment.