UNPKG

@copytrade/shared-types

Version:

Shared TypeScript types for CopyTrade application

221 lines (220 loc) 6.66 kB
/** * Shared Constants for CopyTrade Application * * This file contains all constants used across: * - Broker modules * - Unified broker module * - Backend services * - Frontend UI * - Database structures */ /** * Account authentication status enum * Used across database, API responses, and UI */ export declare const ACCOUNT_STATUS: { readonly ACTIVE: "ACTIVE"; readonly INACTIVE: "INACTIVE"; readonly PROCEED_TO_OAUTH: "PROCEED_TO_OAUTH"; }; export type AccountStatus = typeof ACCOUNT_STATUS[keyof typeof ACCOUNT_STATUS]; /** * Authentication flow steps * Used in broker connections and OAuth flows */ export declare const AUTHENTICATION_STEP: { readonly DIRECT_AUTH: "DIRECT_AUTH"; readonly OAUTH_REQUIRED: "OAUTH_REQUIRED"; readonly OAUTH_PENDING: "OAUTH_PENDING"; readonly ACTIVE: "ACTIVE"; readonly INACTIVE: "INACTIVE"; readonly EXPIRED: "EXPIRED"; readonly ERROR: "ERROR"; }; export type AuthenticationStep = typeof AUTHENTICATION_STEP[keyof typeof AUTHENTICATION_STEP]; /** * Supported broker names */ export declare const BROKER_NAMES: { readonly SHOONYA: "shoonya"; readonly FYERS: "fyers"; readonly ZERODHA: "zerodha"; readonly UPSTOX: "upstox"; readonly ANGEL_ONE: "angelone"; }; export type BrokerName = typeof BROKER_NAMES[keyof typeof BROKER_NAMES]; /** * Broker display names for UI */ export declare const BROKER_DISPLAY_NAMES: { readonly shoonya: "Shoonya (Finvasia)"; readonly fyers: "FYERS"; readonly zerodha: "Zerodha"; readonly upstox: "Upstox"; readonly angelone: "Angel One"; }; /** * Supported exchanges */ export declare const EXCHANGES: { readonly NSE: "NSE"; readonly BSE: "BSE"; readonly NFO: "NFO"; readonly BFO: "BFO"; readonly MCX: "MCX"; readonly CDS: "CDS"; readonly NIPO: "NIPO"; readonly BSTAR: "BSTAR"; }; export type Exchange = typeof EXCHANGES[keyof typeof EXCHANGES]; /** * Order actions */ export declare const ORDER_ACTION: { readonly BUY: "BUY"; readonly SELL: "SELL"; }; export type OrderAction = typeof ORDER_ACTION[keyof typeof ORDER_ACTION]; /** * Order types */ export declare const ORDER_TYPE: { readonly MARKET: "MARKET"; readonly LIMIT: "LIMIT"; readonly SL_LIMIT: "SL-LIMIT"; readonly SL_MARKET: "SL-MARKET"; }; export type OrderType = typeof ORDER_TYPE[keyof typeof ORDER_TYPE]; /** * Product types */ export declare const PRODUCT_TYPE: { readonly CNC: "CNC"; readonly MIS: "MIS"; readonly NRML: "NRML"; readonly BO: "BO"; readonly CO: "CO"; readonly C: "C"; readonly M: "M"; readonly H: "H"; readonly B: "B"; }; export type ProductType = typeof PRODUCT_TYPE[keyof typeof PRODUCT_TYPE]; /** * Order status */ export declare const ORDER_STATUS: { readonly SUBMITTED: "SUBMITTED"; readonly PLACED: "PLACED"; readonly PENDING: "PENDING"; readonly PARTIALLY_FILLED: "PARTIALLY_FILLED"; readonly EXECUTED: "EXECUTED"; readonly REJECTED: "REJECTED"; readonly CANCELLED: "CANCELLED"; readonly FAILED: "FAILED"; }; export type OrderStatus = typeof ORDER_STATUS[keyof typeof ORDER_STATUS]; /** * Standardized API error codes */ export declare const API_ERROR_CODE: { readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS"; readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND"; readonly BROKER_CONNECTION_FAILED: "BROKER_CONNECTION_FAILED"; readonly BROKER_ERROR: "BROKER_ERROR"; readonly VALIDATION_ERROR: "VALIDATION_ERROR"; readonly AUTHENTICATION_REQUIRED: "AUTHENTICATION_REQUIRED"; readonly OAUTH_ERROR: "OAUTH_ERROR"; readonly TOKEN_EXPIRED: "TOKEN_EXPIRED"; readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS"; readonly ORDER_REJECTED: "ORDER_REJECTED"; readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED"; readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR"; }; export type ApiErrorCode = typeof API_ERROR_CODE[keyof typeof API_ERROR_CODE]; /** * Standardized database field names * Used across MongoDB adapters */ export declare const DB_FIELDS: { readonly USER_ID: "user_id"; readonly EMAIL: "email"; readonly NAME: "name"; readonly PASSWORD: "password"; readonly CREATED_AT: "created_at"; readonly UPDATED_AT: "updated_at"; readonly BROKER_NAME: "broker_name"; readonly ACCOUNT_ID: "account_id"; readonly USER_NAME: "user_name"; readonly BROKER_DISPLAY_NAME: "broker_display_name"; readonly EXCHANGES: "exchanges"; readonly PRODUCTS: "products"; readonly ENCRYPTED_CREDENTIALS: "encrypted_credentials"; readonly ACCOUNT_STATUS: "account_status"; readonly TOKEN_EXPIRY_TIME: "token_expiry_time"; readonly BROKER_ORDER_ID: "broker_order_id"; readonly SYMBOL: "symbol"; readonly EXCHANGE: "exchange"; readonly ACTION: "action"; readonly QUANTITY: "quantity"; readonly ORDER_TYPE: "order_type"; readonly PRODUCT_TYPE: "product_type"; readonly PRICE: "price"; readonly TRIGGER_PRICE: "trigger_price"; readonly ORDER_STATUS: "order_status"; readonly EXECUTED_QUANTITY: "executed_quantity"; readonly EXECUTED_PRICE: "executed_price"; readonly ORDER_TIME: "order_time"; readonly EXECUTION_TIME: "execution_time"; readonly ERROR_MESSAGE: "error_message"; }; /** * Token expiry settings for different brokers */ export declare const TOKEN_EXPIRY: { readonly SHOONYA_HOURS: null; readonly FYERS_HOURS: 24; readonly DEFAULT_HOURS: 24; }; /** * Validation rules and limits */ export declare const VALIDATION: { readonly PASSWORD_MIN_LENGTH: 8; readonly PASSWORD_PATTERN: RegExp; readonly EMAIL_PATTERN: RegExp; readonly MAX_QUANTITY: 999999; readonly MIN_QUANTITY: 1; readonly MAX_PRICE: 999999.99; readonly MIN_PRICE: 0.01; }; /** * UI-specific constants */ export declare const UI_CONSTANTS: { readonly TOAST_DURATION: 5000; readonly POLLING_INTERVAL: 5000; readonly DEBOUNCE_DELAY: 300; readonly MAX_RETRY_ATTEMPTS: 3; readonly DEFAULT_PAGE_SIZE: 20; }; /** * Check if account status is active */ export declare const isAccountActive: (status: AccountStatus) => boolean; /** * Check if account requires OAuth */ export declare const requiresOAuth: (status: AccountStatus) => boolean; /** * Get broker display name */ export declare const getBrokerDisplayName: (brokerName: BrokerName) => string; /** * Check if order is in final state */ export declare const isOrderFinal: (status: OrderStatus) => boolean; /** * Get token expiry hours for broker */ export declare const getTokenExpiryHours: (brokerName: BrokerName) => number | null;