Socket
Socket
Sign inDemoInstall

@fugle/marketdata-nest

Package Overview
Dependencies
32
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @fugle/marketdata-nest

A Nest module wrapper for @fugle/marketdata


Version published
Weekly downloads
20
increased by300%
Maintainers
4
Created
Weekly downloads
 

Readme

Source

@fugle/marketdata-nest

NPM version

A Nest module wrapper for @fugle/marketdata

Installation

To begin using it, we first install the required dependencies.

$ npm install --save @fugle/marketdata-nest @fugle/marketdata

Getting started

Once the installation is complete, to use the RestClient or WebSocketClient, first import FugleMarketDataModule and pass the options with apiKey to the forRoot() method.

import { Module } from '@nestjs/common';
import { FugleMarketDataModule } from '@fugle/marketdata-nest';

@Module({
  imports: [
    FugleMarketDataModule.forRoot({
      apiKey: 'YOUR_API_KEY',
    }),
  ],
})
export class AppModule {}

Next, inject the RestClient instance using the @InjectRestClient() decorator.

constructor(@InjectRestClient() private readonly client: RestClient) {}

The @InjectWebSocketClient() decorator is used for the WebSocketClient instance injection.

constructor(@InjectWebSocketClient() private readonly client: WebSocketClient) {}

Async configuration

When you need to pass module options asynchronously instead of statically, use the forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.

One technique is to use a factory function:

FugleMarketDataModule.forRootAsync({
  useFactory: () => ({
    apiKey: 'YOUR_API_KEY',
  }),
});

Like other factory providers, our factory function can be async and can inject dependencies through inject.

FugleMarketDataModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    apiKey: configService.get('FUGLE_MARKETDATA_API_KEY'),
  }),
  inject: [ConfigService],
});

Alternatively, you can configure the FugleMarketDataModule using a class instead of a factory, as shown below.

FugleMarketDataModule.forRootAsync({
  useClass: FugleMarketDataConfigService,
});

The construction above instantiates FugleMarketDataConfigService inside FugleMarketDataModule, using it to create an options object. Note that in this example, the FugleMarketDataConfigService has to implement FugleMarketDataModuleOptionsFactory interface as shown below. The FugleMarketDataModule will call the createFugleMarketDataOptions() method on the instantiated object of the supplied class.

@Injectable()
class FugleMarketDataConfigService implements FugleMarketDataModuleOptionsFactory {
  createFugleMarketDataOptions(): FugleMarketDataModuleOptions {
    return {
      apiKey: 'YOUR_API_KEY',
    };
  }
}

If you want to reuse an existing options provider instead of creating a private copy inside the FugleMarketDataModule, use the useExisting syntax.

FugleMarketDataModule.forRootAsync({
  imports: [ConfigModule],
  useExisting: FugleMarketDataConfigService,
});

Reference

License

MIT

Keywords

FAQs

Last updated on 01 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc