Message Boards Message Boards

0
|
7482 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to slow down Dynamic?

Posted 10 years ago

I just started using Dynamic[..]. I am trying to watch bitcoin prices by a url call. While I am getting updates, they are too fast. Although the output changes only once a second (because there is a time returned that changes once a second) I worry that I am actually and needlessly querying the remote server many times a second. (Obviously, I don't want to be the source of an unintended DoS attack!) Trying either UpdateInterval->5 (see my code below) or Clock[{1,1},5] doesn't slow down the response. How can I slow it, or alternatively, can someone explain how often the remote server is actually being queried by this?

Style[Dynamic[Import["https://btc-e.com/api/2/btc_usd/ticker"], 
  UpdateInterval -> 5], DynamicEvaluationTimeout -> 10]
POSTED BY: Alan Lewis
3 Replies
Posted 10 years ago

Thank you both very much. Since my original post, I discovered the exchange has a somewhat newer api and suggests a query no often than once every 2 secs. Also I just wanted a last price that I could feed to other modules. So, the code below is what I finally settled on for anybody interested.

Style[Dynamic[{DateString[], 
   ToExpression[
    StringCases[Import["https://btc-e.com/api/3/ticker/btc_usd"], 
      "last\":" ~~ x__ ~~ ",\"buy" -> x][[1]]]}, UpdateInterval -> 2, 
  TrackedSymbols :> {}], DynamicEvaluationTimeout -> 10]
POSTED BY: Alan Lewis
Posted 10 years ago

You need , TrackedSymbols :> {}, check documentation for Refresh, there is an example about that.

So the full code:

Style[Dynamic[  Import["https://btc-e.com/api/2/btc_usd/ticker"], 
                        UpdateInterval -> 5, TrackedSymbols :> {}], 
      DynamicEvaluationTimeout -> 10]
POSTED BY: Kuba Podkalicki

Hello, Here is one possible solution:

This will import every 10 seconds, and repeat 100 times. See CreateScheduledTask to modify this.

StartScheduledTask[
 CreateScheduledTask[
  bitCoinVal = {DateString[], 
    Import["https://btc-e.com/api/2/btc_usd/ticker"]}, {10, 100}]]

Dynamic[bitCoinVal]

The remote server queries are a mystery to me.

POSTED BY: W. Craig Carter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract