Welcome, if you are reading this, you are probably interested in the Solana Market API. This code is based on npm package @solana/[email protected]
IF you would like to tip me ☕ : 3ARB6St5G3jBPdN9e9qozsXVdurSkGeQ5g1rXnAmdx9K
This Microservice is a work in progress, and it's not ready for production use. But you can use it for your own projects. Building on Solana is not easy if you're not Rust dev, so I'm trying to make it easier live-streaming data such as price, liquidity, volume, etc.
We relying on RPC Node, so it's not real-time, but it's fast enough for most of the use cases.
I beleive that this is a solid foundation for building on Solana, and I will continue to improve it.
If you want to contribute, you can fork the project and improve it.I'll be glad to review and merge your changes.Remember, tools are made to make life easier, not harder. By crafting ourselves tools that unavailable on the market, we can obtain edge in the market.
If you have any questions or suggestions, please contact me on Telegram: @shasiuk
Stack : NodeJS, Typescript, Solana, Raydium, Pump.fun
P.S. This code was taken from one of the projects i wrote, and i decided to share it with closed community as i just don't have time to maintain it. It's been tested and working, but you may need to adjust it to your needs. There is still some work to be done related to token / pool data completeness, as there is more insights to be obtained from the blockchain.
- Clone the repository
- Install dependencies:
npm install
- Configure environment variables
- Run the service:
ts-node src/market/app.ts
- Required: Redis, PostgreSQL
- Environment Variables:
- RPC_URL
- RPC_WSS
- DATABASE_URL
- REDIS_HOST
- REDIS_PORT
- REDIS_PASSWORD
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This documentation provides an overview of the API and the accompanying API client designed to interact with Solana blockchain data, specifically focusing on Raydium pool data, price updates, and pump migration events. The API exposes RESTful and WebSocket endpoints, while the API client offers convenient methods to interact with these endpoints programmatically.
to run use :
ts-node src/market/app.ts
To use api methods copy apiClient.ts to your project and import MarketClient class
The API provides the following endpoints:
- REST Endpoint:
/data/raydium
- Fetches Raydium pool data.
- WebSocket Endpoints:
/price/raydium
- Subscribes to Raydium price updates./price/pump
- Subscribes to Pump price updates./data/pump/migration
- Subscribes to Pump migration events.
The base URL for the API is:
http://localhost:3000
Fetches data for a specific Raydium pool.
GET
/data/raydium
poolId
(string, required): The identifier of the Raydium pool.
- Success (200): Returns a JSON object containing the pool data.
- Error (400): Missing
poolId
parameter. - Error (500): Failed to fetch Raydium pool data.
GET /data/raydium?poolId=YourPoolIdHere HTTP/1.1
Host: localhost:3000
{
"poolId": "YourPoolIdHere",
"liquidity": 123456.78,
"volume": 987654.32,
"otherData": "..."
}
Subscribes to real-time price updates for a specific Raydium pool.
/price/raydium
poolId
(string, required): The identifier of the Raydium pool.
- Establish a WebSocket connection to
/price/raydium
with thepoolId
query parameter. - The server will start sending price updates for the specified pool.
ws://localhost:3000/price/raydium?poolId=YourPoolIdHere
- Price Updates: JSON-formatted messages containing the latest price data.
{
"poolId": "YourPoolIdHere",
"price": 1.2345,
"timestamp": "2023-10-19T12:34:56Z",
"otherData": "..."
}
Subscribes to real-time price updates for a specific token in the Pump program.
/price/pump
tokenMint
(string, required): The token mint address.trade_id
(string, required): The trade identifier.
- Establish a WebSocket connection to
/price/pump
with thetokenMint
andtrade_id
query parameters. - The server will start sending price updates for the specified token and trade ID.
ws://localhost:3000/price/pump?tokenMint=YourTokenMintHere&trade_id=YourTradeIdHere
- Price Updates: JSON-formatted messages containing the latest price data.
{
"trade_id": "YourTradeIdHere",
"tokenMint": "YourTokenMintHere",
"price": 0.9876,
"timestamp": "2023-10-19T12:34:56Z",
"otherData": "..."
}
Subscribes to real-time pump migration events. This endpoint streams updates related to migration events occurring within the pump program.
/data/pump/migration
- Establish a WebSocket connection to
/data/pump/migration
. - Send a
'start'
message to activate the data stream. - The server will start sending migration events.
- Send a
'stop'
message to deactivate the data stream without closing the connection. - Close the WebSocket connection when done.
ws://localhost:3000/data/pump/migration
- Start Data Stream: Send
'start'
. - Stop Data Stream: Send
'stop'
.
- Migration Events: JSON-formatted messages containing migration event data.
{
"timestamp": "2023-10-19T12:34:56Z",
"token": "TokenMintAddress",
"status": "add", // or "withdraw"
"poolId": "PoolIdIfAvailable"
}
The API client is a TypeScript class that provides methods to interact with the API endpoints. It simplifies the process of fetching data and subscribing to real-time updates.
import { ApiClient } from './apiClient';
const apiClient = new MarketClient(); // Uses default API base URL
You can also specify a custom base URL:
const apiClient = new MarketClient('http://your-api-base-url');
Fetches data for a specific Raydium pool.
- Parameters:
poolId
(string): The identifier of the Raydium pool.
- Returns: A promise that resolves to a
market_RaydiumPoolData
object.
Example Usage:
apiClient.getRaydiumPoolData('YourPoolIdHere')
.then((data) => {
console.log('Pool Data:', data);
})
.catch((error) => {
console.error('Error fetching pool data:', error);
});
Subscribes to real-time price updates for a specific Raydium pool.
- Parameters:
poolId
(string): The identifier of the Raydium pool.
- Returns: An
EventEmitter
that emits'data'
,'error'
, and'close'
events.
Example Usage:
const raydiumPriceEmitter = apiClient.getRaydiumPriceUpdates('YourPoolIdHere');
raydiumPriceEmitter.on('data', (update) => {
console.log('Raydium Price Update:', update);
});
raydiumPriceEmitter.on('error', (error) => {
console.error('Error:', error);
});
// Close the connection after 3 minutes
setTimeout(() => {
raydiumPriceEmitter.emit('closeConnection');
}, 180000);
Events:
'data'
: Emitted when a new price update is received.'error'
: Emitted when an error occurs.'close'
: Emitted when the WebSocket connection is closed.
Subscribes to real-time price updates for a specific token in the Pump program.
- Parameters:
tokenMint
(string): The token mint address.trade_id
(string): The trade identifier.
- Returns: An
EventEmitter
that emits'data'
,'error'
, and'close'
events.
Example Usage:
const pumpPriceEmitter = apiClient.getPumpPriceUpdates('YourTokenMintHere', 'YourTradeIdHere');
pumpPriceEmitter.on('data', (update) => {
console.log('Pump Price Update:', update);
});
pumpPriceEmitter.on('error', (error) => {
console.error('Error:', error);
});
// Close the connection after 3 minutes
setTimeout(() => {
pumpPriceEmitter.emit('closeConnection');
}, 180000);
Events:
'data'
: Emitted when a new price update is received.'error'
: Emitted when an error occurs.'close'
: Emitted when the WebSocket connection is closed.
Subscribes to real-time pump migration events.
- Parameters: None.
- Returns: An
EventEmitter
that emits'data'
,'error'
, and'close'
events.
Example Usage:
const migrationEmitter = apiClient.getPumpMigrationEvents();
migrationEmitter.on('data', (event) => {
console.log('Migration Event:', event);
});
migrationEmitter.on('error', (error) => {
console.error('Error:', error);
});
// Optional: Stop the data stream before closing
setTimeout(() => {
migrationEmitter.emit('stop');
}, 170000);
// Close the connection after 3 minutes
setTimeout(() => {
migrationEmitter.emit('closeConnection');
}, 180000);
Events:
'data'
: Emitted when a new migration event is received.'error'
: Emitted when an error occurs.'close'
: Emitted when the WebSocket connection is closed.
Control Messages:
- To start the data stream (sent automatically upon connection):
migrationEmitter.emit('start');
- To stop the data stream:
migrationEmitter.emit('stop');
- To close the connection:
migrationEmitter.emit('closeConnection');
Define TypeScript interfaces to represent the data structures returned by the API.
export interface market_RaydiumPoolData {
poolId: string;
liquidity: number;
volume: number;
// Add other relevant fields
}
export interface market_RaydiumPriceUpdate {
poolId: string;
price: number;
timestamp: string;
// Add other relevant fields
}
export interface market_PumpPriceUpdates {
trade_id: string;
tokenMint: string;
price: number;
timestamp: string;
// Add other relevant fields
}
export interface PumpMigrationEvent {
timestamp: string;
token: string;
status: string; // 'add' or 'withdraw'
poolId?: string;
}
This documentation provides an overview of the API endpoints and the API client methods available for interacting with Solana blockchain data related to Raydium pools, price updates, and pump migration events. By following the examples and utilizing the provided methods, developers can integrate these data streams into their applications efficiently.
- Error Handling: Always include error handling when using the API client methods to gracefully handle any network or parsing errors.
- WebSocket Management: Remember to close WebSocket connections when they are no longer needed to free up resources.
- Data Validation: Ensure that the data received from the API conforms to the expected formats before processing it in your application.
- Logging: Utilize logging to monitor the data flow and catch any unexpected behavior during development and production.
- Environment Variables: Configure environment variables like
API_BASE_URL
as needed for different deployment environments.
For any questions or issues related to the API or the API client, please contact @shasiuk or refer to the project's repository for more information.
Copyright (c) 2024 q-sag / shasiuk
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), subject to the following conditions:
-
Non-Commercial Use Only: The Software may not be used, directly or indirectly, for commercial purposes. Commercial purposes include, but are not limited to:
- Using the Software for commercial advantage or monetary compensation
- Integrating the Software into a commercial product
- Using the Software in a commercial service
- Using the Software to generate revenue, directly or indirectly
-
Attribution: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
Modifications: You may modify and distribute the Software for non-commercial purposes only, provided that:
- You clearly indicate that you have made modifications
- You include the original copyright notice
- You include this license text
- You distribute under the same license terms
-
No Warranty: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Termination: Your rights under this license will terminate automatically if you fail to comply with any of its terms.
For commercial use inquiries, please contact: @shasiuk on Telegram