Skip to content

Commit d3b7878

Browse files
authored
Merge pull request #5 from MarketDataApp/fill-in-stub-endpoints
Fill in stub endpoints
2 parents 03faf1a + 9f5fd47 commit d3b7878

31 files changed

Lines changed: 1504 additions & 104 deletions

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## v0.4.0-alpha
4+
5+
- Completed remaining endpoints:
6+
- Options
7+
- expirations
8+
- lookup
9+
- strikes
10+
- option_chain
11+
- quotes
12+
- Utilities
13+
- api_status
14+
- headers
15+
- Mutual Funds
16+
- candles
17+
- Markets
18+
- status
19+
320
## v0.3.0-alpha
421

522
- Completed Stocks endpoints: earnings, news.

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,42 @@ $quotes = $client->stocks->quotes(['AAPL', 'NFLX']);
3939
$bulk_quotes = $client->stocks->bulk_quotes(['AAPL', 'NFLX']);
4040
$earnings = $client->stocks->earnings(symbol: 'AAPL', from: Carbon::parse('2023-01-01'));
4141
$news = $client->stocks->news(symbol: 'AAPL', from: Carbon::parse('2023-01-01'));
42+
43+
// Markets
44+
$status = $client->markets->status(date: Carbon::parse('2023-01-01'));
45+
46+
// Mutual Funds
47+
$candles = $client->mutual_funds->candles(
48+
symbol: 'VFINX',
49+
from: Carbon::parse('2022-09-01'),
50+
to: Carbon::parse('2022-09-05'),
51+
resolution: 'D'
52+
);
53+
54+
// Options
55+
$expirations = $client->options->expirations('AAPL');
56+
$lookup = $client->options->lookup('AAPL 7/28/23 $200 Call');
57+
$strikes = $client->options->strikes(
58+
symbol: 'AAPL',
59+
expiration: Carbon::parse('2023-01-20'),
60+
date: Carbon::parse('2023-01-03'),
61+
);
62+
$option_chain = $client->options->option_chain(
63+
symbol: 'AAPL',
64+
expiration: Carbon::parse('2025-01-17'),
65+
side: Side::CALL,
66+
);
67+
$quotes = $client->options->quotes('AAPL250117C00150000');
68+
69+
// Utilities
70+
$status = $client->utilities->api_status();
71+
$headers = $client->utilities->headers();
4272
```
4373

4474
## Testing
4575

4676
```bash
47-
./vendor/bin/phpunit tests
77+
./vendor/bin/phpunit
4878
```
4979

5080
## Changelog

src/ClientBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function execute($method, array $arguments = []): object
6666

6767
$response = json_decode($json_response);
6868

69-
if($response->s === 'error') {
69+
if(isset($response->s) && $response->s === 'error') {
7070
throw new ApiException(message: $response->errmsg, response: $response);
7171
}
7272

src/Endpoints/Markets.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace MarketDataApp\Endpoints;
44

5+
use Carbon\Carbon;
6+
use GuzzleHttp\Exception\GuzzleException;
57
use MarketDataApp\Client;
6-
use MarketDataApp\Endpoints\Responses\Markets\Status;
8+
use MarketDataApp\Endpoints\Responses\Markets\Statuses;
9+
use MarketDataApp\Exceptions\ApiException;
710

811
class Markets
912
{
@@ -16,9 +19,31 @@ public function __construct($client)
1619
$this->client = $client;
1720
}
1821

19-
public function status(): Status
20-
{
22+
/**
23+
* Get the past, present, or future status for a stock market. The endpoint will respond with "open" for trading
24+
* days or "closed" for weekends or market holidays.
25+
*
26+
* @param string $country The country. Use the two digit ISO 3166 country code. If no country is specified, US will
27+
* be assumed. Only countries that Market Data supports for stock price data are available (currently only the
28+
* United States).
29+
*
30+
* @param Carbon|null $date Consult whether the market was open or closed on the specified date.
31+
* @param Carbon|null $from The earliest date (inclusive). If you use countback, from is not required.
32+
* @param Carbon|null $to The last date (inclusive).
33+
* @param int|null $countback Countback will fetch a number of dates before to If you use from, countback is not
34+
* required.
35+
* @return Statuses
36+
* @throws GuzzleException|ApiException
37+
*/
38+
public function status(
39+
string $country = "US",
40+
Carbon $date = null,
41+
Carbon $from = null,
42+
Carbon $to = null,
43+
int $countback = null
44+
): Statuses {
2145
// Stub
22-
return new Status();
46+
return new Statuses($this->client->execute(self::BASE_URL . "status/",
47+
compact('country', 'date', 'from', 'to', 'countback')));
2348
}
2449
}

src/Endpoints/MutualFunds.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace MarketDataApp\Endpoints;
44

5+
use Carbon\Carbon;
6+
use GuzzleHttp\Exception\GuzzleException;
57
use MarketDataApp\Client;
68
use MarketDataApp\Endpoints\Responses\MutualFunds\Candles;
9+
use MarketDataApp\Exceptions\ApiException;
710

811
class MutualFunds
912
{
@@ -16,9 +19,34 @@ public function __construct($client)
1619
$this->client = $client;
1720
}
1821

19-
public function candles(): Candles
20-
{
21-
// Stub
22-
return new Candles();
22+
/**
23+
* Get historical price candles for a mutual fund.
24+
*
25+
* @param string $symbol The mutual fund's ticker symbol.
26+
* @param Carbon $from The leftmost candle on a chart (inclusive). If you use countback, to is not required.
27+
* @param Carbon|null $to The rightmost candle on a chart (inclusive).
28+
* @param string $resolution The duration of each candle.
29+
* Minutely Resolutions: (minutely, 1, 3, 5, 15, 30, 45, ...) Hourly Resolutions: (hourly, H, 1H, 2H, ...)
30+
* Daily Resolutions: (daily, D, 1D, 2D, ...)
31+
* Weekly Resolutions: (weekly, W, 1W, 2W, ...)
32+
* Monthly Resolutions: (monthly, M, 1M, 2M, ...)
33+
* Yearly Resolutions:(yearly, Y, 1Y, 2Y, ...)
34+
*
35+
* @param int|null $countback Will fetch a number of candles before (to the left of) to. If you use from, countback
36+
* is not required.
37+
*
38+
* @return Candles
39+
* @throws GuzzleException|ApiException
40+
*/
41+
public function candles(
42+
string $symbol,
43+
Carbon $from,
44+
Carbon $to = null,
45+
string $resolution = 'D',
46+
int $countback = null,
47+
): Candles {
48+
return new Candles($this->client->execute(self::BASE_URL . "candles/{$resolution}/{$symbol}/",
49+
compact('from', 'to', 'countback')
50+
));
2351
}
2452
}

0 commit comments

Comments
 (0)