Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import supercollider.*;
- import oscP5.*;
- import netP5.*;
- import hypermedia.net.*;
- UDP udp;
- Synth synth;
- Synth pink;
- Synth market;
- void setup ()
- {
- size(800, 200);
- market = new Synth("market");
- pink = new Synth("pink-noise");
- pink.set("vol", 0.2);
- pink.create();
- market.create();
- udp = new UDP( this, 11001 );
- udp.listen( true );
- }
- void draw ()
- {
- background(0);
- }
- void receive( byte[] data, String ip, int port )
- {
- data = subset(data, 0, data.length-2);
- String message = new String( data );
- //println(message);
- ParseLine(message);
- }
- public void ParseLine(String line) {
- if (line.startsWith("Ask") || line.startsWith("Bid") || line.startsWith("Vol")) {
- String test = line.replace(",", "").replace(" ", "").replace("BTC", "").replace("$", "").replace("Â", "").replace("USD", "");
- String[] splitString = test.split("#");
- HashMap<String, Float> keyVal = new HashMap<String, Float>();
- //println(line);
- for (String item : splitString) {
- String[] itemSplit = item.split(":");
- String key = itemSplit[0];
- Float amt;
- Float price;
- if(key.equals("Bid") || key.equals("Ask")){
- price = Float.parseFloat(itemSplit[3].substring(0,itemSplit[3].length()-2));
- keyVal.put("Price", price);
- }
- if(key.equals("Vol")){
- amt = Float.parseFloat(itemSplit[1].substring(0, itemSplit[1].length()-5));
- }else{
- amt = Float.parseFloat(itemSplit[1]);
- }
- keyVal.put(key, amt);
- }
- for (Map.Entry entry : keyVal.entrySet()) {
- if (entry.getKey().equals("Ask")) {
- HandleAskChanged((Float)entry.getValue(),keyVal.get("Price"));
- continue;
- }
- if (entry.getKey().equals("Bid")) {
- HandleBidChanged((Float)entry.getValue(),keyVal.get("Price"));
- continue;
- }
- if (entry.getKey().equals("Last")) {
- HandleLastChanged((Float)entry.getValue());
- continue;
- }
- if (entry.getKey().equals("Low")) {
- HandleLowChanged((Float)entry.getValue());
- continue;
- }
- if (entry.getKey().equals("High")) {
- HandleHighChanged((Float)entry.getValue());
- continue;
- }
- if (entry.getKey().equals("Avg")) {
- HandleAvgChanged((Float)entry.getValue());
- continue;
- }
- if (entry.getKey().equals("Vol")) {
- HandleVolChanged((Float)entry.getValue());
- continue;
- }
- }
- }
- }
- public void HandleAskChanged(float vol, float price) {
- println("HandleAskChanged"+vol+" "+price);
- market.set("freq", price);
- }
- public void HandleBidChanged(float vol, float price) {
- //println("HandleBidChanged"+vol+" "+price);
- }
- public void HandleLastChanged(float lastChanged) {
- //println("HandleLastChanged:"+lastChanged);
- }
- public void HandleVolChanged(float vol) {
- //println("HandleVolChanged:"+Math.log(Math.log(vol)+1)/2);
- //println("HandleVolChanged:"+vol);
- float logvol = Float.parseFloat(Math.log(Math.log(vol)+1)+"");
- pink.set("vol", logvol);
- }
- public void HandleLowChanged(float low) {
- //println("HandleLowChanged:"+low);
- }
- public void HandleHighChanged(float high) {
- //println("HandleHighChanged:"+high);
- }
- public void HandleAvgChanged(float avg) {
- //println("HandleAvgChanged:"+avg);
- }
- void exit ()
- {
- market.free();
- pink.free();
- super.exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement