1.1 --- a/modules/lib.securities/src/org/aiotrade/lib/securities/Ticker.scala Fri Nov 06 01:44:53 2009 +0800
1.2 +++ b/modules/lib.securities/src/org/aiotrade/lib/securities/Ticker.scala Fri Nov 06 02:49:59 2009 +0800
1.3 @@ -184,11 +184,10 @@
1.4 if (values(PREV_CLOSE) == 0) 0f else (values(LAST_PRICE) - values(PREV_CLOSE)) / values(PREV_CLOSE) * 100f
1.5 }
1.6
1.7 - def compareLastCloseTo(prevTicker: Ticker) : Int = {
1.8 - if (values(LAST_PRICE) > prevTicker.values(LAST_PRICE)) 1
1.9 - else {
1.10 - if (values(LAST_PRICE) == prevTicker.values(LAST_PRICE)) 0 else 1
1.11 - }
1.12 + def compareLastCloseTo(prevTicker: Ticker): Int = {
1.13 + if (values(LAST_PRICE) > prevTicker.values(LAST_PRICE)) 1
1.14 + else if (values(LAST_PRICE) == prevTicker.values(LAST_PRICE)) 0
1.15 + else 1
1.16 }
1.17
1.18 override def clone: Ticker = {
2.1 --- a/modules/lib.securities/src/org/aiotrade/lib/securities/dataserver/TickerServer.scala Fri Nov 06 01:44:53 2009 +0800
2.2 +++ b/modules/lib.securities/src/org/aiotrade/lib/securities/dataserver/TickerServer.scala Fri Nov 06 02:49:59 2009 +0800
2.3 @@ -154,7 +154,7 @@
2.4 }
2.5
2.6 override protected def postStopUpdateServer: Unit = {
2.7 - for (tickerSnapshot <- symbolToTickerSnapshot.values) {
2.8 + for (tickerSnapshot <- symbolToTickerSnapshot.valuesIterator) {
2.9 tickerSnapshot.deleteObserver(this)
2.10 }
2.11 symbolToTickerSnapshot synchronized {
2.12 @@ -200,15 +200,13 @@
2.13 while (i >= 0 && i <= size - 1) {
2.14 ticker = storage(i)
2.15 ticker.time = (freq.round(ticker.time, cal))
2.16 - val prevTicker = symbolToPreviousTicker.get(symbol) match {
2.17 - case None =>
2.18 - val x = new Ticker
2.19 - symbolToPreviousTicker.put(symbol, x)
2.20 - x
2.21 - case Some(x) => x
2.22 + val prevTicker = symbolToPreviousTicker.get(symbol) getOrElse {
2.23 + val x = new Ticker
2.24 + symbolToPreviousTicker.put(symbol, x)
2.25 + x
2.26 }
2.27
2.28 - val item = symbolToIntervalLastTickerPair.get(symbol) match {
2.29 + symbolToIntervalLastTickerPair.get(symbol) match {
2.30 case None =>
2.31 /**
2.32 * this is today's first ticker we got when begin update data server,
2.33 @@ -218,7 +216,7 @@
2.34 symbolToIntervalLastTickerPair.put(symbol, intervalLastTickerPair)
2.35 intervalLastTickerPair.currIntervalOne.copy(ticker)
2.36
2.37 - val item1 = tickerSer.createItemOrClearIt(ticker.time).asInstanceOf[QuoteItem]
2.38 + val itemx = tickerSer.createItemOrClearIt(ticker.time).asInstanceOf[QuoteItem]
2.39
2.40 /**
2.41 * As this is the first data of today:
2.42 @@ -227,19 +225,18 @@
2.43 * so give it a small 0.0001 (if give it a 0, it will won't be calculated
2.44 * in calcMaxMin() of ChartView)
2.45 */
2.46 - item1.open = ticker(Ticker.LAST_PRICE)
2.47 - item1.high = ticker(Ticker.LAST_PRICE)
2.48 - item1.low = ticker(Ticker.LAST_PRICE)
2.49 - item1.close = ticker(Ticker.LAST_PRICE)
2.50 - item1.volume = 0.00001f
2.51 - item1
2.52 + itemx.open = ticker(Ticker.LAST_PRICE)
2.53 + itemx.high = ticker(Ticker.LAST_PRICE)
2.54 + itemx.low = ticker(Ticker.LAST_PRICE)
2.55 + itemx.close = ticker(Ticker.LAST_PRICE)
2.56 + itemx.volume = 0.00001F
2.57 + itemx
2.58
2.59 case Some(intervalLastTickerPair) =>
2.60 /** normal process */
2.61
2.62 /** check if in new interval */
2.63 - freq.sameInterval(ticker.time, intervalLastTickerPair.currIntervalOne.time, cal)
2.64 - val item1 = if (freq.sameInterval(ticker.time, intervalLastTickerPair.currIntervalOne.time, cal)) {
2.65 + val itemx = if (freq.sameInterval(ticker.time, intervalLastTickerPair.currIntervalOne.time, cal)) {
2.66 intervalLastTickerPair.currIntervalOne.copy(ticker)
2.67
2.68 /** still in same interval, just pick out the old data of this interval */
2.69 @@ -255,36 +252,36 @@
2.70 intervalLastTickerPair.currIntervalOne.copy(ticker)
2.71
2.72 /** a new interval starts, we'll need a new data */
2.73 - val item2 = tickerSer.createItemOrClearIt(ticker.time).asInstanceOf[QuoteItem]
2.74 + val itemxx = tickerSer.createItemOrClearIt(ticker.time).asInstanceOf[QuoteItem]
2.75
2.76 - item2.high = -Float.MaxValue
2.77 - item2.low = +Float.MaxValue
2.78 - item2.open = ticker(Ticker.LAST_PRICE)
2.79 - item2
2.80 + itemxx.high = -Float.MaxValue
2.81 + itemxx.low = +Float.MaxValue
2.82 + itemxx.open = ticker(Ticker.LAST_PRICE)
2.83 + itemxx
2.84 }
2.85
2.86 if (ticker(Ticker.DAY_HIGH) > prevTicker(Ticker.DAY_HIGH)) {
2.87 /** this is a new high happened in this ticker */
2.88 - item1.high = ticker(Ticker.DAY_HIGH)
2.89 + itemx.high = ticker(Ticker.DAY_HIGH)
2.90 }
2.91 - item1.high = Math.max(item1.high, ticker(Ticker.LAST_PRICE))
2.92 + itemx.high = Math.max(itemx.high, ticker(Ticker.LAST_PRICE))
2.93
2.94 if (prevTicker(Ticker.DAY_LOW) != 0) {
2.95 if (ticker(Ticker.DAY_LOW) < prevTicker(Ticker.DAY_LOW)) {
2.96 - /** this is a new low happened in this ticker */
2.97 - item1.low = ticker(Ticker.DAY_LOW)
2.98 + /** this is a new low that happened in this ticker */
2.99 + itemx.low = ticker(Ticker.DAY_LOW)
2.100 }
2.101 }
2.102 if (ticker(Ticker.LAST_PRICE) != 0) {
2.103 - item1.low = Math.min(item1.low, ticker(Ticker.LAST_PRICE))
2.104 + itemx.low = Math.min(itemx.low, ticker(Ticker.LAST_PRICE))
2.105 }
2.106
2.107 - item1.close = ticker(Ticker.LAST_PRICE)
2.108 + itemx.close = ticker(Ticker.LAST_PRICE)
2.109 val preVolume = intervalLastTickerPair.prevIntervalOne(Ticker.DAY_VOLUME)
2.110 if (preVolume > 1) {
2.111 - item1.volume = ticker(Ticker.DAY_VOLUME) - intervalLastTickerPair.prevIntervalOne(Ticker.DAY_VOLUME)
2.112 + itemx.volume = ticker(Ticker.DAY_VOLUME) - intervalLastTickerPair.prevIntervalOne(Ticker.DAY_VOLUME)
2.113 }
2.114 - item1
2.115 + itemx
2.116 }
2.117
2.118 prevTicker.copy(ticker)
2.119 @@ -295,7 +292,7 @@
2.120 i += 1
2.121 }
2.122
2.123 - val itemTime = item.time
2.124 + val itemTime = ticker.time
2.125 begTime = Math.min(begTime, itemTime)
2.126 endTime = Math.max(endTime, itemTime)
2.127
2.128 @@ -303,9 +300,9 @@
2.129 * Now, try to update today's quoteSer with current last ticker
2.130 */
2.131 for (chainSer <- chainSersOf(tickerSer)) {
2.132 - if (chainSer.freq.equals(TFreq.DAILY)) {
2.133 + if (chainSer.freq == TFreq.DAILY) {
2.134 updateDailyQuoteItem(chainSer.asInstanceOf[QuoteSer], ticker, cal)
2.135 - } else if (chainSer.freq.equals(TFreq.ONE_MIN)) {
2.136 + } else if (chainSer.freq == TFreq.ONE_MIN) {
2.137 updateMinuteQuoteItem(chainSer.asInstanceOf[QuoteSer], ticker, tickerSer.asInstanceOf[QuoteSer], cal)
2.138 }
2.139 }
2.140 @@ -322,18 +319,11 @@
2.141 * no new ticker got, but should consider if need to update quoteSer
2.142 * as the quote window may be just opened.
2.143 */
2.144 - symbolToPreviousTicker.get(symbol) match {
2.145 - case None =>
2.146 - case Some(ticker) =>
2.147 - val today = TUnit.Day.beginTimeOfUnitThatInclude(ticker.time, cal)
2.148 - for (ser <- chainSersOf(tickerSer)) {
2.149 - if (ser.freq.equals(TFreq.DAILY)) {
2.150 - if (ser.itemOf(today) != null) {
2.151 - updateDailyQuoteItem(ser.asInstanceOf[QuoteSer], ticker, cal)
2.152 - }
2.153 - }
2.154 - }
2.155 -
2.156 + symbolToPreviousTicker.get(symbol) foreach {ticker =>
2.157 + val today = TUnit.Day.beginTimeOfUnitThatInclude(ticker.time, cal)
2.158 + for (ser <- chainSersOf(tickerSer) if ser.freq == TFreq.DAILY && ser.exists(today)) {
2.159 + updateDailyQuoteItem(ser.asInstanceOf[QuoteSer], ticker, cal)
2.160 + }
2.161 }
2.162 }
2.163
2.164 @@ -370,13 +360,14 @@
2.165 */
2.166 private def updateMinuteQuoteItem(minuteSer: QuoteSer, ticker: Ticker, tickerSer: QuoteSer, cal: Calendar): Unit = {
2.167 val now = TUnit.Minute.beginTimeOfUnitThatInclude(ticker.time, cal)
2.168 + val tickerItem = tickerSer.itemOf(now).asInstanceOf[QuoteItem]
2.169 val itemNow = minuteSer.createItemOrClearIt(now).asInstanceOf[QuoteItem]
2.170
2.171 - itemNow.open = ticker(Ticker.DAY_OPEN)
2.172 - itemNow.high = ticker(Ticker.DAY_HIGH)
2.173 - itemNow.low = ticker(Ticker.DAY_LOW)
2.174 - itemNow.close = ticker(Ticker.LAST_PRICE)
2.175 - itemNow.volume = ticker(Ticker.DAY_VOLUME)
2.176 + itemNow.open = tickerItem.open
2.177 + itemNow.high = tickerItem.high
2.178 + itemNow.low = tickerItem.low
2.179 + itemNow.close = tickerItem.close
2.180 + itemNow.volume = tickerItem.volume
2.181
2.182 /** be ware of fromTime here may not be same as ticker's event */
2.183 val evt = new SerChangeEvent(minuteSer, SerChangeEvent.Type.Updated, "", now, now)