@hellomoon/api
v1.23.0
Published
SDK for Hello Moon's REST API, Streaming, and Subscription Management
Downloads
4,645
Readme
Hello Moon API SDK
Installation
Package Manager
Using npm:
$ npm install @hellomoon/api
Using yarn:
$ yarn add @hellomoon/api
Managing subscriptions
Listing your subscriptions
const { RestClient } = require("@hellomoon/api");
const client = new RestClient(process.env.API_KEY);
client.send(new ListStreamsRequest()).then(subscriptions => {
// Do something with your subscriptions
}).catch(console.error);
Create a subscription
const { RestClient, TokenSwapStream, dataStreamFilters } = require("@hellomoon/api");
const stream = new TokenSwapStream({
target: {
targetType: "WEBSOCKET",
},
filters: {
programId: dataStreamFilters.text.equals("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc")
},
name: "SDK Test"
});
const client = new RestClient(process.env.API_KEY);
client.send(new CreateStreamsRequest(stream)).then(subscription => {
// Do something with your subscription
}).catch(console.error);
Update a subscription
const { RestClient, TokenSwapStream, dataStreamFilters } = require("@hellomoon/api");
const stream = new TokenSwapStream({
id: "YOUR_SUBSCRIPTION_ID",
target: {
targetType: "WEBSOCKET",
},
filters: {
programId: dataStreamFilters.text.equals("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc")
},
name: "SDK Test"
});
const client = new RestClient(process.env.API_KEY);
client.send(new UpdateStreamsRequest(stream)).then(subscription => {
// Do something with your subscription
}).catch(console.error);
Delete a subscription
const { RestClient } = require("@hellomoon/api");
const client = new RestClient(process.env.API_KEY);
client.send(new DeleteStreamsRequest("YOUR_SUBSCRIPTION_ID")).then(() => {
}).catch(console.error);
Available Streams
BalanceChangeStream
Balance changes for all accounts at a transaction level. Each transaction will have 0 or more balance changes.
LpBalanceChangeStream
Balance changes for Liquidity Pool (LP) at a transaction level.
LpCreationStream
Creation of new Liquidity Pools (LPs)
LpDepositWithdrawalStream
Liquidity has been deposited or withdrawn from the Liquidity Pool (LP).
NftCollectionListingStatsStream
Listing stats for the NFT collection. This is at the collection level. Each collection is emitted at most once per block. If a block contains multiple instruction that modify the stats for a collection, this describes the last instruction.
NftMarketActionStream
Actions taken on secondary NFT markets, e.g. MagicEden. These are generally emitted in the order as they happen on-chain, but new collections may be delayed.
NftPrimarySaleWithCollectionStream
NFT tokens that are minted or sold from the collection to the first owner during the mint phase. These are not emitted in the order as they happen on-chain. To receive the events as they happen on-chain, use NftPrimarySaleWithoutCollection.
NftPrimarySaleWithoutCollectionStream
NFT tokens that are minted or sold from the collection to the first owner during the mint phase. These are emitted in the order as they happen on-chain. To receive the events with the collection name, use NftPrimarySaleWithCollection.
SharkyEventStream
Events related to the Sharky protocol
TokenPriceStream
This stream emits events everytime Hello Moon determines a liquidity pool has changed the valuation of a tokens
TokenSwapStream
This stream emits events anytime a token is swapped on a DEX that Hello Moon monitors.
TokenTransferStream
Balance changes for all accounts at a transaction level. Each transaction will have 0 or more balance changes.
Streaming
Subscribe to a Websocket Subscription
const { StreamClient, isStreamError } = require("@hellomoon/api");
/**
* The format of the data you expect to receive back from your stream.
* We don't know what a stream will return ahead of time, it is optional to define for typing support
*/
type MyDataType {
mint: string;
}
const client = new StreamClient(process.env.API_KEY);
client.connect(data => {
// A fallback message catcher. This shouldn't fire, but can be used for system messages come through
console.log(data);
}).then(disconnect => {
const unsubscribe = client.subscribe("YOUR_SUBSCRIPTION_ID", data => {
// An array of streamed events
console.log(data);
});
// Disconnect after 60 seconds
setTimeout(disconnect, 60000);
}, err => {
// Handle error
console.log(err);
}).catch(console.error);
Query a Websocket Subscription
const { StreamClient, TokenPriceRequest } = require("@hellomoon/api");
const client = new StreamClient(process.env.API_KEY);
client.connect(data => {
// A fallback message catcher. This shouldn't fire, but can be used for system messages come through
console.log(data);
}).then(disconnect => {
client.send(new TokenPriceRequest({
}).then(responseData => {
// The response object
console.log(responseData);
// Disconnect when we are done
disconnect();
}, err => {
// Handle error
}));
}).catch(console.error);
Combining streaming with Query
const { StreamClient, isStreamError } = require("@hellomoon/api");
/**
* The format of the data you expect to receive back from your stream.
* We don't know what a stream will return ahead of time, it is optional to define for typing support
*/
type MyDataType {
mint: string;
}
const client = new StreamClient(process.env.API_KEY);
client.connect(data => {
// A fallback message catcher. This shouldn't fire, but can be used for system messages come through
console.log(data);
}).then(disconnect => {
const unsubscribe = client.subscribe<MyDataType>("YOUR_SUBSCRIPTION_ID", data => {
client.send(new TokenPriceRequest({
mint: data[0].mint
}).then(price => {
// The response object
console.log(data);
// Disconnect when we are done
}, err => {
// Handle error
}));
});
// Disconnect after 10 seconds
setTimeout(disconnect, 10000);
}).catch(console.error);
Rest API
const { RestClient, NftListingStatusRequest } = require("@hellomoon/api");
const client = new RestClient(process.env.API_KEY);
client
.send(new NftListingStatusRequest())
.then(console.log)
.catch(console.error);
Available Rest Requests
- AllTimeTxnsByUserRequest
- BlockRewardsRequest
- CitrusLoanEventsRequest
- CitrusLoanSummaryRequest
- CollaterizedLoanSummaryRequest
- CollectionAllTimeRequest
- CollectionFloorpriceRequest
- CollectionListingCandlesticksRequest
- CollectionListingStatsRequest
- CollectionMintsRequest
- CollectionNameRequest
- CollectionProgramUsageRequest
- CollectionStatsRequest
- CollectionVolatilityRequest
- CumulativeTokenVolumeRequest
- CurrentLpEmissionsRequest
- DailyNftAvgMedianSalesRequest
- DefiLendingRequest
- DefiLiquidityPoolsBalancesRequest
- DefiLiquidityPoolsMetadataRequest
- DefiLiquidityPoolsRequest
- DefiProgramLeaderboardV2Request
- DefiProgramNetNewUsersDailyRequest
- DefiProgramOverlapRequest
- DefiSwapProgramsRequest
- DefiTokenLeaderboardV3Request
- DefiTokenNetNewPurchasesRequest
- DefiTokenUsersDailyRequest
- FilterSetRequest
- FraktLoanEventsRequest
- FraktLoanSummaryRequest
- JupiterCurrentStatsRequest
- JupiterHistoricalTradingStatsRequest
- JupiterPairsBrokenDownWeeklyRequest
- JupiterSwapStatsRequest
- LeaderboardStatsRequest
- NftCollectionOwnersCurrentV1Request
- NftDistinctOwnersInTimeDailyV1Request
- NftHoldingPeriodV1Request
- NftListingStatusRequest
- NftListingsRequest
- NftMarketStatsRequest
- NftMintInformationRequest
- NftMintPriceByCreatorAvgRequest
- NftMintsByOwnerRequest
- NftOverlappingOwnersV1Request
- NftOwnersCumulativeV1Request
- NftPrimarySaleCollectionStatsRequest
- NftSocialRequest
- NftTopHoldersRequest
- OverlapTopRequest
- SalesPerMarketDailyRequest
- SalesPrimaryRequest
- SalesSecondaryRequest
- SharkyApyRequest
- SharkyDefaultStatsRequest
- SharkyHistoricalDefaultsRequest
- SharkyLoanEventsRequest
- SharkyLoanSummaryRequest
- SolanaArtemisProgramStatsRequest
- SolanaTxnsByUserRequest
- SplTokenListRequest
- Stakeaccountsv2Request
- Stakeactionsv2Request
- Staketransfersv2Request
- StreamCreateRequest
- StreamUpdateRequest
- TokenBalancesByOwnerRequest
- TokenPriceCandlesticksRequest
- TokenPriceRequest
- TokenSwapsRequest
- TokenTransfersWithOwnerRequest
- Tokencreationv2Request
- Tokensupplyv2Request
- TopTokenSellBuyJupRequest
- TopTokensPerProgram24hrRequest
- WashtradingCollectionIndexV7Request