Documentation ¶
Index ¶
Constants ¶
View Source
const StreamName = "finance"
Variables ¶
View Source
var Module = fx.Options( fx.Provide( func() (supplier.Marketdata, supplier.Trading, error) { if environment.GetAlpacaAPIKey() == "" || environment.GetAlpacaAPISecret() == "" { marketData, err := marketdata.NewYahooClient() if err != nil { return nil, nil, fmt.Errorf("failed to create Yahoo client: %w", err) } return marketData, nil, nil } marketData, err := marketdata.NewAlpacaClient() if err != nil { return nil, nil, fmt.Errorf("failed to create Alpaca client: %w", err) } t, err := trading.NewAlpacaClient() if err != nil { return nil, nil, fmt.Errorf("failed to create Alpaca client: %w", err) } return marketData, t, nil }, func(jt nats.JetStreamContext, conn *pgxpool.Pool, marketData supplier.Marketdata) (Stream, error) { dc := stream.NewDependencyContainer() dc.AddSingleton(stream.DBDep, conn) dc.AddSingleton(dependency.MarketDataDep, marketData) s, err := stream.NewNATSStream(jt, StreamName, dc, conn) if err != nil { return nil, fmt.Errorf("failed to create stream: %w", err) } return s, nil }, ), fx.Invoke( func(s *grpc.Server, pgx *pgxpool.Pool, md supplier.Marketdata, t supplier.Trading) error { marketdata := servicer.NewMarketdataServer(pgx, md) pb.RegisterMarketdataServer(s, marketdata) trading := servicer.NewTradingServer(pgx, t) pb.RegisterTradingServer(s, trading) return nil }, func(conn *pgxpool.Pool) error { return repository.CreateTables(context.Background(), conn) }, func(lc fx.Lifecycle, stream Stream) error { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { err := stream.CommandSubscriber("marketdata", "ingest", command.Ingest) if err != nil { return fmt.Errorf("failed to subscribe to ingest command: %w", err) } return nil }, OnStop: func(ctx context.Context) error { return stream.Unsubscribe() }, }) return nil }, ), )
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.