Skip to content

Commit a85c731

Browse files
author
1Forge
committed
market_status
* Added support for the the market_status API call * Changed the primary class name from QuoteRequest to ForexRequest
1 parent 478060c commit a85c731

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ Or in your composer.json
3737
```php
3838
<?php
3939

40-
use OneForge\ForexQuotes\QuoteRequest;
40+
use OneForge\ForexQuotes\ForexRequest;
4141

4242
//Returns an array of symbols, eg: ['EURUSD', 'GBPJPY']
43-
QuoteRequest::getSymbols();
43+
ForexRequest::getSymbols();
4444
```
4545
### Get quotes for specified symbols:
4646
```php
4747
<?php
4848

49-
use OneForge\ForexQuotes\QuoteRequest;
49+
use OneForge\ForexQuotes\ForexRequest;
5050

5151
/*
5252
Returns an array of quotes, eg:
@@ -63,12 +63,29 @@ Returns an array of quotes, eg:
6363
],
6464
]
6565
*/
66-
QuoteRequest::getQuotes([
66+
ForexRequest::getQuotes([
6767
'AUDUSD',
6868
'GBPJPY'
6969
]);
7070
```
7171

72+
73+
### Check if the market is open:
74+
```php
75+
<?php
76+
77+
use OneForge\ForexQuotes\ForexRequest;
78+
79+
/*
80+
Returns an boolean
81+
*/
82+
if (ForexRequest::marketIsOpen())
83+
{
84+
echo "Market is open";
85+
}
86+
```
87+
88+
7289
## Other implementations
7390
You can also implement the api directly in any other way you wish. Full documentation is maintained here: <a href="https://1forge.com/forex-data-api">https://1forge.com/forex-data-api</a>
7491

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "oneforge/forexquotes",
33
"type": "library",
4-
"version": "1.0.4",
4+
"version": "1.0.5",
55
"description": "Library to fetch and parse realtime Forex quotes",
66
"keywords": [
77
"forex",

example.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99

1010
require_once __DIR__ . '/vendor/autoload.php';
1111

12-
$quotes = QuoteRequest::getQuotes(['AUDUSD',
13-
'GBPJPY']);
12+
$quotes = ForexRequest::getQuotes(['AUDUSD',
13+
'GBPJPY']);
14+
$symbols = ForexRequest::getSymbols();
15+
$market_is_open = ForexRequest::marketIsOpen();
1416

15-
$symbols = QuoteRequest::getSymbols();
17+
if ($market_is_open)
18+
{
19+
echo 'yes';
20+
}
1621

1722
print_r($quotes);
1823
print_r($symbols);
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
use GuzzleHttp\Client;
1111

12-
class QuoteRequest
12+
13+
class ForexRequest
1314
{
1415
public static function client()
1516
{
@@ -45,4 +46,18 @@ public static function getQuotes(array $symbols)
4546

4647
return $quotes_array;
4748
}
49+
50+
public static function marketIsOpen()
51+
{
52+
$body = self::client()->get('market_status')->getBody();
53+
54+
$body = json_decode($body);
55+
56+
if (property_exists($body, market_is_open))
57+
{
58+
return (bool)$body->market_is_open;
59+
}
60+
61+
return false;
62+
}
4863
}

0 commit comments

Comments
 (0)