UNPKG

@cranberry-money/shared-services

Version:

Platform-agnostic API services with pure functions and dependency injection. Includes auth, portfolios, assets, countries, sectors, and more.

124 lines 6.17 kB
import { ARCA_ENDPOINTS } from '@cranberry-money/shared-constants'; export const getShareTokens = (apiClient) => apiClient.get(ARCA_ENDPOINTS.TOKENS.LIST); export const getShareToken = (apiClient, uuid) => apiClient.get(ARCA_ENDPOINTS.TOKENS.DETAIL(uuid)); export const getOrderBook = (apiClient, tokenUuid) => apiClient.get(ARCA_ENDPOINTS.TOKENS.ORDER_BOOK(tokenUuid)); export const getMarketData = (apiClient, tokenUuid) => apiClient.get(ARCA_ENDPOINTS.TOKENS.MARKET_DATA(tokenUuid)); export const getOrders = (apiClient, params) => apiClient.get(ARCA_ENDPOINTS.ORDERS.LIST, { params }); export const getOrder = (apiClient, uuid) => apiClient.get(ARCA_ENDPOINTS.ORDERS.DETAIL(uuid)); export const getOpenOrders = (apiClient, tokenUuid) => apiClient.get(ARCA_ENDPOINTS.ORDERS.LIST, { params: { token: tokenUuid, status: 'OPEN' }, }); export const getUserOrders = (apiClient, walletAddress) => apiClient.get(ARCA_ENDPOINTS.ORDERS.LIST, { params: { wallet_address: walletAddress }, }); export const getOrderCreateMessage = (apiClient, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.CREATE_MESSAGE, { token: data.token, order_type: data.orderType.toLowerCase(), wallet_address: data.walletAddress, quantity: data.quantity, min_quantity: data.minQuantity ?? 0, price_per_share: data.pricePerShare, }); export const getOrderCancelMessage = (apiClient, uuid) => apiClient.get(ARCA_ENDPOINTS.ORDERS.CANCEL_MESSAGE(uuid)); export const createOrder = (apiClient, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.CREATE, { token: data.token, order_type: data.orderType.toLowerCase(), wallet_address: data.walletAddress, quantity: data.quantity, min_quantity: data.minQuantity ?? 0, price_per_share: data.pricePerShare, message: data.message, signature: data.signature, }); export const cancelOrder = (apiClient, uuid, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.CANCEL(uuid), { message: data.message, signature: data.signature, }); export const getWalletBalances = (apiClient, walletAddress) => apiClient.get(ARCA_ENDPOINTS.WALLETS.BALANCES, { params: { wallet_address: walletAddress }, }); // ============================================================================ // Direct Share Token Transfer Functions // ============================================================================ /** * Prepare a direct share token transfer. * Returns unsigned transaction data for signing. */ export const prepareShareTokenTransfer = (apiClient, data) => apiClient.post(ARCA_ENDPOINTS.TRANSFERS.PREPARE, data); /** * Broadcast a signed share token transfer transaction. */ export const broadcastShareTokenTransfer = (apiClient, signedTx) => apiClient.post(ARCA_ENDPOINTS.TRANSFERS.BROADCAST, { signed_transaction: signedTx, }); export const getWhitelistStatus = (apiClient, walletAddress) => apiClient.get(ARCA_ENDPOINTS.WHITELIST.STATUS(walletAddress)); export const getSwapOrders = (apiClient, walletAddress) => apiClient.get(ARCA_ENDPOINTS.SWAPS.LIST, { params: { wallet_address: walletAddress }, }); export const getOrderSwapData = (apiClient, orderUuid, params) => apiClient.get(ARCA_ENDPOINTS.ORDERS.SWAP(orderUuid), { params: { wallet_address: params.walletAddress }, }); export const submitOrderSwapSignature = (apiClient, orderUuid, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.SWAP_SIGN(orderUuid), { signature: data.signature, signer_address: data.signerAddress, }); export const getOrderSwapApprovalStatus = (apiClient, orderUuid, walletAddress) => apiClient.get(ARCA_ENDPOINTS.ORDERS.SWAP_APPROVAL_STATUS(orderUuid), { params: { wallet_address: walletAddress }, }); export const getOrderSwapApprovalData = (apiClient, orderUuid, walletAddress) => apiClient.get(ARCA_ENDPOINTS.ORDERS.SWAP_APPROVAL_DATA(orderUuid), { params: { wallet_address: walletAddress }, }); // ============================================================================ // Order Modification Functions // ============================================================================ /** * Get a modification message for signing. * This is step 1 of the two-step modification flow. */ export const getOrderModificationMessage = (apiClient, orderUuid, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.MODIFY_MESSAGE(orderUuid), { new_quantity: data.newQuantity, new_min_quantity: data.newMinQuantity, new_price_per_share: data.newPricePerShare, }); /** * Execute an order modification with a signed message. * This is step 2 of the two-step modification flow. */ export const modifyOrder = (apiClient, orderUuid, data) => apiClient.post(ARCA_ENDPOINTS.ORDERS.MODIFY(orderUuid), { message: data.message, signature: data.signature, }); /** * Get the modification history for an order. */ export const getOrderModificationHistory = (apiClient, orderUuid) => apiClient.get(ARCA_ENDPOINTS.ORDERS.MODIFICATIONS(orderUuid)); export function parseArcaError(error) { if (!error) return 'An unknown error occurred'; const axiosError = error; if (axiosError.response?.data) { const data = axiosError.response.data; if (data.code === 'not_whitelisted') { return 'Your wallet is not verified for trading. Please complete KYC verification to trade tokenized securities.'; } if (data.detail) { if (data.detail.includes('not whitelisted')) { return 'Your wallet is not verified for trading. Please complete KYC verification to trade tokenized securities.'; } return data.detail; } if (data.message) return data.message; } if (axiosError.response?.status === 403) { return 'Your wallet is not authorized to trade. Please ensure your wallet is verified and whitelisted.'; } if (axiosError.message) { if (axiosError.message.includes('403')) { return 'Your wallet is not authorized to trade. Please ensure your wallet is verified and whitelisted.'; } return axiosError.message; } return 'An error occurred while processing your request'; } //# sourceMappingURL=trading.js.map