Skip to content

Commit

Permalink
Merge pull request #3 from timirey/feature/refactor-with-enum
Browse files Browse the repository at this point in the history
Feature/refactor with enum
  • Loading branch information
timirey authored Jul 1, 2024
2 parents 45af08c + e1353c8 commit 8adcb7e
Show file tree
Hide file tree
Showing 28 changed files with 502 additions and 65 deletions.
18 changes: 9 additions & 9 deletions src/Connections/Client.php → src/Client.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

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

use Timirey\XApi\Connections\Enums\Host;
use Timirey\XApi\Enums\Cmd;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Enums\Level;
use Timirey\XApi\Payloads\AbstractPayload;
use Timirey\XApi\Payloads\Data\ChartLastInfoRecord;
use Timirey\XApi\Payloads\Data\ChartRangeInfoRecord;
Expand Down Expand Up @@ -62,8 +64,6 @@

/**
* Client class for interacting with the xStation5 API.
*
* todo: rename this class and think of better folder structure.
*/
class Client
{
Expand Down Expand Up @@ -278,15 +278,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 +320,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 Expand Up @@ -395,7 +395,7 @@ public function getVersion(): GetVersionResponse
* @param AbstractPayload $payload The payload to send.
* @param class-string<T> $responseClass The response class to instantiate.
* @return AbstractResponse The response instance.
* @return T
* @return AbstractResponse
*/
protected function sendRequest(AbstractPayload $payload, string $responseClass): AbstractResponse
{
Expand Down
49 changes: 49 additions & 0 deletions src/Enums/Cmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the command type for a trade.
*/
enum Cmd: int
{
/**
* Buy command.
*/
case BUY = 0;

/**
* Sell command.
*/
case SELL = 1;

/**
* Buy limit order.
*/
case BUY_LIMIT = 2;

/**
* Sell limit order.
*/
case SELL_LIMIT = 3;

/**
* Buy stop order.
*/
case BUY_STOP = 4;

/**
* Sell stop order.
*/
case SELL_STOP = 5;

/**
* Balance operation (read only).
*/
case BALANCE = 6;

/**
* Credit operation (read only).
*/
case CREDIT = 7;
}
44 changes: 44 additions & 0 deletions src/Enums/Day.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the day of the week.
*/
enum Day: int
{
/**
* Monday.
*/
case MONDAY = 1;

/**
* Tuesday.
*/
case TUESDAY = 2;

/**
* Wednesday.
*/
case WEDNESDAY = 3;

/**
* Thursday.
*/
case THURSDAY = 4;

/**
* Friday.
*/
case FRIDAY = 5;

/**
* Saturday.
*/
case SATURDAY = 6;

/**
* Sunday.
*/
case SUNDAY = 7;
}
2 changes: 1 addition & 1 deletion src/Connections/Enums/Host.php → src/Enums/Host.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

/**
* Enum representing the WebSocket host URLs for xStation5 API.
Expand Down
24 changes: 24 additions & 0 deletions src/Enums/Impact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the impact level.
*/
enum Impact: string
{
/**
* Low impact.
*/
case LOW = "1";

/**
* Medium impact.
*/
case MEDIUM = "2";

/**
* High impact.
*/
case HIGH = "3";
}
24 changes: 24 additions & 0 deletions src/Enums/Level.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the price level.
*/
enum Level: int
{
/**
* All available levels.
*/
case ALL = -1;

/**
* Base level bid and ask price for instrument.
*/
case BASE = 0;

/**
* Specified level.
*/
case SPECIFIED = 1;
}
24 changes: 24 additions & 0 deletions src/Enums/MarginMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the margin mode.
*/
enum MarginMode: int
{
/**
* Forex.
*/
case FOREX = 101;

/**
* CFD leveraged.
*/
case CFD_LEVERAGED = 102;

/**
* CFD.
*/
case CFD = 103;
}
54 changes: 54 additions & 0 deletions src/Enums/Period.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the period.
*/
enum Period: int
{
/**
* 1 minute.
*/
case PERIOD_M1 = 1;

/**
* 5 minutes.
*/
case PERIOD_M5 = 5;

/**
* 15 minutes.
*/
case PERIOD_M15 = 15;

/**
* 30 minutes.
*/
case PERIOD_M30 = 30;

/**
* 60 minutes (1 hour).
*/
case PERIOD_H1 = 60;

/**
* 240 minutes (4 hours).
*/
case PERIOD_H4 = 240;

/**
* 1440 minutes (1 day).
*/
case PERIOD_D1 = 1440;

/**
* 10080 minutes (1 week).
*/
case PERIOD_W1 = 10080;

/**
* 43200 minutes (30 days).
*/
case PERIOD_MN1 = 43200;
}
19 changes: 19 additions & 0 deletions src/Enums/ProfitMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the profit mode.
*/
enum ProfitMode: int
{
/**
* FOREX.
*/
case FOREX = 5;

/**
* CFD.
*/
case CFD = 6;
}
29 changes: 29 additions & 0 deletions src/Enums/QuoteId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the source of price.
*/
enum QuoteId: int
{
/**
* Fixed source.
*/
case FIXED = 1;

/**
* Float source.
*/
case FLOAT = 2;

/**
* Depth source.
*/
case DEPTH = 3;

/**
* Cross source.
*/
case CROSS = 4;
}
29 changes: 29 additions & 0 deletions src/Enums/RequestStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the request status.
*/
enum RequestStatus: int
{
/**
* Error status.
*/
case ERROR = 0;

/**
* Pending status.
*/
case PENDING = 1;

/**
* Accepted status. The transaction has been executed successfully.
*/
case ACCEPTED = 3;

/**
* Rejected status. The transaction has been rejected.
*/
case REJECTED = 4;
}
19 changes: 19 additions & 0 deletions src/Enums/Side.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Timirey\XApi\Enums;

/**
* Enum representing the side of a trade.
*/
enum Side: int
{
/**
* Buy side.
*/
case BUY = 0;

/**
* Sell side.
*/
case SELL = 1;
}
Loading

0 comments on commit 8adcb7e

Please sign in to comment.