Jump to content

Recommended Posts

Hello, look at this data :

 

{"amount":"2.001","date":1436471288,"date_ms":1436471288000,"price":"46.94","tid":109134569,"type":"sell"},{"amount":"2.001","date":1436471289,"date_ms":1436471289000,"price":"46.94","tid":109134571,"type":"sell"},{"amount":"2.001","date":1436471290,"date_ms":1436471290000,"price":"46.94","tid":109134576,"type":"sell"},{"amount":"2.001","date":1436471290,"date_ms":1436471290000,"price":"46.94","tid":109134579,"type":"sell"},{"amount":"1","date":1436471292,"date_ms":1436471292000,"price":"46.95","tid":109134587,"type":"buy"},{"amount":"4.21","date":1436471292,"date_ms":1436471292000,"price":"46.95","tid":109134589,"type":"buy"},{"amount":"8.299","date":1436471292,"date_ms":1436471292000,"price":"46.96","tid":109134591,"type":"buy"},{"amount":"5.346","date":1436471292,"date_ms":1436471292000,"price":"46.97","tid":109134593,"type":"buy"},{"amount":"2.001","date":1436471292,"date_ms":1436471292000,"price":"46.94","tid":109134594,"type":"sell"},{"amount":"10.2","date":1436471295,"date_ms":1436471295000,"price":"46.94","tid":109134615,"type":"sell"},

 

They are market data from a URL that refreshing too fast so new data will be added every second . I want to write a code to add amount of buy requests and amount of sell requests every second that the new data comes then have the buy sum and sell sum sepratelly . how to do this ?

Link to comment
https://forums.phpfreaks.com/topic/297240-i-need-help-to-write-a-piece-of-code/
Share on other sites

As you said, write some code.

 

 

The forum is for people who actually are trying to write code. It is not here to just figure out what you are talking about it and come up with your solution for you. Try to code it. If you can't then try to learn by reading and researching and becoming a programmer. Or go to the forum designated for professional help and pay someone to write your code for you.

 

You might also re-read your post and correct the language so that it tells us what you are talking about. I know I'm confused by your post.

As you said, write some code.

 

 

The forum is for people who actually are trying to write code. It is not here to just figure out what you are talking about it and come up with your solution for you. Try to code it. If you can't then try to learn by reading and researching and becoming a programmer. Or go to the forum designated for professional help and pay someone to write your code for you.

 

You might also re-read your post and correct the language so that it tells us what you are talking about. I know I'm confused by your post.

yeah my language is awful but you could give me some functions to research them , I didn't ask anyone to give me the full code . if you can't help others you are free to leave this topic because it's PHP coding help .

Some explanation of the whole process would help. For example, is that data the result of a single call to the url or accumulated from several calls. If several, how are you storing it? Do you want individual total for every second or is it that the data comes in every second but you want the accumulated totals for the day/hour or whatever time period?

 

That is JSON data so you might want to start by looking at json_decode()

Some explanation of the whole process would help. For example, is that data the result of a single call to the url or accumulated from several calls. If several, how are you storing it? Do you want individual total for every second or is it that the data comes in every second but you want the accumulated totals for the day/hour or whatever time period?

 

That is JSON data so you might want to start by looking at json_decode()

that json_decode() can help too much . actually they are exchange market data and the new data will be added every second , see this : https://www.okcoin.cn/api/v1/trades.do?symbol=ltc_cny

I'm thinking about something like this :

$obj = THE CODE TO REQUEST THE JSON FROM THE WEBSERVER

$obj = json_decode($obj);

$sell = 0;
$buy = 0;

//loop through object and increment $buy and $sell by value of each row
foreach($obj as $key => $row){
    if($row->type == "sell"){
          $sell = $sell + intval($row->amount);
    } else if($row->type == "buy"){
           $buy = $buy + intval($row->amount);
    } 
} 

My problem is how to handle all that data that fast and how to store them in one variable like $buy or $sell ? I think that variables will reset after every refresh .

It's going to be difficult to guarantee that you can do that in one second, every second. You can't even guarantee their server is going to respond within 1 second.

 

If that requirement is absolutely critical you're probably going to want parallel computing.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.