1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DPRMC\IceRemotePlusClient; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemDoesNotExistInSecurityResponse; |
7
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailable; |
8
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseErrorCode5000; |
9
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseErrorCode6000; |
10
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseErrorCode7000; |
11
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseErrorCode8000; |
12
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseHoliday; |
13
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseNotExpected; |
14
|
|
|
use DPRMC\IceRemotePlusClient\Exceptions\ItemValueNotAvailableBecauseNotReported; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Represents all of the data items requested for a specific security. |
18
|
|
|
* Class SecurityResponse |
19
|
|
|
* @package DPRMC\InteractiveData |
20
|
|
|
*/ |
21
|
|
|
class SecurityResponse { |
22
|
|
|
/** |
23
|
|
|
* @var string The security identifier |
24
|
|
|
*/ |
25
|
|
|
public $identifier; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Carbon The date of the data being pulled. |
29
|
|
|
*/ |
30
|
|
|
public $date; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array An array of itemCode => value for each item code you want to pull for this security. |
34
|
|
|
*/ |
35
|
|
|
public $items; // array itemCode => value |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* SecurityResponse constructor. |
39
|
|
|
*/ |
40
|
|
|
public function __construct() { |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return SecurityResponse |
45
|
|
|
*/ |
46
|
|
|
public static function instantiate() { |
47
|
|
|
return new static(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $identifier |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function addIdentifier( string $identifier ) { |
55
|
|
|
$this->identifier = $identifier; |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $date |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function addDate( string $date ) { |
64
|
|
|
$this->date = Carbon::parse( $date ); |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $code |
70
|
|
|
* @param null $value |
|
|
|
|
71
|
|
|
* @return $this |
72
|
|
|
* |
73
|
|
|
* The following are special values that indicate some kind of non-response occurred. |
74
|
|
|
* “!NA” not available |
75
|
|
|
* “!NH” holiday (only applicable to US/Canadian securities) |
76
|
|
|
* “!NE” not expected (e.g., prices for future dates) |
77
|
|
|
* “!NR” not reported |
78
|
|
|
* “!N5” an error code 5000 was returned |
79
|
|
|
* “!N6” an error code 6000 was returned |
80
|
|
|
* “!N7” an error code 7000 was returned |
81
|
|
|
* “!N8” an error code 8000 was returned |
82
|
|
|
*/ |
83
|
|
|
public function addItem( string $code, $value = NULL ) { |
84
|
|
|
$this->items[ $code ] = trim( $value, ' "' ); |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Logic method to improve readability. |
90
|
|
|
* @param string $item |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
|
|
protected function itemExists( string $item ): bool { |
94
|
|
|
if ( isset( $this->items[ $item ] ) ): |
95
|
|
|
return TRUE; |
96
|
|
|
endif; |
97
|
|
|
return FALSE; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $item The item code of the value you want to retrieve. |
102
|
|
|
* @return mixed |
103
|
|
|
* @throws ItemDoesNotExistInSecurityResponse |
104
|
|
|
* @throws ItemValueNotAvailable |
105
|
|
|
* @throws ItemValueNotAvailableBecauseErrorCode5000 |
106
|
|
|
* @throws ItemValueNotAvailableBecauseErrorCode6000 |
107
|
|
|
* @throws ItemValueNotAvailableBecauseErrorCode7000 |
108
|
|
|
* @throws ItemValueNotAvailableBecauseErrorCode8000 |
109
|
|
|
* @throws ItemValueNotAvailableBecauseHoliday |
110
|
|
|
* @throws ItemValueNotAvailableBecauseNotExpected |
111
|
|
|
* @throws ItemValueNotAvailableBecauseNotReported |
112
|
|
|
* @note From Client Support at ICE Data Services: unfortunately we don't have examples for the others (!NR, !N5, !N6, !N7, and !N8). |
113
|
|
|
* ...so as a result those Exceptions can't be tested with our unit tests. |
114
|
|
|
*/ |
115
|
|
|
public function getItem( string $item ) { |
116
|
|
|
if ( FALSE === $this->itemExists( $item ) ): |
117
|
|
|
throw new ItemDoesNotExistInSecurityResponse(); |
118
|
|
|
endif; |
119
|
|
|
|
120
|
|
|
$value = $this->items[ $item ]; |
121
|
|
|
|
122
|
|
|
switch ( $value ): |
123
|
|
|
case '!NA': |
124
|
|
|
throw new ItemValueNotAvailable(); |
125
|
|
|
case '!NH': |
126
|
|
|
throw new ItemValueNotAvailableBecauseHoliday(); |
127
|
|
|
case '!NE': |
128
|
|
|
throw new ItemValueNotAvailableBecauseNotExpected(); |
129
|
|
|
case '!NR': |
130
|
|
|
throw new ItemValueNotAvailableBecauseNotReported(); |
131
|
|
|
case '!N5': |
132
|
|
|
throw new ItemValueNotAvailableBecauseErrorCode5000(); |
133
|
|
|
case '!N6': |
134
|
|
|
throw new ItemValueNotAvailableBecauseErrorCode6000(); |
135
|
|
|
case '!N7': |
136
|
|
|
throw new ItemValueNotAvailableBecauseErrorCode7000(); |
137
|
|
|
case '!N8': |
138
|
|
|
throw new ItemValueNotAvailableBecauseErrorCode8000(); |
139
|
|
|
endswitch; |
140
|
|
|
|
141
|
|
|
return $value; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
} |