Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import {Component, OnInit} from '@angular/core';
  2. import * as socketIo from 'socket.io-client';
  3. import {Statics} from './statics';
  4. import {CurrencyPair} from './CurrencyPair'
  5. @Component({
  6. selector: 'app-root',
  7. templateUrl: './app.component.html',
  8. styleUrls: ['./app.component.css']
  9. })
  10. export class AppComponent {
  11.  
  12. type
  13. exchangeName
  14. fromCurrency
  15. toCurrency
  16. flag
  17. price
  18. lastUpdate
  19. lastVolume
  20. lastVolumeTo
  21. lastTradeId
  22. volume24h
  23. volume24hTo
  24. maskInt
  25. response
  26. globals
  27. currencySubs = []
  28. currencyMap = {}
  29.  
  30. ngOnInit(){
  31. //called after the constructor and called after the first ngOnChanges()
  32.  
  33. this.statics.currencies.forEach((currencyName, index )=> {
  34. this.currencyMap[currencyName] = new CurrencyPair(currencyName)
  35. this.currencySubs.push(`2~BitTrex~${currencyName}~BTC`)
  36. });
  37. var socket = socketIo("wss://streamer.cryptocompare.com");
  38. socket.emit('SubAdd', { subs: this.currencySubs } );
  39. socket.on("m", (message) => {
  40. this.response = message
  41. var arr: Array<string> = message.split('~')
  42. if (arr.length > 1){
  43. // console.log("New Currency Name = " + arr[2])
  44. // console.log("Upcoming Volume Update = " +arr[8])
  45. // console.log("Upcoming Price Update = "+ arr[5])
  46. this.currencyMap[arr[2]].updateVolume(parseFloat(arr[8]))
  47. this.currencyMap[arr[2]].updatePrice(parseFloat(arr[5]))
  48.  
  49. this.type = arr[0]
  50. this.exchangeName = arr[1]
  51. this.fromCurrency = arr[2]
  52. this.toCurrency = arr[3]
  53. this.flag = arr[4]
  54. this.price = arr[5]
  55. this.lastUpdate = arr[6]
  56. this.lastVolume = arr[7]
  57. this.lastVolumeTo = arr[8]
  58. this.lastTradeId = arr[9]
  59. this.volume24h = arr[10]
  60. this.volume24hTo = arr[11]
  61. this.maskInt = arr[12]
  62. }})
  63. setInterval(()=>{ this.calculateIntervalResults(); }, 30000 );
  64. // 300000
  65. }
  66. constructor(private statics: Statics) {
  67. this.type = 5
  68. this.globals = this.statics.globals
  69. }
  70.  
  71. calculateIntervalResults(): void {
  72. this.statics.currencies.forEach((currencyName, idx) => {
  73. this.currencyMap[currencyName].calculateIntervalResult();
  74. });
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement