diff --git a/realtime/src/app/realtime/index.types.d.ts b/realtime/src/app/realtime/index.types.d.ts index 1ef8f79..9d59ae6 100644 --- a/realtime/src/app/realtime/index.types.d.ts +++ b/realtime/src/app/realtime/index.types.d.ts @@ -1,6 +1,6 @@ type RefreshRealtimeDataArgs = { currency: CurrencyCode - exchange: ExchangeConfig + exchange: DevExchangeConfig | ExchangeConfig } type RefreshDataCallbackArgs = { diff --git a/realtime/src/app/realtime/start-watchers.ts b/realtime/src/app/realtime/start-watchers.ts index 0717418..eae4a43 100644 --- a/realtime/src/app/realtime/start-watchers.ts +++ b/realtime/src/app/realtime/start-watchers.ts @@ -25,7 +25,7 @@ const startWatcher = async ({ callback, }: { currency: CurrencyCode - exchange: ExchangeConfig + exchange: DevExchangeConfig | ExchangeConfig callback?: RefreshDataCallback }): Promise => { const task = async () => { diff --git a/realtime/src/config/index.types.d.ts b/realtime/src/config/index.types.d.ts index 21ee954..1087894 100644 --- a/realtime/src/config/index.types.d.ts +++ b/realtime/src/config/index.types.d.ts @@ -6,7 +6,7 @@ type RawExchangeConfig = { quoteAlias: string[] provider: string cron: string - config: { [key: string]: string | number | boolean } + config: { [key: string]: string | number | boolean } | MockedConfig } type PartialExchangeConfig = { diff --git a/realtime/src/config/yaml.ts b/realtime/src/config/yaml.ts index 62facfb..1b9e733 100644 --- a/realtime/src/config/yaml.ts +++ b/realtime/src/config/yaml.ts @@ -69,7 +69,7 @@ export const supportedCurrencies: FiatCurrency[] = yamlConfig.quotes.map((q) => export const defaultBaseCurrency: CurrencyCode = yamlConfig.base export const defaultQuoteCurrency: FiatCurrency = supportedCurrencies[0] -export const getExchangesConfig = (): ExchangeConfig[] => { +export const getExchangesConfig = (): (DevExchangeConfig | ExchangeConfig)[] => { // Set dev mode if dev config is present if (yamlConfig.exchanges.find((e) => e.provider === "dev-mock")) { yamlConfig.exchanges = yamlConfig.exchanges.filter((e) => e.provider === "dev-mock") @@ -98,19 +98,27 @@ export const getExchangesConfig = (): ExchangeConfig[] => { } }) - const rawExchangesConfig: ExchangeConfig[] = [] + const rawExchangesConfig: (DevExchangeConfig | ExchangeConfig)[] = [] for (const config of enabledRawExchangesConfig) { const newConfig = config.quote - .map((q, i) => ({ - ...config, - quote: q, - quoteAlias: config.quoteAlias[i], - })) + .map((q, i) => + typeof config.config === "object" && "devMockPrice" in config.config + ? ({ + ...config, + quote: q, + quoteAlias: config.quoteAlias[i], + } as DevExchangeConfig) + : ({ + ...config, + quote: q, + quoteAlias: config.quoteAlias[i], + } as ExchangeConfig), + ) .filter((c) => c.base !== c.quote) rawExchangesConfig.push(...newConfig) } - const exchangesConfig: ExchangeConfig[] = [] + const exchangesConfig: (DevExchangeConfig | ExchangeConfig)[] = [] for (const config of rawExchangesConfig) { let newConfigs = [config] if (config.quote === "*" || config.quoteAlias === "*") { diff --git a/realtime/src/domain/exchanges/index.types.d.ts b/realtime/src/domain/exchanges/index.types.d.ts index 230bf5f..6626631 100644 --- a/realtime/src/domain/exchanges/index.types.d.ts +++ b/realtime/src/domain/exchanges/index.types.d.ts @@ -16,5 +16,7 @@ interface IExchangeService { } type ExchangeFactory = { - create(config: ExchangeConfig): Promise + create( + config: DevExchangeConfig | ExchangeConfig, + ): Promise }