@apexfintechsolutions/ascend-sdk
v1.8.2
Published
Apex Ascend SDK
Keywords
Readme
Introducing the Apex Typescript SDK
In today's fast-paced digital ecosystem, developers need tools that not only streamline the development process but also unlock new possibilities for innovation and efficiency.
Enter the Apex Typescript SDK, a cutting-edge software development kit designed to empower fintech app developers like never before. With our SDK, you can more easily integrate new account creation, optimize trading, and elevate your applications with realtime buying power, all through a seamless SDK interface.
Whether you're building complex, data-driven platforms or simplified, user-centric applications, Apex Typescript SDK was created to offer the flexibility, power, and ease of use to bring your visions to life faster and more effectively. Join us in redefining the boundaries of what your applications can achieve. Start your journey with Apex today.
SDK Installation
NPM
npm add @apexfintechsolutions/ascend-sdkPNPM
pnpm add @apexfintechsolutions/ascend-sdkBun
bun add @apexfintechsolutions/ascend-sdkYarn
yarn add @apexfintechsolutions/ascend-sdk zod
# Note that Yarn does not install peer dependencies automatically. You will need
# to install zod as shown above.Supported JavaScript Runtimes
This SDK is intended to be used in JavaScript runtimes that support the following features:
- Web Fetch API
- Web Streams API and in particular
ReadableStream - Async iterables using
Symbol.asyncIterator
Runtime environments that are explicitly supported are:
- Evergreen browsers which include: Chrome, Safari, Edge, Firefox
- Node.js active and maintenance LTS releases
- Currently, this is v18 and v20
- Bun v1 and above
- Deno v1.39
- Note that Deno does not currently have native support for streaming file uploads backed by the filesystem (issue link)
Initializing the SDK
The following sample shows how to initialise the SDK, using the API Key and Service Account Credentials you received during sign-up:
import {Apexascend} from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend({
security: {
apiKey: "ABCDEFGHIJ0123456789abcdefghij0123456789",
serviceAccountCreds: {
privateKey: "-----BEGIN PRIVATE KEY--{OMITTED FOR BREVITY}",
name: "FinFirm",
organization: "correspondents/00000000-0000-0000-0000-000000000000",
type: "serviceAccount",
},
},
});
async function run() {
// With an instance of the SDK, invoke any operation e.g.
let resp = await apexascend.accountCreation.getAccount("VALID_ACCOUNT_ID");
console.log(resp);
}
run();Error Handling
ApexascendError is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
| ------------------------- | ---------- | --------------------------------------------------------------------------------------- |
| error.message | string | Error message |
| error.httpMeta.response | Response | HTTP response. Access to headers and more. |
| error.httpMeta.request | Request | HTTP request. Access to headers and more. |
| error.data$ | | Optional. Some errors may contain structured data. See Error Classes. |
Example
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
import * as errors from "@apexfintechsolutions/ascend-sdk/models/errors";
const apexascend = new Apexascend({
security: {
apiKey: "ABCDEFGHIJ0123456789abcdefghij0123456789",
serviceAccountCreds: {
privateKey: "-----BEGIN PRIVATE KEY--{OMITTED FOR BREVITY}",
name: "FinFirm",
organization: "correspondents/00000000-0000-0000-0000-000000000000",
type: "serviceAccount",
},
},
});
async function run() {
try {
const result = await apexascend.accountCreation.getAccount(
"01HC3MAQ4DR9QN1V8MJ4CN1HMK",
);
console.log(result);
} catch (error) {
// The base class for HTTP error responses
if (error instanceof errors.ApexascendError) {
console.log(error.message);
console.log(error.httpMeta.response.status);
console.log(error.httpMeta.response.headers);
console.log(error.httpMeta.request);
// Depending on the method different errors may be thrown
if (error instanceof errors.Status) {
console.log(error.data$.code); // number
console.log(error.data$.details); // Any[]
console.log(error.data$.message); // string
}
}
}
}
run();
Error Classes
Primary errors:
ApexascendError: The base class for HTTP error responses.Status: The status message serves as the general-purpose service error message. Each status message includes a gRPC error code, error message, and error details.
Network errors:
ConnectionError: HTTP client was unable to make a request to a server.RequestTimeoutError: HTTP request timed out due to an AbortSignal signal.RequestAbortedError: HTTP request was aborted by the client.InvalidRequestError: Any input used to create a request is invalid.UnexpectedClientError: Unrecognised or unexpected error.
Inherit from ApexascendError:
ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. Seeerror.rawValuefor the raw value anderror.pretty()for a nicely formatted multi-line string.
Server Selection
Select Server by Name
You can override the default server globally by passing a server name to the server: keyof typeof ServerList optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
| Name | Server | Description |
| ------ | -------------------------- | -------------------------- |
| uat | https://uat.apexapis.com | our uat environment |
| prod | https://api.apexapis.com | our production environment |
| sbx | https://sbx.apexapis.com | our sandbox environment |
Example
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend({
server: "sbx",
security: {
apiKey: "ABCDEFGHIJ0123456789abcdefghij0123456789",
serviceAccountCreds: {
privateKey: "-----BEGIN PRIVATE KEY--{OMITTED FOR BREVITY}",
name: "FinFirm",
organization: "correspondents/00000000-0000-0000-0000-000000000000",
type: "serviceAccount",
},
},
});
async function run() {
const result = await apexascend.accountCreation.getAccount(
"01HC3MAQ4DR9QN1V8MJ4CN1HMK",
);
console.log(result);
}
run();
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend({
serverURL: "https://uat.apexapis.com",
security: {
apiKey: "ABCDEFGHIJ0123456789abcdefghij0123456789",
serviceAccountCreds: {
privateKey: "-----BEGIN PRIVATE KEY--{OMITTED FOR BREVITY}",
name: "FinFirm",
organization: "correspondents/00000000-0000-0000-0000-000000000000",
type: "serviceAccount",
},
},
});
async function run() {
const result = await apexascend.accountCreation.getAccount(
"01HC3MAQ4DR9QN1V8MJ4CN1HMK",
);
console.log(result);
}
run();
Custom HTTP Client
The TypeScript SDK makes API calls using an HTTPClient that wraps the native
Fetch API. This
client is a thin wrapper around fetch and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.
The HTTPClient constructor takes an optional fetcher argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.
The following example shows how to use the "beforeRequest" hook to to add a
custom header and a timeout to requests and how to use the "requestError" hook
to log errors:
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
import { HTTPClient } from "@apexfintechsolutions/ascend-sdk/lib/http";
const httpClient = new HTTPClient({
// fetcher takes a function that has the same signature as native `fetch`.
fetcher: (request) => {
return fetch(request);
}
});
httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request, {
signal: request.signal || AbortSignal.timeout(5000)
});
nextRequest.headers.set("x-custom-header", "custom value");
return nextRequest;
});
httpClient.addHook("requestError", (error, request) => {
console.group("Request Error");
console.log("Reason:", `${error}`);
console.log("Endpoint:", `${request.method} ${request.url}`);
console.groupEnd();
});
const sdk = new Apexascend({ httpClient });Available Resources and Operations
accountCreation
- createAccount - Create Account
- getAccount - Get Account
accountManagement
- listAccounts - List Accounts
- updateAccount - Update Account
- addParty - Add Party
- updateParty - Update Party
- replaceParty - Replace Party
- removeParty - Remove Party
- closeAccount - Close Account
- createTrustedContact - Create Trusted Contact
- updateTrustedContact - Update Trusted Contact
- deleteTrustedContact - Delete Trusted Contact
- createInterestedParty - Create Interested Party
- updateInterestedParty - Update Interested Party
- deleteInterestedParty - Delete Interested Party
- listAvailableRestrictions - List Available Restrictions
- createRestriction - Create Restriction
- endRestriction - End Restriction
accountTransfers
- createTransfer - Create Transfer
- listTransfers - List Transfers
- acceptTransfer - Accept Transfer
- rejectTransfer - Reject Transfer
- getTransfer - Get Transfer
achTransfers
- createAchDeposit - Create ACH Deposit
- getAchDeposit - Get ACH Deposit
- cancelAchDeposit - Cancel ACH Deposit
- createAchWithdrawal - Create ACH Withdrawal
- getAchWithdrawal - Get ACH Withdrawal
- cancelAchWithdrawal - Cancel ACH Withdrawal
assets
- listAssets - List Assets
- getAsset - Get Asset
- listAssetsCorrespondent - List Assets (By Correspondent)
- getAssetCorrespondent - Get Asset (By Correspondent)
assetTradingConfig
- getAssetTradingConfig - Get Asset Trading Config
- listAssetTradingConfigs - List Asset Trading Configs
authentication
- generateServiceAccountToken - Generate Service Account Token
- listSigningKeys - List Signing Keys
bankRelationships
- createBankRelationship - Create Bank Relationship
- listBankRelationships - List Bank Relationships
- getBankRelationship - Get Bank Relationship
- updateBankRelationship - Update Bank Relationship
- cancelBankRelationship - Cancel Bank Relationship
- verifyMicroDeposits - Verify Micro Deposits
- reissueMicroDeposits - Reissue Micro Deposits
- reuseBankRelationship - Reuse Bank Relationship
basketOrders
- createBasket - Create Basket
- addOrders - Add Orders
- getBasket - Get Basket
- submitBasket - Submit Basket
- listBasketOrders - List Basket Orders
- listCompressedOrders - List Compressed Orders
- removeOrders - Remove Basket Orders
- setExtraReportingData - Set Extra Reporting Data
cashBalances
- calculateCashBalance - Get Cash Balance
checks
- getCheckDeposit - Get Check Deposit
dataRetrieval
- listSnapshots - List Snapshots
enrollmentsAndAgreements
- enrollAccount - Enroll Account
- listAvailableEnrollments - List Available Enrollments
- accountsListAvailableEnrollmentsByAccountGroup - List Available Enrollments (by Account Group)
- deactivateEnrollment - Deactivate Enrollment
- listEnrollments - List Account Enrollments
- affirmAgreements - Affirm Agreements
- listAgreements - List Account Agreements
- listEntitlements - List Account Entitlements
feesAndCredits
- createFee - Create Fee
- getFee - Get Fee
- cancelFee - Cancel Fee
- createCredit - Create Credit
- getCredit - Get Credit
- cancelCredit - Cancel Credit
fixedIncomePricing
- previewOrderCost - Preview Order Cost
- retrieveQuote - Retrieve Quote
- retrieveFixedIncomeMarks - Retrieve Fixed Income Marks
instantCashTransferICT
- createIctDeposit - Create ICT Deposit
- getIctDeposit - Get ICT Deposit
- cancelIctDeposit - Cancel ICT Deposit
- createIctWithdrawal - Create ICT Withdrawal
- getIctWithdrawal - Get ICT Withdrawal
- cancelIctWithdrawal - Cancel ICT Withdrawal
- locateIctReport - Locate ICT Report
investigations
- getInvestigation - Get Investigations
- updateInvestigation - Update Investigation
- listInvestigations - List Investigations
- linkDocuments - Link Documents
- getWatchlistItem - Get Watchlist Item
- getCustomerIdentification - Get Identity Verification
- createIdentityLookup - Create Identity Lookup
- verifyIdentityLookup - Verify Identity Lookup
investorDocs
- batchCreateUploadLinks - Batch Create Upload Links
- listDocuments - List Documents
journals
- retrieveCashJournalConstraints - Retrieve Cash Journal Constraints
- createCashJournal - Create Cash Journal
- getCashJournal - Get Cash Journal
- cancelCashJournal - Cancel Cash Journal
- checkPartyType - Retrieve Cash Journal Party
ledger
- listEntries - List Entries
- listActivities - List Activities
- listPositions - List Positions
- getActivity - Get Activity
- getEntry - Get Entry
margins
- getBuyingPower - Get Buying Power
orders
- createOrder - Create Order
- getOrder - Get Order
- cancelOrder - Cancel Order
- setExtraReportingData - Set Extra Reporting Data
- listCorrespondentOrders - List Correspondent Orders
personManagement
- createLegalNaturalPerson - Create Legal Natural Person
- listLegalNaturalPersons - List Legal Natural Persons
- getLegalNaturalPerson - Get Legal Natural Persons
- updateLegalNaturalPerson - Update Legal Natural Person
- assignLargeTrader - Assign Large Trader
- endLargeTraderLegalNaturalPerson - End Large Trader
- createLegalEntity - Create Legal Entity
- listLegalEntities - List Legal Entity
- getLegalEntity - Get Legal Entity
- updateLegalEntity - Update Legal Entity
- assignLargeTraderLegalEntity - Assign Entity Large Trader
- endLargeTrader - End Entity Large Trader
positionJournals
- createPositionJournal - Create Position Journal
- getPositionJournal - Get Position Journal
- cancelPositionJournal - Cancel Position Journal
reader
- listEventMessages - List Event Messages
- getEventMessage - Get Event Message
retirements
- listContributionSummaries - List Contribution Summaries
- retrieveContributionConstraints - Retrieve Contribution Constraints
- listDistributionSummaries - List Distribution Summaries
- retrieveDistributionConstraints - Retrieve Distribution Constraints
scheduleTransfers
- listScheduleSummaries - List Schedule Summaries
- createAchDepositSchedule - Create ACH Deposit Schedule
- listAchDepositSchedules - List ACH Deposit Schedules
- getAchDepositSchedule - Get ACH Deposit Schedule
- updateAchDepositSchedule - Update ACH Deposit Schedules
- cancelAchDepositSchedule - Cancel ACH Deposit Schedule
- createAchWithdrawalSchedule - Create ACH Withdrawal Schedule
- listAchWithdrawalSchedules - List ACH Withdrawal Schedules
- getAchWithdrawalSchedule - Get ACH Withdrawal Schedule
- updateAchWithdrawalSchedule - Update ACH Withdrawal Schedule
- cancelAchWithdrawalSchedule - Cancel ACH Withdrawal Schedule
- createCheckWithdrawalSchedule - Create Check Withdrawal Schedule
- listCheckWithdrawalSchedules - List Check Withdrawal Schedules
- getCheckWithdrawalSchedule - Get Check Withdrawal Schedule
- updateCheckWithdrawalSchedule - Update Check Withdrawal Schedule
- cancelCheckWithdrawalSchedule - Cancel Check Withdrawal Schedule
- createWireWithdrawalSchedule - Create Wire Withdrawal Schedule
- listWireWithdrawalSchedules - List Wire Withdrawal Schedules
- getWireWithdrawalSchedule - Get Wire Withdrawal Schedule
- updateWireWithdrawalSchedule - Update Wire Withdrawal Schedule
- cancelWireWithdrawalSchedule - Cancel Wire Withdrawal Schedule
subscriber
- createPushSubscription - Create Push Subscription
- listPushSubscriptions - List Push Subscriptions
- getPushSubscription - Get Push Subscription
- updatePushSubscription - Update Subscription
- deletePushSubscription - Delete Subscription
- getPushSubscriptionDelivery - Get Subscription Event Delivery
- listPushSubscriptionDeliveries - List Push Subscription Event Deliveries
testSimulation
- simulateCreateCheckDeposit - Simulate Check Deposit Creation
- forceApproveCheckDeposit - Check Deposit Approval
- forceApproveAchDeposit - ACH Deposit Approval
- forceNocAchDeposit - NOC for a Deposit
- forceRejectAchDeposit - ACH Deposit Rejection
- forceReturnAchDeposit - ACH Deposit Return
- forceApproveAchWithdrawal - ACH Withdrawal Approval
- forceNocAchWithdrawal - ACH Withdrawal NOC
- forceRejectAchWithdrawal - ACH Withdrawal Rejection
- forceReturnAchWithdrawal - ACH Withdrawal Return
- getMicroDepositAmounts - Get Relationship Micro Deposit Verification
- forceApproveIctDeposit - Force Approve ICT Deposit
- forceRejectIctDeposit - Force Reject ICT Deposit
- forceApproveIctWithdrawal - Force Approve ICT Withdrawal
- forceRejectIctWithdrawal - Force Reject ICT Withdrawal
- forceApproveWireWithdrawal - Force Approve Wire Withdrawal
- forceRejectWireWithdrawal - Force Reject Wire Withdrawal
- simulateWireDeposit - Simulate Wire Deposit
- forceApproveWireDeposit - Force Approve Wire Deposit
- forceRejectWireDeposit - Force Reject Wire Deposit
- forceApproveCashJournal - Force Approve Cash Journal
- forceRejectCashJournal - Force Reject Cash Journal
- forceApprovePositionJournal - Force Approve Position Journal
- forceRejectPositionJournal - Force Reject Position Journal
tradeAllocation
- createTradeAllocation - Create Trade Allocation
- getTradeAllocation - Get Trade Allocation
- cancelTradeAllocation - Cancel Trade Allocation
- rebookTradeAllocation - Rebook Trade Allocation
tradeBooking
- createTrade - Create Trade
- getTrade - Get Trade
- completeTrade - Complete Trade
- cancelTrade - Cancel Trade
- rebookTrade - Rebook Trade
- createExecution - Create Execution
- getExecution - Get Execution
- cancelExecution - Cancel Execution
- rebookExecution - Rebook Execution
wires
- getWireDeposit - Get Wire Deposit
- createWireWithdrawal - Create Wire Withdrawal
- getWireWithdrawal - Get Wire Withdrawal
- cancelWireWithdrawal - Cancel Wire Withdrawal
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you
make your SDK calls as usual, but the returned response object will also be an
async iterable that can be consumed using the for await...of
syntax.
Here's an example of one such pagination call:
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend();
async function run() {
const result = await apexascend.authentication.listSigningKeys({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
for await (const page of result) {
console.log(page);
}
}
run();
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend();
async function run() {
const result = await apexascend.authentication.generateServiceAccountToken({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
}, {
jws:
"eyJhbGciOiAiUlMyNTYifQ.eyJuYW1lIjogImpkb3VnaCIsIm9yZ2FuaXphdGlvbiI6ICJjb3JyZXNwb25kZW50cy8xMjM0NTY3OC0xMjM0LTEyMzQtMTIzNC0xMjM0NTY3ODkxMDEiLCJkYXRldGltZSI6ICIyMDI0LTAyLTA1VDIxOjAyOjI3LjkwMTE4MFoifQ.IMy3KmYoG8Ppf+7hXN7tm7J4MrNpQLGL7WCWvhh4nZWAVKkluL3/u3KC6hZ6Mb/5p7Y54CgZ68aWT2BcP5y4VtzIZR1Chm5pxbLfgE4aJuk+FnF6K3Gc3bBjOWCL58pxY2aTb0iU/exDEA1cbMDvbCzmY5kRefDvorLOqgUS/tS2MJ2jv4RlZFPlmHv5PtOruJ8xUW19gEgGhsPXYYeSHFTE1ZlaDvyXrKtpOvlf+FVc2RTuEw529LZnzwH4/eJJR3BpSpHyJTjQqiaMT3wzpXXYKfCRqnDkSSKJDzCzTb0/uWK/Lf0uafxPXk5YLdis+dbo1zNQhVVKjwnMpk1vLw",
}, {
retries: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
console.log(result);
}
run();
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const apexascend = new Apexascend({
retryConfig: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
async function run() {
const result = await apexascend.authentication.generateServiceAccountToken({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
}, {
jws:
"eyJhbGciOiAiUlMyNTYifQ.eyJuYW1lIjogImpkb3VnaCIsIm9yZ2FuaXphdGlvbiI6ICJjb3JyZXNwb25kZW50cy8xMjM0NTY3OC0xMjM0LTEyMzQtMTIzNC0xMjM0NTY3ODkxMDEiLCJkYXRldGltZSI6ICIyMDI0LTAyLTA1VDIxOjAyOjI3LjkwMTE4MFoifQ.IMy3KmYoG8Ppf+7hXN7tm7J4MrNpQLGL7WCWvhh4nZWAVKkluL3/u3KC6hZ6Mb/5p7Y54CgZ68aWT2BcP5y4VtzIZR1Chm5pxbLfgE4aJuk+FnF6K3Gc3bBjOWCL58pxY2aTb0iU/exDEA1cbMDvbCzmY5kRefDvorLOqgUS/tS2MJ2jv4RlZFPlmHv5PtOruJ8xUW19gEgGhsPXYYeSHFTE1ZlaDvyXrKtpOvlf+FVc2RTuEw529LZnzwH4/eJJR3BpSpHyJTjQqiaMT3wzpXXYKfCRqnDkSSKJDzCzTb0/uWK/Lf0uafxPXk5YLdis+dbo1zNQhVVKjwnMpk1vLw",
});
console.log(result);
}
run();
Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console's interface as an SDK option.
[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
import { Apexascend } from "@apexfintechsolutions/ascend-sdk";
const sdk = new Apexascend({ debugLogger: console });