-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue-192
- Loading branch information
Showing
11 changed files
with
246 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
indicator-backtest | ||
indicator-sync | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
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 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,60 @@ | ||
// Copyright (c) 2021-2024 Onur Cinar. | ||
// The source code is provided under GNU AGPLv3 License. | ||
// https://github.com/cinar/indicator | ||
|
||
package asset | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const ( | ||
// InMemoryRepositoryBuilderName is the name for the in memory repository builder. | ||
InMemoryRepositoryBuilderName = "memory" | ||
|
||
// FileSystemRepositoryBuilderName is the name for the file system repository builder. | ||
FileSystemRepositoryBuilderName = "filesystem" | ||
|
||
// TiingoRepositoryBuilderName is the name of the Tiingo repository builder. | ||
TiingoRepositoryBuilderName = "tiingo" | ||
) | ||
|
||
// RepositoryBuilderFunc defines a function to build a new repository using the given configuration parameter. | ||
type RepositoryBuilderFunc func(config string) (Repository, error) | ||
|
||
// repositoryBuilders provides mapping for the repository builders. | ||
var repositoryBuilders = map[string]RepositoryBuilderFunc{ | ||
InMemoryRepositoryBuilderName: inMemoryRepositoryBuilder, | ||
FileSystemRepositoryBuilderName: fileSystemRepositoryBuilder, | ||
TiingoRepositoryBuilderName: tiingoRepositoryBuilder, | ||
} | ||
|
||
// RegisterRepositoryBuilder registers the given builder. | ||
func RegisterRepositoryBuilder(name string, builder RepositoryBuilderFunc) { | ||
repositoryBuilders[name] = builder | ||
} | ||
|
||
// NewRepository builds a new repository by the given name type and the configuration. | ||
func NewRepository(name, config string) (Repository, error) { | ||
builder, ok := repositoryBuilders[name] | ||
if !ok { | ||
return nil, fmt.Errorf("unknown repository: %s", name) | ||
} | ||
|
||
return builder(config) | ||
} | ||
|
||
// inMemoryRepositoryBuilder builds a new in memory repository instance. | ||
func inMemoryRepositoryBuilder(_ string) (Repository, error) { | ||
return NewInMemoryRepository(), nil | ||
} | ||
|
||
// fileSystemRepositoryBuilder builds a new file system repository instance. | ||
func fileSystemRepositoryBuilder(config string) (Repository, error) { | ||
return NewFileSystemRepository(config), nil | ||
} | ||
|
||
// tiingoRepositoryBuilder builds a new Tiingo repository instance. | ||
func tiingoRepositoryBuilder(config string) (Repository, error) { | ||
return NewTiingoRepository(config), nil | ||
} |
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,77 @@ | ||
// Copyright (c) 2021-2024 Onur Cinar. | ||
// The source code is provided under GNU AGPLv3 License. | ||
// https://github.com/cinar/indicator | ||
|
||
package asset_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cinar/indicator/v2/asset" | ||
) | ||
|
||
func TestNewRepositoryUnknown(t *testing.T) { | ||
repository, err := asset.NewRepository("unknown", "") | ||
if err == nil { | ||
t.Fatalf("unknown repository: %T", repository) | ||
} | ||
} | ||
|
||
func TestRegisterRepositoryBuilder(t *testing.T) { | ||
builderName := "testbuilder" | ||
|
||
repository, err := asset.NewRepository(builderName, "") | ||
if err == nil { | ||
t.Fatalf("testbuilder is: %T", repository) | ||
} | ||
|
||
asset.RegisterRepositoryBuilder(builderName, func(_ string) (asset.Repository, error) { | ||
return asset.NewInMemoryRepository(), nil | ||
}) | ||
|
||
repository, err = asset.NewRepository(builderName, "") | ||
if err != nil { | ||
t.Fatalf("testbuilder is not found: %v", err) | ||
} | ||
|
||
_, ok := repository.(*asset.InMemoryRepository) | ||
if !ok { | ||
t.Fatalf("testbuilder is: %T", repository) | ||
} | ||
} | ||
|
||
func TestNewRepositoryMemory(t *testing.T) { | ||
repository, err := asset.NewRepository(asset.InMemoryRepositoryBuilderName, "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, ok := repository.(*asset.InMemoryRepository) | ||
if !ok { | ||
t.Fatalf("repository not correct type: %T", repository) | ||
} | ||
} | ||
|
||
func TestNewRepositoryFileSystem(t *testing.T) { | ||
repository, err := asset.NewRepository(asset.FileSystemRepositoryBuilderName, "testdata") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, ok := repository.(*asset.FileSystemRepository) | ||
if !ok { | ||
t.Fatalf("repository not correct type: %T", repository) | ||
} | ||
} | ||
|
||
func TestNewTiingoRepository(t *testing.T) { | ||
repository, err := asset.NewRepository(asset.TiingoRepositoryBuilderName, "1234") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, ok := repository.(*asset.TiingoRepository) | ||
if !ok { | ||
t.Fatalf("repository not correct type: %T", repository) | ||
} | ||
} |
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 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
Oops, something went wrong.