Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getNFTTradesByToken. #1228

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add getNFTTradesByToken.
  • Loading branch information
b4rtaz committed Aug 12, 2024
commit 2e02cdee529865e3f71179354ebdde35d5968003
7 changes: 7 additions & 0 deletions .changeset/slimy-berries-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/evm-api': patch
'moralis': patch
---

Added a new method to the EVM API: `getNFTTradesByToken`.
3 changes: 2 additions & 1 deletion packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"getDefiPositionsSummary",
"getWalletProfitabilitySummary",
"getWalletProfitability",
"getTopProfitableWalletPerToken"
"getTopProfitableWalletPerToken",
"getNFTTradesByToken"
]
}
}
Expand Down
28 changes: 28 additions & 0 deletions packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GetNFTTradesOperation, GetNFTTradesOperationRequest, GetNFTTradesOperationRequestJSON } from '../operations/GetNFTTradesOperation';
import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection';
import { GetNFTTradesByTokenOperation, GetNFTTradesByTokenOperationRequest, GetNFTTradesByTokenOperationRequestJSON } from '../operations/GetNFTTradesByTokenOperation';
import { GetNFTContractSalePricesOperation, GetNFTContractSalePricesOperationRequest, GetNFTContractSalePricesOperationRequestJSON } from '../operations/GetNFTContractSalePricesOperation';
import { EvmSoldPrice, EvmSoldPriceJSON } from '../types/EvmSoldPrice';
import { GetNFTSalePricesOperation, GetNFTSalePricesOperationRequest, GetNFTSalePricesOperationRequestJSON } from '../operations/GetNFTSalePricesOperation';
Expand Down Expand Up @@ -214,6 +215,33 @@ export abstract class AbstractClient {
EvmTradeCollection,
EvmTradeCollectionJSON
>(GetNFTTradesOperation),
/**
* @description Get trades of NFTs for a given contract and token ID.
* @param request Request with parameters.
* @param {Object} request.address The address of the NFT contract
* @param {String} request.tokenId The token ID of the NFT contract
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.fromBlock] The minimum block number from which to get the transfers
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Number} [request.toBlock] The block number to get the trades from (optional)
* @param {Date} [request.fromDate] The start date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Date} [request.toDate] The end date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @param {Number} [request.limit] The desired page size of the result. (optional)
* @param {Boolean} [request.nftMetadata] Include the NFT Metadata of the NFT Token (optional)
* @returns {Object} Response for the request.
*/
getNFTTradesByToken: this.createEndpoint<
GetNFTTradesByTokenOperationRequest,
GetNFTTradesByTokenOperationRequestJSON,
EvmTradeCollection,
EvmTradeCollectionJSON
>(GetNFTTradesByTokenOperation),
/**
* @description Get the sold price for an NFT contract for the last x days (only trades paid in ETH).
* @param request Request with parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { EvmChain, EvmChainInput, EvmChainJSON, EvmAddress, EvmAddressInput, EvmAddressJSON } from '../../dataTypes';
import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCollection';

// request parameters:
// - chain ($ref: #/components/schemas/nftTradesChainList)
// - from_block ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/1/schema)
// - to_block ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/2/schema)
// - from_date ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/3/schema)
// - to_date ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/4/schema)
// - cursor ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/5/schema)
// - limit ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/6/schema)
// - nft_metadata ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/7/schema)
// - address ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/8/schema)
// - token_id ($ref: #/paths/~1nft~1{address}~1{token_id}~1trades/get/parameters/9/schema)

export interface GetNFTTradesByTokenOperationRequest {
/**
* @description The chain to query
*/
readonly chain?: EvmChainInput | EvmChain;
/**
* @description The minimum block number from which to get the transfers
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
readonly fromBlock?: number;
/**
* @description The block number to get the trades from
*/
readonly toBlock?: number;
/**
* @description The start date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used.
*/
readonly fromDate?: Date;
/**
* @description The end date from which to get the transfers (format in seconds or datestring accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used.
*/
readonly toDate?: Date;
/**
* @description The cursor returned in the previous response (used for getting the next page).
*/
readonly cursor?: string;
/**
* @description The desired page size of the result.
*/
readonly limit?: number;
/**
* @description Include the NFT Metadata of the NFT Token
*/
readonly nftMetadata?: boolean;
/**
* @description The address of the NFT contract
*/
readonly address: EvmAddressInput | EvmAddress;
/**
* @description The token ID of the NFT contract
*/
readonly tokenId: string;
}

export interface GetNFTTradesByTokenOperationRequestJSON {
readonly chain?: EvmChainJSON;
readonly from_block?: number;
readonly to_block?: string;
readonly from_date?: string;
readonly to_date?: string;
readonly cursor?: string;
readonly limit?: number;
readonly nft_metadata?: boolean;
readonly address: EvmAddressJSON;
readonly token_id: string;
}

export type GetNFTTradesByTokenOperationResponse = EvmTradeCollection;
export type GetNFTTradesByTokenOperationResponseJSON = EvmTradeCollectionJSON;

export const GetNFTTradesByTokenOperation = {
operationId: "getNFTTradesByToken",
groupName: "nft",
httpMethod: "get",
routePattern: "/nft/{address}/{token_id}/trades",
parameterNames: ["chain","from_block","to_block","from_date","to_date","cursor","limit","nft_metadata","address","token_id"],
hasResponse: true,
hasBody: false,

parseResponse(json: EvmTradeCollectionJSON): EvmTradeCollection {
return EvmTradeCollection.fromJSON(json);
},

serializeRequest(request: GetNFTTradesByTokenOperationRequest): GetNFTTradesByTokenOperationRequestJSON {
const chain = request.chain ? EvmChain.create(request.chain) : undefined;
const fromBlock = request.fromBlock;
const toBlock = request.toBlock;
const fromDate = request.fromDate;
const toDate = request.toDate;
const cursor = request.cursor;
const limit = request.limit;
const nftMetadata = request.nftMetadata;
const address = EvmAddress.create(request.address);
const tokenId = request.tokenId;
return {
chain: chain ? chain.toJSON() : undefined,
from_block: fromBlock,
to_block: toBlock !== undefined ? String(toBlock) : undefined,
from_date: fromDate !== undefined ? fromDate.toISOString() : undefined,
to_date: toDate !== undefined ? toDate.toISOString() : undefined,
cursor: cursor,
limit: limit,
nft_metadata: nftMetadata,
address: address.toJSON(),
token_id: tokenId,
};
},

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './GetNFTTradesOperation';
export * from './GetNFTTradesByTokenOperation';
export * from './GetNFTContractSalePricesOperation';
export * from './GetNFTSalePricesOperation';
export * from './GetMultipleTokenPricesOperation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetNFTTradesOperation } from './GetNFTTradesOperation';
import { GetNFTTradesByTokenOperation } from './GetNFTTradesByTokenOperation';
import { GetNFTContractSalePricesOperation } from './GetNFTContractSalePricesOperation';
import { GetNFTSalePricesOperation } from './GetNFTSalePricesOperation';
import { GetMultipleTokenPricesOperation } from './GetMultipleTokenPricesOperation';
Expand Down Expand Up @@ -32,6 +33,7 @@ import { GetTopProfitableWalletPerTokenOperation } from './GetTopProfitableWalle

export const operations = [
GetNFTTradesOperation,
GetNFTTradesByTokenOperation,
GetNFTContractSalePricesOperation,
GetNFTSalePricesOperation,
GetMultipleTokenPricesOperation,
Expand Down
Loading
Loading