|
|
@ -1,4 +1,4 @@ |
|
|
|
// Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved.
|
|
|
|
// Copyright (c) 2013-2015 by Michael Dvorkin. All Rights Reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style license that can
|
|
|
|
// Use of this source code is governed by a MIT-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
@ -18,6 +18,7 @@ type Sorter struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type sortable []Stock |
|
|
|
type sortable []Stock |
|
|
|
|
|
|
|
|
|
|
|
func (list sortable) Len() int { return len(list) } |
|
|
|
func (list sortable) Len() int { return len(list) } |
|
|
|
func (list sortable) Swap(i, j int) { list[i], list[j] = list[j], list[i] } |
|
|
|
func (list sortable) Swap(i, j int) { list[i], list[j] = list[j], list[i] } |
|
|
|
|
|
|
|
|
|
|
@ -53,37 +54,93 @@ type byDividendDesc struct { sortable } |
|
|
|
type byYieldDesc struct{ sortable } |
|
|
|
type byYieldDesc struct{ sortable } |
|
|
|
type byMarketCapDesc struct{ sortable } |
|
|
|
type byMarketCapDesc struct{ sortable } |
|
|
|
|
|
|
|
|
|
|
|
func (list byTickerAsc) Less(i, j int) bool { return list.sortable[i].Ticker < list.sortable[j].Ticker } |
|
|
|
func (list byTickerAsc) Less(i, j int) bool { |
|
|
|
func (list byLastTradeAsc) Less(i, j int) bool { return list.sortable[i].LastTrade < list.sortable[j].LastTrade } |
|
|
|
return list.sortable[i].Ticker < list.sortable[j].Ticker |
|
|
|
func (list byChangeAsc) Less(i, j int) bool { return c(list.sortable[i].Change) < c(list.sortable[j].Change) } |
|
|
|
} |
|
|
|
func (list byChangePctAsc) Less(i, j int) bool { return c(list.sortable[i].ChangePct) < c(list.sortable[j].ChangePct) } |
|
|
|
func (list byLastTradeAsc) Less(i, j int) bool { |
|
|
|
func (list byOpenAsc) Less(i, j int) bool { return list.sortable[i].Open < list.sortable[j].Open } |
|
|
|
return list.sortable[i].LastTrade < list.sortable[j].LastTrade |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byChangeAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return c(list.sortable[i].Change) < c(list.sortable[j].Change) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byChangePctAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return c(list.sortable[i].ChangePct) < c(list.sortable[j].ChangePct) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byOpenAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[i].Open < list.sortable[j].Open |
|
|
|
|
|
|
|
} |
|
|
|
func (list byLowAsc) Less(i, j int) bool { return list.sortable[i].Low < list.sortable[j].Low } |
|
|
|
func (list byLowAsc) Less(i, j int) bool { return list.sortable[i].Low < list.sortable[j].Low } |
|
|
|
func (list byHighAsc) Less(i, j int) bool { return list.sortable[i].High < list.sortable[j].High } |
|
|
|
func (list byHighAsc) Less(i, j int) bool { |
|
|
|
func (list byLow52Asc) Less(i, j int) bool { return list.sortable[i].Low52 < list.sortable[j].Low52 } |
|
|
|
return list.sortable[i].High < list.sortable[j].High |
|
|
|
func (list byHigh52Asc) Less(i, j int) bool { return list.sortable[i].High52 < list.sortable[j].High52 } |
|
|
|
} |
|
|
|
func (list byVolumeAsc) Less(i, j int) bool { return list.sortable[i].Volume < list.sortable[j].Volume } |
|
|
|
func (list byLow52Asc) Less(i, j int) bool { |
|
|
|
func (list byAvgVolumeAsc) Less(i, j int) bool { return list.sortable[i].AvgVolume < list.sortable[j].AvgVolume } |
|
|
|
return list.sortable[i].Low52 < list.sortable[j].Low52 |
|
|
|
func (list byPeRatioAsc) Less(i, j int) bool { return list.sortable[i].PeRatio < list.sortable[j].PeRatio } |
|
|
|
} |
|
|
|
func (list byDividendAsc) Less(i, j int) bool { return list.sortable[i].Dividend < list.sortable[j].Dividend } |
|
|
|
func (list byHigh52Asc) Less(i, j int) bool { |
|
|
|
func (list byYieldAsc) Less(i, j int) bool { return list.sortable[i].Yield < list.sortable[j].Yield } |
|
|
|
return list.sortable[i].High52 < list.sortable[j].High52 |
|
|
|
func (list byMarketCapAsc) Less(i, j int) bool { return m(list.sortable[i].MarketCap) < m(list.sortable[j].MarketCap) } |
|
|
|
} |
|
|
|
|
|
|
|
func (list byVolumeAsc) Less(i, j int) bool { |
|
|
|
func (list byTickerDesc) Less(i, j int) bool { return list.sortable[j].Ticker < list.sortable[i].Ticker } |
|
|
|
return list.sortable[i].Volume < list.sortable[j].Volume |
|
|
|
func (list byLastTradeDesc) Less(i, j int) bool { return list.sortable[j].LastTrade < list.sortable[i].LastTrade } |
|
|
|
} |
|
|
|
func (list byChangeDesc) Less(i, j int) bool { return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) } |
|
|
|
func (list byAvgVolumeAsc) Less(i, j int) bool { |
|
|
|
func (list byChangePctDesc) Less(i, j int) bool { return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) } |
|
|
|
return list.sortable[i].AvgVolume < list.sortable[j].AvgVolume |
|
|
|
func (list byOpenDesc) Less(i, j int) bool { return list.sortable[j].Open < list.sortable[i].Open } |
|
|
|
} |
|
|
|
|
|
|
|
func (list byPeRatioAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[i].PeRatio < list.sortable[j].PeRatio |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byDividendAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[i].Dividend < list.sortable[j].Dividend |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byYieldAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[i].Yield < list.sortable[j].Yield |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byMarketCapAsc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return m(list.sortable[i].MarketCap) < m(list.sortable[j].MarketCap) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (list byTickerDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].Ticker < list.sortable[i].Ticker |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byLastTradeDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].LastTrade < list.sortable[i].LastTrade |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byChangeDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byChangePctDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byOpenDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].Open < list.sortable[i].Open |
|
|
|
|
|
|
|
} |
|
|
|
func (list byLowDesc) Less(i, j int) bool { return list.sortable[j].Low < list.sortable[i].Low } |
|
|
|
func (list byLowDesc) Less(i, j int) bool { return list.sortable[j].Low < list.sortable[i].Low } |
|
|
|
func (list byHighDesc) Less(i, j int) bool { return list.sortable[j].High < list.sortable[i].High } |
|
|
|
func (list byHighDesc) Less(i, j int) bool { |
|
|
|
func (list byLow52Desc) Less(i, j int) bool { return list.sortable[j].Low52 < list.sortable[i].Low52 } |
|
|
|
return list.sortable[j].High < list.sortable[i].High |
|
|
|
func (list byHigh52Desc) Less(i, j int) bool { return list.sortable[j].High52 < list.sortable[i].High52 } |
|
|
|
} |
|
|
|
func (list byVolumeDesc) Less(i, j int) bool { return list.sortable[j].Volume < list.sortable[i].Volume } |
|
|
|
func (list byLow52Desc) Less(i, j int) bool { |
|
|
|
func (list byAvgVolumeDesc) Less(i, j int) bool { return list.sortable[j].AvgVolume < list.sortable[i].AvgVolume } |
|
|
|
return list.sortable[j].Low52 < list.sortable[i].Low52 |
|
|
|
func (list byPeRatioDesc) Less(i, j int) bool { return list.sortable[j].PeRatio < list.sortable[i].PeRatio } |
|
|
|
} |
|
|
|
func (list byDividendDesc) Less(i, j int) bool { return list.sortable[j].Dividend < list.sortable[i].Dividend } |
|
|
|
func (list byHigh52Desc) Less(i, j int) bool { |
|
|
|
func (list byYieldDesc) Less(i, j int) bool { return list.sortable[j].Yield < list.sortable[i].Yield } |
|
|
|
return list.sortable[j].High52 < list.sortable[i].High52 |
|
|
|
func (list byMarketCapDesc) Less(i, j int) bool { return m(list.sortable[j].MarketCap) < m(list.sortable[i].MarketCap) } |
|
|
|
} |
|
|
|
|
|
|
|
func (list byVolumeDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].Volume < list.sortable[i].Volume |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byAvgVolumeDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].AvgVolume < list.sortable[i].AvgVolume |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byPeRatioDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].PeRatio < list.sortable[i].PeRatio |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byDividendDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].Dividend < list.sortable[i].Dividend |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byYieldDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return list.sortable[j].Yield < list.sortable[i].Yield |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (list byMarketCapDesc) Less(i, j int) bool { |
|
|
|
|
|
|
|
return m(list.sortable[j].MarketCap) < m(list.sortable[i].MarketCap) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Returns new Sorter struct.
|
|
|
|
// Returns new Sorter struct.
|
|
|
|
func NewSorter(profile *Profile) *Sorter { |
|
|
|
func NewSorter(profile *Profile) *Sorter { |
|
|
|