UNPKG

metaapi.cloud-sdk

Version:

SDK for MetaApi, a professional cloud forex API which includes MetaTrader REST API and MetaTrader websocket API. Supports both MetaTrader 5 (MT5) and MetaTrader 4 (MT4). CopyFactory copy trading API included. (https://metaapi.cloud)

36 lines (33 loc) 976 B
'use strict'; /** * Simplifies time amount converting large numeric values to small with larger unit, so it is easier to read * @param amount amount of time * @param unit time unit * @returns simplified time amount */ export function simplifyTimeAmount(amount: number, unit: 'ms' | 's' | 'm'): TimeAmount { if (unit === 'ms') { if (amount < 1000) { return {amount, unit, description: `${amount} ${amount === 1 ? 'millisecond' : 'milliseconds'}`}; } amount /= 1000; unit = 's'; } if (unit === 's') { if (amount < 60) { return {amount, unit, description: `${amount} ${amount === 1 ? 'second' : 'seconds'}`}; } amount /= 60; unit = 'm'; } return {amount, unit, description: `${amount} ${amount === 1 ? 'minute' : 'minutes'}`}; } /** Time amount */ export type TimeAmount = { /** Amount */ amount: number; /** Time unit */ unit: 'ms' | 's' | 'm'; /** Time amount text description */ description: string; };