Skip to content

Commit a7fb424

Browse files
authored
Merge pull request #15 from MarketDataApp/add-comments-for-php-doc
Add updated doc strings for php doc
2 parents 0b4b4bd + e40c375 commit a7fb424

56 files changed

Lines changed: 1903 additions & 554 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Client.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@
99
use MarketDataApp\Endpoints\Stocks;
1010
use MarketDataApp\Endpoints\Utilities;
1111

12+
/**
13+
* Client class for the Market Data API.
14+
*
15+
* This class provides access to various endpoints of the Market Data API,
16+
* including indices, stocks, options, markets, mutual funds, and utilities.
17+
*/
1218
class Client extends ClientBase
1319
{
1420

1521
/**
1622
* The index endpoints provided by the Market Data API offer access to both real-time and historical data related to
1723
* financial indices. These endpoints are designed to cater to a wide range of financial data needs.
24+
*
25+
* @var Indices
1826
*/
1927
public Indices $indices;
2028

2129
/**
2230
* Stock endpoints include numerous fundamental, technical, and pricing data.
31+
*
32+
* @var Stocks
2333
*/
2434
public Stocks $stocks;
2535

@@ -28,25 +38,40 @@ class Client extends ClientBase
2838
* around options data. These endpoints are designed to be flexible and robust, supporting both real-time
2939
* and historical data queries. They accommodate a wide range of optional parameters for detailed data
3040
* retrieval, making the Market Data API a versatile tool for options traders and financial analysts.
41+
*
42+
* @var Options
3143
*/
3244
public Options $options;
3345

3446
/**
3547
* The Markets endpoints provide reference and status data about the markets covered by Market Data.
48+
*
49+
* @var Markets
3650
*/
3751
public Markets $markets;
3852

3953
/**
4054
* The mutual funds endpoints offer access to historical pricing data for mutual funds.
55+
*
56+
* @var MutualFunds
4157
*/
4258
public MutualFunds $mutual_funds;
4359

4460
/**
4561
* These endpoints are designed to assist with API-related service issues, including checking the online status and
4662
* uptime.
63+
*
64+
* @var Utilities
4765
*/
4866
public Utilities $utilities;
4967

68+
/**
69+
* Constructor for the Client class.
70+
*
71+
* Initializes all endpoint classes with the provided API token.
72+
*
73+
* @param string $token The API token for authentication.
74+
*/
5075
public function __construct($token)
5176
{
5277
parent::__construct($token);

src/ClientBase.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,62 @@
88
use GuzzleHttp\Promise\PromiseInterface;
99
use MarketDataApp\Exceptions\ApiException;
1010

11+
/**
12+
* Abstract base class for Market Data API client.
13+
*
14+
* This class provides core functionality for API communication,
15+
* including parallel execution, async requests, and response handling.
16+
*/
1117
abstract class ClientBase
1218
{
1319

20+
/**
21+
* The base URL for the Market Data API.
22+
*/
1423
public const API_URL = "https://api.marketdata.app/";
24+
25+
/**
26+
* The host for the Market Data API.
27+
*/
1528
public const API_HOST = "api.marketdata.app";
1629

30+
/**
31+
* @var GuzzleClient The Guzzle HTTP client instance.
32+
*/
1733
protected GuzzleClient $guzzle;
34+
35+
/**
36+
* @var string The API token for authentication.
37+
*/
1838
protected string $token;
1939

40+
/**
41+
* ClientBase constructor.
42+
*
43+
* @param string $token The API token for authentication.
44+
*/
2045
public function __construct(string $token)
2146
{
2247
$this->guzzle = new GuzzleClient(['base_uri' => self::API_URL]);
2348
$this->token = $token;
2449
}
2550

51+
/**
52+
* Set a custom Guzzle client.
53+
*
54+
* @param GuzzleClient $guzzleClient The Guzzle client to use.
55+
*/
2656
public function setGuzzle(GuzzleClient $guzzleClient): void
2757
{
2858
$this->guzzle = $guzzleClient;
2959
}
3060

3161
/**
62+
* Execute multiple API calls in parallel.
63+
*
64+
* @param array $calls An array of method calls, each containing the method name and arguments.
65+
*
66+
* @return array An array of decoded JSON responses.
3267
* @throws \Throwable
3368
*/
3469
public function execute_in_parallel(array $calls): array
@@ -44,6 +79,14 @@ public function execute_in_parallel(array $calls): array
4479
}, $responses);
4580
}
4681

82+
/**
83+
* Perform an asynchronous API request.
84+
*
85+
* @param string $method The API method to call.
86+
* @param array $arguments The arguments for the API call.
87+
*
88+
* @return PromiseInterface
89+
*/
4790
protected function async($method, array $arguments = []): PromiseInterface
4891
{
4992
return $this->guzzle->getAsync($method, [
@@ -53,6 +96,12 @@ protected function async($method, array $arguments = []): PromiseInterface
5396
}
5497

5598
/**
99+
* Execute a single API request.
100+
*
101+
* @param string $method The API method to call.
102+
* @param array $arguments The arguments for the API call.
103+
*
104+
* @return object The API response as an object.
56105
* @throws GuzzleException
57106
* @throws ApiException
58107
*/
@@ -93,6 +142,13 @@ public function execute($method, array $arguments = []): object
93142
return $object_response;
94143
}
95144

145+
/**
146+
* Generate headers for API requests.
147+
*
148+
* @param string $format The desired response format (json, csv, or html).
149+
*
150+
* @return array An array of headers.
151+
*/
96152
protected function headers(string $format = 'json'): array
97153
{
98154
return [

src/Endpoints/Indices.php

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,25 @@
1111
use MarketDataApp\Exceptions\ApiException;
1212
use MarketDataApp\Traits\UniversalParameters;
1313

14+
/**
15+
* Indices class for handling index-related API endpoints.
16+
*/
1417
class Indices
1518
{
1619

1720
use UniversalParameters;
1821

22+
/** @var Client The Market Data API client instance. */
1923
private Client $client;
24+
25+
/** @var string The base URL for index endpoints. */
2026
public const BASE_URL = "v1/indices/";
2127

28+
/**
29+
* Indices constructor.
30+
*
31+
* @param Client $client The Market Data API client instance.
32+
*/
2233
public function __construct($client)
2334
{
2435
$this->client = $client;
@@ -27,13 +38,15 @@ public function __construct($client)
2738
/**
2839
* Get a real-time quote for an index.
2940
*
30-
* @param string $symbol The index symbol, without any leading or trailing index identifiers. For example, use DJI
31-
* do not use $DJI, ^DJI, .DJI, DJI.X, etc.
41+
* @param string $symbol The index symbol, without any leading or trailing index identifiers. For
42+
* example, use DJI do not use $DJI, ^DJI, .DJI, DJI.X, etc.
3243
*
33-
* @param bool $fifty_two_week Enable the output of 52-week high and 52-week low data in the quote output.
44+
* @param bool $fifty_two_week Enable the output of 52-week high and 52-week low data in the quote
45+
* output.
3446
*
35-
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
47+
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
3648
*
49+
* @return Quote
3750
* @throws GuzzleException|ApiException
3851
*/
3952
public function quote(
@@ -44,14 +57,15 @@ public function quote(
4457
return new Quote($this->execute("quotes/$symbol", ['52week' => $fifty_two_week], $parameters));
4558
}
4659

47-
4860
/**
49-
* Get a real-time price quote for a multiple indices by doing parallel requests.
61+
* Get real-time price quotes for multiple indices by doing parallel requests.
5062
*
51-
* @param array $symbols The ticker symbols to return in the response.
52-
* @param bool $fifty_two_week Enable the output of 52-week high and 52-week low data in the quote output.
53-
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
63+
* @param array $symbols The ticker symbols to return in the response.
64+
* @param bool $fifty_two_week Enable the output of 52-week high and 52-week low data in the quote
65+
* output.
66+
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
5467
*
68+
* @return Quotes
5569
* @throws \Throwable
5670
*/
5771
public function quotes(
@@ -71,27 +85,27 @@ public function quotes(
7185
/**
7286
* Get historical price candles for an index.
7387
*
74-
* @param string $symbol The index symbol, without any leading or trailing index identifiers. For example, use DJI
75-
* do not use $DJI, ^DJI, .DJI, DJI.X, etc.
88+
* @param string $symbol The index symbol, without any leading or trailing index identifiers. For
89+
* example, use DJI do not use $DJI, ^DJI, .DJI, DJI.X, etc.
7690
*
77-
* @param string $from The leftmost candle on a chart (inclusive). If you use countback, to is not required.
78-
* Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
91+
* @param string $from The leftmost candle on a chart (inclusive). If you use countback, to is not
92+
* required. Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
7993
*
80-
* @param string|null $to The rightmost candle on a chart (inclusive). Accepted timestamp inputs: ISO 8601, unix,
81-
* spreadsheet.
94+
* @param string|null $to The rightmost candle on a chart (inclusive). Accepted timestamp inputs: ISO
95+
* 8601, unix, spreadsheet.
8296
*
83-
* @param string $resolution The duration of each candle.
84-
* Minutely Resolutions: (minutely, 1, 3, 5, 15, 30, 45, ...) Hourly Resolutions: (hourly, H, 1H, 2H, ...)
85-
* Daily Resolutions: (daily, D, 1D, 2D, ...)
86-
* Weekly Resolutions: (weekly, W, 1W, 2W, ...)
87-
* Monthly Resolutions: (monthly, M, 1M, 2M, ...)
88-
* Yearly Resolutions:(yearly, Y, 1Y, 2Y, ...)
97+
* @param string $resolution The duration of each candle.
98+
* Minutely Resolutions: (minutely, 1, 3, 5, 15, 30, 45, ...) Hourly
99+
* Resolutions: (hourly, H, 1H, 2H, ...) Daily Resolutions: (daily, D, 1D, 2D,
100+
* ...) Weekly Resolutions: (weekly, W, 1W, 2W, ...) Monthly Resolutions:
101+
* (monthly, M, 1M, 2M, ...) Yearly Resolutions:(yearly, Y, 1Y, 2Y, ...)
89102
*
90-
* @param int|null $countback Will fetch a number of candles before (to the left of) to. If you use from, countback
91-
* is not required.
103+
* @param int|null $countback Will fetch a number of candles before (to the left of) to. If you use from,
104+
* countback is not required.
92105
*
93106
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
94107
*
108+
* @return Candles
95109
* @throws ApiException|GuzzleException
96110
*/
97111
public function candles(

src/Endpoints/Markets.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,55 @@
99
use MarketDataApp\Exceptions\ApiException;
1010
use MarketDataApp\Traits\UniversalParameters;
1111

12+
/**
13+
* Markets class for handling market-related API endpoints.
14+
*/
1215
class Markets
1316
{
1417

1518
use UniversalParameters;
1619

20+
/** @var Client The Market Data API client instance. */
1721
private Client $client;
22+
23+
/** @var string The base URL for market endpoints. */
1824
public const BASE_URL = "v1/markets/";
1925

26+
/**
27+
* Markets constructor.
28+
*
29+
* @param Client $client The Market Data API client instance.
30+
*/
2031
public function __construct($client)
2132
{
2233
$this->client = $client;
2334
}
2435

2536
/**
37+
* Get the market status for a specific country and date range.
38+
*
2639
* Get the past, present, or future status for a stock market. The endpoint will respond with "open" for trading
2740
* days or "closed" for weekends or market holidays.
2841
*
29-
* @param string $country The country. Use the two-digit ISO 3166 country code. If no country is specified, US will
30-
* be assumed. Only countries that Market Data supports for stock price data are available (currently only the
31-
* United States).
42+
* @param string $country The country. Use the two-digit ISO 3166 country code. If no country is
43+
* specified, US will be assumed. Only countries that Market Data supports for
44+
* stock price data are available (currently only the United States).
3245
*
33-
* @param string|null $date Consult whether the market was open or closed on the specified date. Accepted timestamp
34-
* inputs: ISO 8601, unix, spreadsheet.
46+
* @param string|null $date Consult whether the market was open or closed on the specified date. Accepted
47+
* timestamp inputs: ISO 8601, unix, spreadsheet.
3548
*
36-
* @param string|null $from The earliest date (inclusive). If you use countback, from is not required. Accepted
37-
* timestamp inputs: ISO 8601, unix, spreadsheet.
49+
* @param string|null $from The earliest date (inclusive). If you use countback, from is not required.
50+
* Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
3851
*
39-
* @param string|null $to The last date (inclusive). Accepted timestamp inputs: ISO 8601, unix, spreadsheet.
52+
* @param string|null $to The last date (inclusive). Accepted timestamp inputs: ISO 8601, unix,
53+
* spreadsheet.
4054
*
41-
* @param int|null $countback Countback will fetch a number of dates before to If you use from, countback is not
42-
* required.
55+
* @param int|null $countback Countback will fetch a number of dates before to If you use from, countback
56+
* is not required.
4357
*
4458
* @param Parameters|null $parameters Universal parameters for all methods (such as format).
4559
*
60+
* @return Statuses
4661
* @throws GuzzleException|ApiException
4762
*/
4863
public function status(

0 commit comments

Comments
 (0)