social-stock-sdk
v1.1.0
Published
TypeScript SDK for Social Stock Exchange - shared business logic for web and mobile
Downloads
29
Readme
Social Stock Exchange SDK
TypeScript SDK for Social Stock Exchange - shared business logic for web and mobile applications.
Installation
npm install social-stock-sdkFeatures
- 🏗️ Cross-platform compatible - Works in React Native, Next.js, and Node.js
- 🔒 Type-safe - Full TypeScript support with comprehensive type definitions
- 📊 Portfolio Management - Real-time portfolio calculations and metrics
- 💹 Exchange Integration - Direct communication with trading APIs
- 👥 User Management - Supabase integration for user profiles and social features
Quick Start
Exchange Client
import { createExchangeClient, ExchangeConfig } from 'social-stock-sdk';
const config: ExchangeConfig = {
baseURL: 'https://your-exchange-api.com',
readApiKey: 'your-read-key',
tradingApiKey: 'your-trading-key',
timeout: 10000
};
const exchangeClient = createExchangeClient(config);
// Get stock data
const stockData = await exchangeClient.getStockData('AAPL');
// Submit an order
const orderResult = await exchangeClient.submitOrder({
order_type: 'BUY',
stock_ticker: 'AAPL',
stock_amount: 10,
stock_price: 150.00
});Portfolio Calculator
import { createPortfolioCalculator, createSocialStockSupabaseClient } from 'social-stock-sdk';
// Create Supabase client
const supabaseClient = createSocialStockSupabaseClient({
url: 'your-supabase-url',
anonKey: 'your-supabase-anon-key'
});
// Create portfolio calculator
const portfolioCalculator = createPortfolioCalculator(supabaseClient.supabase);
// Calculate real-time portfolio metrics
const metrics = await portfolioCalculator.calculatePortfolioMetrics('user-uuid');User Management
import { createSocialStockSupabaseClient } from 'social-stock-sdk';
const client = createSocialStockSupabaseClient({
url: 'your-supabase-url',
anonKey: 'your-supabase-anon-key'
});
// Get user profile
const profile = await client.getUserProfile('user-uuid');
// Update profile
await client.updateUserProfile('user-uuid', {
bio_description: 'Updated bio'
});
// Friend management
await client.sendFriendRequest('user-id', 'target-username');
await client.acceptFriendRequest('user-id', 'requester-username');
const followers = await client.getFollowersList('user-id');
// Notifications
const notifications = await client.getNotifications('user-id');
await client.markNotificationRead('user-id', 0);
await client.markAllNotificationsRead('user-id');
// Search
const stockResults = await client.searchStocks('AAPL');
const userResults = await client.searchUsers('john');Architecture
The SDK is organized into modules:
Clients
- ExchangeClient - Direct API communication with trading systems
- SocialStockSupabaseClient - Database operations and user management
Utils
- PortfolioCalculator - Portfolio metrics and calculations
- Pending order utilities - Share availability and validation
Types
- Exchange Types - Stock data, orders, trade executions
- Portfolio Types - Positions, metrics, snapshots
- User Types - Profiles, notifications, social features
Usage in Different Environments
Web Application (Next.js)
// Replace your existing imports with SDK imports
import {
createExchangeClient,
createPortfolioCalculator,
ExchangeConfig
} from 'social-stock-sdk';
// Use environment variables
const exchangeConfig: ExchangeConfig = {
baseURL: process.env.EXCHANGE_API_URL!,
readApiKey: process.env.EXCHANGE_API_READ_KEY!,
tradingApiKey: process.env.EXCHANGE_API_TRADING_KEY!,
timeout: 10000
};Mobile Application (React Native)
import {
createExchangeClient,
createSocialStockSupabaseClient,
ExchangeConfig,
SupabaseConfig
} from 'social-stock-sdk';
// Configure clients
const exchangeConfig: ExchangeConfig = {
baseURL: 'https://your-api.com',
readApiKey: 'your-key',
tradingApiKey: 'your-trading-key',
timeout: 10000
};
const supabaseConfig: SupabaseConfig = {
url: 'your-supabase-url',
anonKey: 'your-anon-key'
};
// Create clients
const exchangeClient = createExchangeClient(exchangeConfig);
const dbClient = createSocialStockSupabaseClient(supabaseConfig);API Reference
ExchangeClient Methods
getStockData(ticker?: string)- Get stock market datagetMultipleStocks(tickers: string[])- Get data for multiple stocksgetOrderBook(ticker: string)- Get order book datasubmitOrder(orderData)- Submit trading ordercancelOrder(orderId: string)- Cancel pending orderhealthCheck()- Check API health
PortfolioCalculator Methods
calculatePortfolioMetrics(userUuid: string)- Real-time portfolio calculationscreatePortfolioSnapshot(userUuid: string)- Create portfolio snapshotgetPortfolioHistory(userUuid: string)- Get historical snapshotsupdateStockPriceCache(webhookData)- Update price cache from webhooks
SocialStockSupabaseClient Methods
User Management
createUserProfile(clerkUser)- Create user profile from Clerk datagetUserProfile(userId)- Get user profile by IDupdateUserProfile(userId, updates)- Update user profileupdateLastLogin(userId)- Update last login timestampuserExists(userId)- Check if user exists
Friend/Follower Management
getUserByUsername(username)- Find user by usernamesendFriendRequest(fromUserId, toUsername)- Send follow requestacceptFriendRequest(userId, fromUsername)- Accept friend requestrejectFriendRequest(userId, fromUsername)- Reject friend requestgetUsersByUsernames(usernames)- Get multiple users by usernamegetFollowersList(userId)- Get user's followers listgetFollowingList(userId)- Get user's following list
Notification Management
getNotifications(userId)- Get user notifications with unread countmarkNotificationRead(userId, index)- Mark specific notification as readmarkAllNotificationsRead(userId)- Mark all notifications as read
Search & Discovery
searchStocks(query)- Search for stocks by ticker or company namesearchUsers(query)- Search for users by username or name
Utility Functions
getPendingSellShares(dbClient, userUuid, ticker)- Get pending sell ordersgetAvailableSharesForSelling(dbClient, userUuid, ticker, currentShares)- Calculate available shares
Development
# Install dependencies
npm install
# Build the package
npm run build
# Watch for changes
npm run devVersion
Current version: 1.1.0
What's New in 1.1.0
- Complete Friend/Follower Management: Accept/reject friend requests, get followers/following lists
- Notification System: Full notification management with read/unread status
- User Discovery: Search for users and stocks within the SDK
- Enhanced Types: Comprehensive TypeScript interfaces for all new features
License
MIT
