Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. <script>
  2. import Widget from '@/components/widgets/Widget';
  3. import TabWidget from '@/store/models/tab/TabWidget';
  4. import VolumeInspectorProfile from './VolumeInspectorProfile';
  5. import VolumeInspectorRatios from './VolumeInspectorRatios';
  6. import BaseChip from '../../base/BaseChip';
  7. import VolumeInspectorStream from './VolumeInspectorStream';
  8. import BaseIconButton from '../../base/BaseIconButton';
  9. import TradeFlowSettings from '../../../store/models/widget/TradeFlowSettings';
  10. import BaseMenu from '../../base/BaseMenu';
  11. import BaseCheckbox from '../../base/BaseCheckbox';
  12. import BaseDropdown from '../../base/BaseDropdown';
  13. import TextfieldOutline from '../../base/TextfieldOutline';
  14. import BaseButton from '../../base/BaseButton';
  15. import BaseIcon from '../../base/BaseIcon';
  16. import AppIcon from '../../app/AppIcon';
  17. import NumberfieldOutline from '../../base/NumberfieldOutline';
  18. import TabInformation from '../../mixins/TabInformation';
  19. import TimeFilter from '@/store/models/filter/TimeFilter';
  20. import {combineLatest,of, ReplaySubject} from 'rxjs'
  21. import {debounceTime, distinctUntilChanged, filter, map, pluck, tap, share, toPromise, startWith, switchMap, mergeAll, scan} from 'rxjs/operators'
  22. import VolumeInspectorSetting from '@/store/models/widget/VolumeInspectorSetting';
  23. import VolumeRatioPivot from '@/store/models/widget/TradeFlow/VolumeRatioPivot';
  24.  
  25. export default {
  26. name: 'VolumeInspectorWidget',
  27. mixins: [TabInformation],
  28. components: {
  29. AppIcon,
  30. BaseDropdown,
  31. NumberfieldOutline,
  32. BaseIcon,
  33. BaseButton,
  34. Widget,
  35. BaseMenu,
  36. BaseChip,
  37. BaseCheckbox,
  38. BaseIconButton,
  39. TextfieldOutline,
  40. VolumeInspectorStream,
  41. VolumeInspectorRatios,
  42. VolumeInspectorProfile,
  43. },
  44. props: {
  45. widgetID: Number,
  46. },
  47.  
  48. data() {
  49. return {
  50. ratios: {},
  51. subscription: null,
  52. setWhaleSize: false,
  53. whaleSize: 10000,
  54. totals1: {buys: {volume: 0}, sells: {volume: 0}},
  55. totals5: {buys: {volume: 0}, sells: {volume: 0}},
  56. totals15: {buys: {volume: 0}, sells: {volume: 0}},
  57. totals30: {buys: {volume: 0}, sells: {volume: 0}},
  58. totals60: {buys: {volume: 0}, sells: {volume: 0}},
  59. totals24H: {buys: {volume: 0}, sells: {volume: 0}},
  60. profile: {buys: {volume: 0}, sells: {volume: 0}, avg_buy: 0, total_volume: 0, avg_sell:0, buy_volume: 0, sell_volume:0, average: 0},
  61. totals: {buys: {volume: 0}, sells: {volume: 0}},
  62. filterBySize: false,
  63. filterSize: 10000,
  64. filter$: 60,
  65. expandedPreferences: false,
  66. onlyWhale: false,
  67. panel: [],
  68. data: [],
  69. ratios$: {},
  70. timeFilterRatios: [60, 300, 900, 1800, 3600, 86400]
  71. };
  72. },
  73.  
  74. computed: {
  75. timeFilters() {
  76. return this.activeTab.volume_pivot ||[];
  77. },
  78. filtered() {
  79. return [
  80. this.timeFilters[0].enabled ? this.ratios$[60] : null,
  81. this.timeFilters[1].enabled ? this.ratios$[300] : null,
  82. this.timeFilters[2].enabled ? this.ratios$[900] : null,
  83. this.timeFilters[3].enabled ? this.ratios$[1800] : null,
  84. this.timeFilters[4].enabled ? this.ratios$[3600] : null,
  85. this.timeFilters[5].enabled ? this.ratios$[86400] : null,
  86. ];
  87. },
  88. filter() {
  89. return TimeFilter.query().where('id', this.volumeInspectorSettings.time_filter_id).first();
  90. },
  91. volumeInspectorSettings() {
  92. return (
  93. VolumeInspectorSetting.query().where('tab_id', this.activeTabId).first() || {}
  94. );
  95. },
  96. widget() {
  97. return TabWidget.find(this.widgetID);
  98. },
  99. },
  100.  
  101. methods: {
  102. saveStreamSettings() {
  103. VolumeInspectorSetting.$update({
  104. params: {
  105. id: this.volumeInspectorSettings.id,
  106. },
  107. data: {
  108. filter_amount: this.volumeInspectorSettings.filter_amount,
  109. filter_enabled: this.volumeInspectorSettings.filter_enabled,
  110. whale_trade_amount: this.volumeInspectorSettings.whale_trade_amount,
  111. whale_trade_enabled: this.volumeInspectorSettings.whale_trade_enabled,
  112. only_whale_trades: this.volumeInspectorSettings.only_whale_trades
  113. },
  114. });
  115. },
  116. togglePreferences($e) {
  117. this.expandedPreferences = $e;
  118. },
  119. toggleRatioVisibility(key, filter) {
  120. this.getRatios();
  121.  
  122. VolumeRatioPivot.$update({
  123. params: {id: filter.id},
  124. data: {
  125. enabled: !this.timeFilters[key].enabled,
  126. },
  127. });
  128. },
  129. toggleWhaleTrade() {
  130. TradeFlowSettings.$update({
  131. params: {id: this.volumeInspectorSettings.id},
  132. data: {
  133. only_whale_trades: !this.volumeInspectorSettings.only_whale_trades,
  134. filter_amount: this.volumeInspectorSettings.filter_amount,
  135. filter_enabled: this.volumeInspectorSettings.filter_enabled,
  136. whale_trade_amount: this.volumeInspectorSettings.whale_trade_amount,
  137. whale_trade_enabled: this.volumeInspectorSettings.whale_trade_enabled
  138. },
  139. });
  140. },
  141. updateVolumeSetting(key, $e) {
  142. VolumeInspectorSetting.$update({
  143. params: {
  144. id: this.volumeInspectorSettings.id,
  145. },
  146. data: {
  147. [key]: $e,
  148. },
  149. });
  150. },
  151. getRatios() {
  152. let ratios = {};
  153. this.timeFilters.map(value => {
  154. ratios[value.time_filter.amount] = value.enabled;
  155. });
  156. this.ratios = ratios;
  157. },
  158. setFilter(filter) {
  159. TradeFlowSettings.$update({
  160. params: {id: this.volumeInspectorSettings.id},
  161. data: {time_filter_id: filter.time_filter_id},
  162. });
  163. },
  164. },
  165.  
  166. mounted() {
  167. const symbol$ = this.$watchAsObservable('activeSymbol').pipe(startWith({newValue: this.activeSymbol}), pluck('newValue'),debounceTime(1000), distinctUntilChanged())
  168.  
  169. let symbols = ['XBTUSD', 'ETHUSD'];
  170. let ratios$ = {}
  171. symbols.forEach((symbol) => {
  172. ratios$[symbol] = {}
  173. //const timeFilters = [60,3600]
  174. this.timeFilters.forEach((ratio) => {
  175. ratios$[symbol][ratio] = this.$echo.getVolumeInspectorUpdatedEvents(symbol, ratio, 1)
  176. });
  177. })
  178. const filteredRatios$ = this.$watchAsObservable('timeFilters').pipe(switchMap((res) => {
  179. console.log('r', res)
  180. let observableArray = []
  181. res.map((filter) => {
  182. if (filter.enabled) {
  183. observableArray.push(ratios$['XBTUSD'][filter.time_filter.seconds])
  184. }
  185. })
  186. return combineLatest(...observableArray)
  187. }),
  188. mergeAll(),
  189. tap(console.log),
  190. scan((acc, curr) => {
  191. if(!curr) return acc;
  192. if (curr.time_filter_seconds || false) {
  193. return {...acc, [curr.time_filter_seconds]: curr.stats}
  194. } else
  195. return acc
  196. }, {}
  197. )
  198. )
  199. filteredRatios$.subscribe((res) => console.log(res))
  200. }
  201. };
  202. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement