Writing my api economics.

{ "Meta Data": { "1. Information": "Daily Prices (open, high, low, close) and Volumes", "2. Symbol": "MSFT", "3. Last Refreshed": "2018-02-01 10:22:35", "4. Output Size": "Compact", "5. Time Zone": "US/Eastern" }, "Time Series (Daily)": { "2018-02-01": { "1. open": "94.7900", "2. high": "95.8400", "3. low": "94.2000", "4. close": "95.3201", "5. volume": "12137068" }, "2018-01-31": { "1. open": "93.7500", "2. high": "95.4000", "3. low": "93.5100", "4. close": "95.0100", "5. volume": "46348826" } } }edit: I indented it more for you. JimL

I indented first part so u get an idea how json is presented in my browser extension.
I have no problem puting echo $eco_array[‘Meta Data’][‘2. Symbol’]
give me the symbol data of what i just requested but how to
get down to [‘1. open’] etx I normally never had problem with this arrays but what am i missing?
and im doing this in php after json_decode$dd
:o I hope not too difficult im working on my arrays, but and a side question
if i want to write graphs with the information is it a must to code in js?
And if someone can point me in right direction all i can do with api response
regards
all input is welcome!

[php]<?php
$ecoData = json_decode(’{“Meta Data”:{“1. Information”:“Daily Prices (open, high, low, close) and Volumes”,“2. Symbol”:“MSFT”,“3. Last Refreshed”:“2018-02-01 10:22:35”,“4. Output Size”:“Compact”,“5. Time Zone”:“US/Eastern”},“Time Series (Daily)”:{“2018-02-01”:{“1. open”:“94.7900”,“2. high”:“95.8400”,“3. low”:“94.2000”,“4. close”:“95.3201”,“5. volume”:“12137068”},“2018-01-31”:{“1. open”:“93.7500”,“2. high”:“95.4000”,“3. low”:“93.5100”,“4. close”:“95.0100”,“5. volume”:“46348826”}}}’, true);

foreach($ecoData[‘Time Series (Daily)’] as $date => $data) {
var_dump($date, $data[‘1. open’]);
}[/php]

:wink: :wink: thanks very much You think different than mine but im sure it works, I however fixed the problem
its real time so whenever i edited a timestamp,
it was too late to fit in the array ;D
i feel like a nerd but yeah now and thanks to all help I have api running
its realtime so timezone was problem also,
My next step is to write som kind of graph?
Is it even possible?
thousand thanks anyways.

Im sorry but have also a continuation question how do I
put a variable into a strin with parenthesis?
$F = ($_GET[‘time’]);
$E = ‘Time Series $F’;
when its finished I need it to look like:
‘Time Series (1min)’

Single quotes means, string literal. Double quotes do string interpolation.

[php]$name = “Harry”;
$str = “This is my {$name}”;[/php]

For some real fun…

One hesitation you should have, is XSS attacks based on this code however.
[php]$_GET[‘time’] = “”;
// NOTE: the $_GET assignment is just for example, though this can be passed via url

$time = ($_GET[‘time’]);
$time_string = “Time Series {$F}”;

echo $time_string;[/php]

So, you want to filter or encode anything that comes from an outside source.

ye very much thanks its working! i get the time right every minute so i can fetch api request
correctly.
However is there ani shortcut in making complex time variables and loops
I want a loop 10 min back in time and then add ++1 to 10 times to current
time, but i stumble on problem that i write my loop.
First of all it returns a single digit and requires the zero
when 01 02 03 04 05 06 07 08 09 10
So my algoritm onli works after 10 minutes every hour
And if time is 19:02:00
MY algoritm minus 10 so it returns 19:-8:00
I think its funny but clock is killing me
I dont know how much i can ask but this probably be my last question in subject.
;D

for ($s = $a-04; $s <= $a - 0; $s++)
this is my loop 4 min back in time
it works as mentioned if not close to whole hour and single digits.

You can ask as much as you want!

How is the time piece used? You could use DateTime and then subtract the time you want to use.

https://www.ideone.com/mViRU2

;D ye im back…
I dont know how to explain time code, better and my next question i ask myself is in json.
So its not really right forum but if i for example want the json respons i posted earlier
to look like this
{
“cols”: [
{“id”:"",“label”:“Topping”,“pattern”:"",“type”:“string”},
{“id”:"",“label”:“Slices”,“pattern”:"",“type”:“number”}
],
“rows”: [
{“c”:[{“v”:“Mushrooms”,“f”:null},{“v”:3,“f”:null}]},
{“c”:[{“v”:“Onions”,“f”:null},{“v”:1,“f”:null}]},
{“c”:[{“v”:“Olives”,“f”:null},{“v”:1,“f”:null}]},
{“c”:[{“v”:“Zucchini”,“f”:null},{“v”:1,“f”:null}]},
{“c”:[{“v”:“Pepperoni”,“f”:null},{“v”:2,“f”:null}]}
]
}

Im trying google charts at moment and all data need look like this to be accepted in the graph.
I know this is not php plus its above my understanding but if i be told right direction how to think?
I there a way with php to format it in a specific way?
if i have for example
[php]$economics = ‘https://www.alphxx’;
$mapsjason = file_get_contents($economics);
// here i can just echo $mapsjason;
// and have a json source to fetch but the format is wrong so it give an error @no columns@
//[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service