types: Add TradeWith helper

This commit is contained in:
c9s 2023-06-06 16:57:38 +08:00
parent b90564be90
commit 9f5ef21dda
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -627,6 +627,16 @@ func (k *KLineSeries) Length() int {
var _ Series = &KLineSeries{} var _ Series = &KLineSeries{}
func TradeWith(symbol string, f func(trade Trade)) func(trade Trade) {
return func(trade Trade) {
if symbol != "" && trade.Symbol != symbol {
return
}
f(trade)
}
}
func KLineWith(symbol string, interval Interval, callback KLineCallback) KLineCallback { func KLineWith(symbol string, interval Interval, callback KLineCallback) KLineCallback {
return func(k KLine) { return func(k KLine) {
if k.Symbol != symbol || (k.Interval != "" && k.Interval != interval) { if k.Symbol != symbol || (k.Interval != "" && k.Interval != interval) {