Skip to content

Commit

Permalink
Add more enums and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timirey committed Jul 1, 2024
1 parent 01f3057 commit ae6f5a2
Show file tree
Hide file tree
Showing 30 changed files with 277 additions and 74 deletions.
12 changes: 7 additions & 5 deletions src/Connections/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Timirey\XApi\Connections;

use Timirey\XApi\Enums\Host;
use Timirey\XApi\Connections\Enums\Host;
use Timirey\XApi\Payloads\AbstractPayload;
use Timirey\XApi\Payloads\Data\ChartLastInfoRecord;
use Timirey\XApi\Payloads\Data\ChartRangeInfoRecord;
use Timirey\XApi\Payloads\Data\TradeTransInfo;
use Timirey\XApi\Payloads\Enums\Cmd;
use Timirey\XApi\Payloads\Enums\Level;
use Timirey\XApi\Payloads\GetAllSymbolsPayload;
use Timirey\XApi\Payloads\GetCalendarPayload;
use Timirey\XApi\Payloads\GetChartLastRequestPayload;
Expand Down Expand Up @@ -278,15 +280,15 @@ public function getIbsHistory(int $start, int $end): GetIbsHistoryResponse
* Calculates estimated profit for given deal data.
*
* @param float $closePrice
* @param int $cmd
* @param Cmd $cmd
* @param float $openPrice
* @param string $symbol
* @param float $volume
* @return GetProfitCalculationResponse
*/
public function getProfitCalculation(
float $closePrice,
int $cmd,
Cmd $cmd,
float $openPrice,
string $symbol,
float $volume
Expand Down Expand Up @@ -320,12 +322,12 @@ public function getStepRules(): GetStepRulesResponse
/**
* Returns array of current quotations for given symbols.
*
* @param int $level
* @param Level $level
* @param array $symbols
* @param int $timestamp
* @return GetTickPricesResponse
*/
public function getTickPrices(int $level, array $symbols, int $timestamp): GetTickPricesResponse
public function getTickPrices(Level $level, array $symbols, int $timestamp): GetTickPricesResponse
{
return $this->sendRequest(
new GetTickPricesPayload($level, $symbols, $timestamp),
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Host.php → src/Connections/Enums/Host.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Timirey\XApi\Enums;
namespace Timirey\XApi\Connections\Enums;

/**
* Enum representing the WebSocket host URLs for xStation5 API.
Expand Down
12 changes: 3 additions & 9 deletions src/Payloads/Data/ChartLastInfoRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Payloads\Data;

use Timirey\XApi\Enums\Period;
use Timirey\XApi\Payloads\Enums\Period;

/**
* Class representing the last chart information record.
Expand All @@ -12,20 +12,14 @@
*/
class ChartLastInfoRecord
{
/**
* Period code.
*/
public Period $period;

/**
* Constructor for ChartLastInfoRecord.
*
* @param int $period Period code.
* @param Period $period Period code.
* @param int $start Start of chart block.
* @param string $symbol Symbol.
*/
public function __construct(int $period, public int $start, public string $symbol)
public function __construct(public Period $period, public int $start, public string $symbol)
{
$this->period = Period::from($period);
}
}
12 changes: 3 additions & 9 deletions src/Payloads/Data/ChartRangeInfoRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Payloads\Data;

use Timirey\XApi\Enums\Period;
use Timirey\XApi\Payloads\Enums\Period;

/**
* Class representing the range chart information record.
Expand All @@ -11,27 +11,21 @@
*/
class ChartRangeInfoRecord
{
/**
* @var Period Period code.
*/
public Period $period;

/**
* Constructor for ChartRangeInfoRecord.
*
* @param int $period Period code.
* @param Period $period Period code.
* @param int $start Start of chart block (milliseconds since epoch).
* @param int $end End of chart block (milliseconds since epoch).
* @param string $symbol Symbol.
* @param int|null $ticks Number of ticks needed (optional).
*/
public function __construct(
int $period,
public Period $period,
public int $start,
public int $end,
public string $symbol,
public ?int $ticks = null
) {
$this->period = Period::from($period);
}
}
11 changes: 7 additions & 4 deletions src/Payloads/Data/TradeTransInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Timirey\XApi\Payloads\Data;

use Timirey\XApi\Payloads\Enums\Cmd;
use Timirey\XApi\Payloads\Enums\Type;

/**
* Class representing trade transaction information.
*
Expand All @@ -13,7 +16,7 @@ class TradeTransInfo
/**
* Constructor for TradeTransInfo.
*
* @param int $cmd Operation code.
* @param Cmd $cmd Operation code.
* @param string|null $customComment The value the customer may provide in order to retrieve it later.
* @param int $expiration Pending order expiration time.
* @param int $offset Trailing offset.
Expand All @@ -22,11 +25,11 @@ class TradeTransInfo
* @param float $sl Stop loss.
* @param string $symbol Trade symbol.
* @param float $tp Take profit.
* @param int $type Trade transaction type.
* @param Type $type Trade transaction type.
* @param float $volume Trade volume.
*/
public function __construct(
public int $cmd,
public Cmd $cmd,
public ?string $customComment,
public int $expiration,
public int $offset,
Expand All @@ -35,7 +38,7 @@ public function __construct(
public float $sl,
public string $symbol,
public float $tp,
public int $type,
public Type $type,
public float $volume
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Cmd.php → src/Payloads/Enums/Cmd.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Timirey\XApi\Enums;
namespace Timirey\XApi\Payloads\Enums;

/**
* Enum representing the command type for a trade.
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Level.php → src/Payloads/Enums/Level.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Timirey\XApi\Enums;
namespace Timirey\XApi\Payloads\Enums;

/**
* Enum representing the price level.
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Period.php → src/Payloads/Enums/Period.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Timirey\XApi\Enums;
namespace Timirey\XApi\Payloads\Enums;

/**
* Enum representing the period.
Expand Down
34 changes: 34 additions & 0 deletions src/Payloads/Enums/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Timirey\XApi\Payloads\Enums;

/**
* Enum representing the order type.
*/
enum Type: int
{
/**
* Order open, used for opening orders.
*/
case OPEN = 0;

/**
* Order pending, only used in the streaming getTrades command.
*/
case PENDING = 1;

/**
* Order close.
*/
case CLOSE = 2;

/**
* Order modify, only used in the tradeTransaction command.
*/
case MODIFY = 3;

/**
* Order delete, only used in the tradeTransaction command.
*/
case DELETE = 4;
}
8 changes: 4 additions & 4 deletions src/Payloads/GetProfitCalculationPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Payloads;

use Timirey\XApi\Enums\Cmd;
use Timirey\XApi\Payloads\Enums\Cmd;

/**
* Class that contains payload for the getProfitCalculation command.
Expand All @@ -13,15 +13,15 @@ class GetProfitCalculationPayload extends AbstractPayload
* Constructor for GetProfitCalculationPayload.
*
* @param float $closePrice Theoretical close price of order.
* @param int $cmd Operation code.
* @param Cmd $cmd Operation code.
* @param float $openPrice Theoretical open price of order.
* @param string $symbol Symbol.
* @param float $volume Volume.
*/
public function __construct(float $closePrice, int $cmd, float $openPrice, string $symbol, float $volume)
public function __construct(float $closePrice, Cmd $cmd, float $openPrice, string $symbol, float $volume)
{
$this->arguments['closePrice'] = $closePrice;
$this->arguments['cmd'] = Cmd::from($cmd);
$this->arguments['cmd'] = $cmd->value;
$this->arguments['openPrice'] = $openPrice;
$this->arguments['symbol'] = $symbol;
$this->arguments['volume'] = $volume;
Expand Down
8 changes: 4 additions & 4 deletions src/Payloads/GetTickPricesPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Payloads;

use Timirey\XApi\Enums\Level;
use Timirey\XApi\Payloads\Enums\Level;

/**
* Class that contains payload for the getTickPrices command.
Expand All @@ -12,13 +12,13 @@ class GetTickPricesPayload extends AbstractPayload
/**
* Constructor for GetTickPricesPayload.
*
* @param int $level Price level.
* @param Level $level Price level.
* @param array $symbols Array of symbol names.
* @param int $timestamp The time from which the most recent tick should be looked for.
*/
public function __construct(int $level, array $symbols, int $timestamp)
public function __construct(Level $level, array $symbols, int $timestamp)
{
$this->arguments['level'] = Level::from($level);
$this->arguments['level'] = $level->value;
$this->arguments['symbols'] = $symbols;
$this->arguments['timestamp'] = $timestamp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Data/CalendarRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\Impact;
use Timirey\XApi\Responses\Enums\Impact;

/**
* Class representing a calendar record.
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Data/IbRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\Side;
use Timirey\XApi\Responses\Enums\Side;

/**
* Class representing an IB record.
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Data/QuotesRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\Day;
use Timirey\XApi\Responses\Enums\Day;

/**
* Class representing a quotes record.
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Data/SymbolRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\MarginMode;
use Timirey\XApi\Enums\ProfitMode;
use Timirey\XApi\Enums\QuoteId;
use Timirey\XApi\Responses\Enums\MarginMode;
use Timirey\XApi\Responses\Enums\ProfitMode;
use Timirey\XApi\Responses\Enums\QuoteId;

/**
* Class representing a symbol record.
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Data/TickRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\Level;
use Timirey\XApi\Responses\Enums\Level;

/**
* Class representing a tick record.
Expand Down
3 changes: 1 addition & 2 deletions src/Responses/Data/TradeRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Enums\Cmd;
use Timirey\XApi\Enums\Level;
use Timirey\XApi\Responses\Enums\Cmd;

/**
* Class representing a trade record.
Expand Down
10 changes: 9 additions & 1 deletion src/Responses/Data/TradingRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

namespace Timirey\XApi\Responses\Data;

use Timirey\XApi\Responses\Enums\Day;

/**
* Class representing a trading record.
*/
class TradingRecord
{
/**
* @var Day Day of week.
*/
public Day $day;

/**
* Constructor for TradingRecord.
*
* @param int $day Day of week.
* @param int $fromT Start time in ms from 00:00 CET / CEST time zone.
* @param int $toT End time in ms from 00:00 CET / CEST time zone.
*/
public function __construct(public int $day, public int $fromT, public int $toT)
public function __construct(int $day, public int $fromT, public int $toT)
{
$this->day = Day::from($day);
}
}
Loading

0 comments on commit ae6f5a2

Please sign in to comment.