-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: refactor and rename indicator.MACD to indicator.MACDLegacy
- Loading branch information
Showing
12 changed files
with
127 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package indicator | ||
|
||
//go:generate callbackgen -type Float64Updater | ||
type Float64Updater struct { | ||
updateCallbacks []func(v float64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package indicator | ||
|
||
import "github.com/c9s/bbgo/pkg/types" | ||
|
||
const MaxNumOfKLines = 4_000 | ||
|
||
//go:generate callbackgen -type KLineStream | ||
type KLineStream struct { | ||
updateCallbacks []func(k types.KLine) | ||
|
||
kLines []types.KLine | ||
} | ||
|
||
// AddSubscriber adds the subscriber function and push histrical data to the subscriber | ||
func (s *KLineStream) AddSubscriber(f func(k types.KLine)) { | ||
if len(s.kLines) > 0 { | ||
// push historical klines to the subscriber | ||
} | ||
|
||
s.OnUpdate(f) | ||
} | ||
|
||
// KLines creates a KLine stream that pushes the klines to the subscribers | ||
func KLines(source types.Stream) *KLineStream { | ||
s := &KLineStream{} | ||
|
||
source.OnKLineClosed(func(k types.KLine) { | ||
s.kLines = append(s.kLines, k) | ||
|
||
if len(s.kLines) > MaxNumOfKLines { | ||
s.kLines = s.kLines[len(s.kLines)-1-MaxNumOfKLines:] | ||
} | ||
s.EmitUpdate(k) | ||
}) | ||
|
||
return s | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package indicator | ||
|
||
import ( | ||
"github.com/c9s/bbgo/pkg/datatype/floats" | ||
"github.com/c9s/bbgo/pkg/types" | ||
) | ||
|
||
type KLineSource interface { | ||
OnUpdate(f func(k types.KLine)) | ||
} | ||
|
||
type PriceStream struct { | ||
types.SeriesBase | ||
Float64Updater | ||
|
||
slice floats.Slice | ||
mapper KLineValueMapper | ||
} | ||
|
||
func Price(source KLineSource, mapper KLineValueMapper) *PriceStream { | ||
s := &PriceStream{ | ||
mapper: mapper, | ||
} | ||
s.SeriesBase.Series = s.slice | ||
source.OnUpdate(func(k types.KLine) { | ||
v := s.mapper(k) | ||
s.slice.Push(v) | ||
s.EmitUpdate(v) | ||
}) | ||
return s | ||
} | ||
|
||
func ClosePrices(source KLineSource) *PriceStream { | ||
return Price(source, KLineClosePriceMapper) | ||
} | ||
|
||
func LowPrices(source KLineSource) *PriceStream { | ||
return Price(source, KLineLowPriceMapper) | ||
} | ||
|
||
func HighPrices(source KLineSource) *PriceStream { | ||
return Price(source, KLineHighPriceMapper) | ||
} | ||
|
||
func OpenPrices(source KLineSource) *PriceStream { | ||
return Price(source, KLineOpenPriceMapper) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters