From 855c90dc4b7658bcb625cab28f166a1c751ae80a Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Tue, 25 Mar 2025 11:11:18 +0100 Subject: [PATCH] feat(v4.0.2): Add full support for P2P trading --- .../apidoc/V5/P2P/get-account-information.js | 18 + examples/apidoc/V5/P2P/get-ad-detail.js | 23 + examples/apidoc/V5/P2P/get-all-orders.js | 29 + examples/apidoc/V5/P2P/get-chat-message.js | 25 + examples/apidoc/V5/P2P/get-coin-balance.js | 21 + .../V5/P2P/get-counterparty-user-info.js | 24 + .../V5/P2P/get-market-online-ads-list.js | 22 + examples/apidoc/V5/P2P/get-my-ads-list.js | 28 + examples/apidoc/V5/P2P/get-order-detail.js | 23 + examples/apidoc/V5/P2P/get-pending-orders.js | 29 + examples/apidoc/V5/P2P/get-user-payment.js | 18 + examples/apidoc/V5/P2P/mark-order-as-paid.js | 25 + examples/apidoc/V5/P2P/post-new-ad.js | 47 ++ .../apidoc/V5/P2P/release-digital-asset.js | 23 + examples/apidoc/V5/P2P/remove-my-ad.js | 20 + examples/apidoc/V5/P2P/send-chat-message.js | 28 + examples/apidoc/V5/P2P/update-relist-my-ad.js | 34 + examples/apidoc/V5/P2P/upload-chat-file.js | 24 + package-lock.json | 4 +- package.json | 2 +- src/rest-client-v5.ts | 236 ++++++- src/types/request/index.ts | 24 +- src/types/request/v5-p2p-trading.ts | 119 ++++ src/types/response/index.ts | 12 +- src/types/response/v5-p2p-trading.ts | 603 ++++++++++++++++++ 25 files changed, 1431 insertions(+), 30 deletions(-) create mode 100644 examples/apidoc/V5/P2P/get-account-information.js create mode 100644 examples/apidoc/V5/P2P/get-ad-detail.js create mode 100644 examples/apidoc/V5/P2P/get-all-orders.js create mode 100644 examples/apidoc/V5/P2P/get-chat-message.js create mode 100644 examples/apidoc/V5/P2P/get-coin-balance.js create mode 100644 examples/apidoc/V5/P2P/get-counterparty-user-info.js create mode 100644 examples/apidoc/V5/P2P/get-market-online-ads-list.js create mode 100644 examples/apidoc/V5/P2P/get-my-ads-list.js create mode 100644 examples/apidoc/V5/P2P/get-order-detail.js create mode 100644 examples/apidoc/V5/P2P/get-pending-orders.js create mode 100644 examples/apidoc/V5/P2P/get-user-payment.js create mode 100644 examples/apidoc/V5/P2P/mark-order-as-paid.js create mode 100644 examples/apidoc/V5/P2P/post-new-ad.js create mode 100644 examples/apidoc/V5/P2P/release-digital-asset.js create mode 100644 examples/apidoc/V5/P2P/remove-my-ad.js create mode 100644 examples/apidoc/V5/P2P/send-chat-message.js create mode 100644 examples/apidoc/V5/P2P/update-relist-my-ad.js create mode 100644 examples/apidoc/V5/P2P/upload-chat-file.js create mode 100644 src/types/request/v5-p2p-trading.ts create mode 100644 src/types/response/v5-p2p-trading.ts diff --git a/examples/apidoc/V5/P2P/get-account-information.js b/examples/apidoc/V5/P2P/get-account-information.js new file mode 100644 index 0000000..566f332 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-account-information.js @@ -0,0 +1,18 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Call the function +client + .getP2PUserInfo() + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); diff --git a/examples/apidoc/V5/P2P/get-ad-detail.js b/examples/apidoc/V5/P2P/get-ad-detail.js new file mode 100644 index 0000000..7dab165 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-ad-detail.js @@ -0,0 +1,23 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + itemId: '1898988222063644672', // Replace with your ad ID +}; + +// Call the function +client + .getP2PAdDetail(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); diff --git a/examples/apidoc/V5/P2P/get-all-orders.js b/examples/apidoc/V5/P2P/get-all-orders.js new file mode 100644 index 0000000..1cec40c --- /dev/null +++ b/examples/apidoc/V5/P2P/get-all-orders.js @@ -0,0 +1,29 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + status: null, // Optional: filter by order status + beginTime: null, // Optional: filter by start time + endTime: null, // Optional: filter by end time + tokenId: null, // Optional: filter by token ID + side: null, // Optional: filter by side (0: Buy, 1: Sell) + page: 1, // Required: page number + size: 1, // Required: rows per page +}; + +// Call the function +client + .getP2POrders(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); diff --git a/examples/apidoc/V5/P2P/get-chat-message.js b/examples/apidoc/V5/P2P/get-chat-message.js new file mode 100644 index 0000000..6ef3790 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-chat-message.js @@ -0,0 +1,25 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + orderId: '1898976123321221120', // Replace with your order ID + size: '1', // Number of messages per page + currentPage: '1', // Optional: current page number +}; + +// Call the function +client + .getP2POrderMessages(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/get-coin-balance.js b/examples/apidoc/V5/P2P/get-coin-balance.js new file mode 100644 index 0000000..f6bcde4 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-coin-balance.js @@ -0,0 +1,21 @@ +const { RestClientV5 } = require('bybit-api'); + +// Create a client +const client = new RestClientV5({ + testnet: true, + key: 'XXXXX', + secret: 'XXXXX', +}); + +// Get account coins balance +client + .getP2PAccountCoinsBalance({ + accountType: 'FUND', + coin: 'USDC', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/P2P/get-counterparty-user-info.js b/examples/apidoc/V5/P2P/get-counterparty-user-info.js new file mode 100644 index 0000000..7ce5450 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-counterparty-user-info.js @@ -0,0 +1,24 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + originalUid: '290118', // Replace with the counterparty user ID + orderId: '1900004704665923584', // Replace with your order ID +}; + +// Call the function +client + .getP2PCounterpartyUserInfo(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/get-market-online-ads-list.js b/examples/apidoc/V5/P2P/get-market-online-ads-list.js new file mode 100644 index 0000000..3c99e24 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-market-online-ads-list.js @@ -0,0 +1,22 @@ +const { RestClientV5 } = require('bybit-api'); + +// Create a client +const client = new RestClientV5({ + testnet: true, + key: 'XXXXX', + secret: 'XXXXX', +}); + +// Get market online ads list +client + .getP2POnlineAds({ + tokenId: 'USDT', + currencyId: 'USD', + side: '0', // 0: buy; 1: sell + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/P2P/get-my-ads-list.js b/examples/apidoc/V5/P2P/get-my-ads-list.js new file mode 100644 index 0000000..86520cd --- /dev/null +++ b/examples/apidoc/V5/P2P/get-my-ads-list.js @@ -0,0 +1,28 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET' +}); + +// Example parameters for getting personal P2P ads +const params = { + itemId: '123456789', // Optional: Specific advertisement ID + status: 1, // Optional: Advertisement status (1: active, 2: completed, 3: cancelled) + side: 1, // Optional: 0: buy; 1: sell + tokenId: 'USDT', // Optional: Token ID + page: 1, // Optional: Page number + size: 20, // Optional: Page size + currencyId: 'USD' // Optional: Currency ID +}; + +// Get personal P2P ads +client.getP2PPersonalAds(params) + .then(response => { + console.log('Response:', response); + }) + .catch(error => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/get-order-detail.js b/examples/apidoc/V5/P2P/get-order-detail.js new file mode 100644 index 0000000..975cbad --- /dev/null +++ b/examples/apidoc/V5/P2P/get-order-detail.js @@ -0,0 +1,23 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + orderId: '1900004704665923584', // Replace with your order ID +}; + +// Call the function +client + .getP2POrderDetail(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/get-pending-orders.js b/examples/apidoc/V5/P2P/get-pending-orders.js new file mode 100644 index 0000000..08da469 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-pending-orders.js @@ -0,0 +1,29 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + status: 10, // waiting for buy pay + beginTime: '1741831397000', // Optional: filter by start time + endTime: '1741831424861', // Optional: filter by end time + tokenId: 'USDT', // Optional: filter by token + side: [0, 1], // Optional: filter by side (0: Buy, 1: Sell) + page: 1, + size: 3, +}; + +// Call the function +client + .getP2PPendingOrders(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/get-user-payment.js b/examples/apidoc/V5/P2P/get-user-payment.js new file mode 100644 index 0000000..37a5fe7 --- /dev/null +++ b/examples/apidoc/V5/P2P/get-user-payment.js @@ -0,0 +1,18 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Call the function +client + .getP2PUserPayments() + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/mark-order-as-paid.js b/examples/apidoc/V5/P2P/mark-order-as-paid.js new file mode 100644 index 0000000..05ff35e --- /dev/null +++ b/examples/apidoc/V5/P2P/mark-order-as-paid.js @@ -0,0 +1,25 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + orderId: '1899736339155943424', // Replace with your order ID + paymentType: '14', // Payment method used + paymentId: '7110', // Payment method ID used +}; + +// Call the function +client + .markP2POrderAsPaid(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); diff --git a/examples/apidoc/V5/P2P/post-new-ad.js b/examples/apidoc/V5/P2P/post-new-ad.js new file mode 100644 index 0000000..196c320 --- /dev/null +++ b/examples/apidoc/V5/P2P/post-new-ad.js @@ -0,0 +1,47 @@ +const { RestClientV5 } = require('bybit-api'); + +// Create a client +const client = new RestClientV5({ + testnet: true, + key: 'XXXXX', + secret: 'XXXXX', +}); + +// Create new P2P advertisement +client + .createP2PAd({ + tokenId: 'USDT', + currencyId: 'EUR', + side: '0', + priceType: '0', + premium: '', + price: '0.92', + minAmount: '20', + maxAmount: '45000', + paymentIds: ['7110'], + remark: 'test', + tradingPreferenceSet: { + isKyc: 1, + hasCompleteRateDay30: 1, + completeRateDay30: '95', + hasOrderFinishNumberDay30: 1, + hasRegisterTime: 0, + hasUnPostAd: 0, + isEmail: 0, + isMobile: 0, + nationalLimit: '', + orderFinishNumberDay30: 60, + registerTimeThreshold: 0, + verificationOrderLabels: [], + verificationOrderSwitch: false, + }, + quantity: '20000', + paymentPeriod: '15', + itemType: 'ORIGIN', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/P2P/release-digital-asset.js b/examples/apidoc/V5/P2P/release-digital-asset.js new file mode 100644 index 0000000..45ebaa4 --- /dev/null +++ b/examples/apidoc/V5/P2P/release-digital-asset.js @@ -0,0 +1,23 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + orderId: '1899736339155943424', // Replace with your order ID +}; + +// Call the function +client + .releaseP2POrder(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/remove-my-ad.js b/examples/apidoc/V5/P2P/remove-my-ad.js new file mode 100644 index 0000000..529e365 --- /dev/null +++ b/examples/apidoc/V5/P2P/remove-my-ad.js @@ -0,0 +1,20 @@ +const { RestClientV5 } = require('bybit-api'); + +// Create a client +const client = new RestClientV5({ + testnet: true, + key: 'XXXXX', + secret: 'XXXXX', +}); + +// Cancel P2P advertisement +client + .cancelP2PAd({ + itemId: '1899667660027793408', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/P2P/send-chat-message.js b/examples/apidoc/V5/P2P/send-chat-message.js new file mode 100644 index 0000000..76297f5 --- /dev/null +++ b/examples/apidoc/V5/P2P/send-chat-message.js @@ -0,0 +1,28 @@ +const { RestClientV5 } = require('bybit-api'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Example parameters +const params = { + message: 'hi, test', + contentType: 'text', + orderId: '1898976123321221120', // Replace with your order ID + // Optional parameters: + // msgUuid: 'your-message-uuid', + // fileName: 'example.pdf' +}; + +// Call the function +client + .sendP2POrderMessage(params) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/update-relist-my-ad.js b/examples/apidoc/V5/P2P/update-relist-my-ad.js new file mode 100644 index 0000000..e899f20 --- /dev/null +++ b/examples/apidoc/V5/P2P/update-relist-my-ad.js @@ -0,0 +1,34 @@ +const { RestClientV5 } = require('bybit-api'); + +// Create a client +const client = new RestClientV5({ + testnet: true, + key: 'XXXXX', + secret: 'XXXXX', +}); + +// Update P2P advertisement +client + .updateP2PAd({ + id: '1898988222063644672', + priceType: '0', + premium: '', + price: '0.914', + minAmount: '25', + maxAmount: '5000', + remark: '', + paymentIds: ['-1'], + tradingPreferenceSet: {}, + actionType: 'ACTIVE', + quantity: '1000', + paymentPeriod: '15', + itemType: 'ORIGIN', + subsidyAd: false, + securityRiskToken: '', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); \ No newline at end of file diff --git a/examples/apidoc/V5/P2P/upload-chat-file.js b/examples/apidoc/V5/P2P/upload-chat-file.js new file mode 100644 index 0000000..7fccd98 --- /dev/null +++ b/examples/apidoc/V5/P2P/upload-chat-file.js @@ -0,0 +1,24 @@ +const { RestClientV5 } = require('bybit-api'); +const fs = require('fs'); +const FormData = require('form-data'); + +// Initialize the client with testnet mode +const client = new RestClientV5({ + testnet: true, + key: 'YOUR_API_KEY', + secret: 'YOUR_API_SECRET', +}); + +// Create form data +const formData = new FormData(); +formData.append('upload_file', fs.createReadStream('path/to/your/file.jpg')); // Replace with your file path + +// Call the function +client + .uploadP2PChatFile(formData) + .then((response) => { + console.log('Response:', response); + }) + .catch((error) => { + console.error('Error:', error); + }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f30029c..4553183 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "4.0.1", + "version": "4.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "4.0.1", + "version": "4.0.2", "license": "MIT", "dependencies": { "axios": "^1.7.9", diff --git a/package.json b/package.json index 3e52da2..1a6463e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "4.0.1", + "version": "4.0.2", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 7a84e1a..90e77aa 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -47,6 +47,7 @@ import { ConvertHistoryRecordV5, ConvertQuoteV5, ConvertStatusV5, + CreateP2PAdParamsV5, CreateSubApiKeyParamsV5, CreateSubApiKeyResultV5, CreateSubMemberParamsV5, @@ -59,6 +60,9 @@ import { DeliveryRecordV5, DepositAddressChainV5, DepositRecordV5, + EarnOrderHistory, + EarnPosition, + EarnProduct, ExchangeBrokerAccountInfoV5, ExchangeBrokerEarningResultV5, ExchangeBrokerSubAccountDepositRecordV5, @@ -82,6 +86,8 @@ import { GetDeliveryPriceParamsV5, GetDeliveryRecordParamsV5, GetDepositRecordParamsV5, + GetEarnOrderHistoryParams, + GetEarnPositionParams, GetExchangeBrokerEarningsParamsV5, GetExecutionListParamsV5, GetFeeRateParamsV5, @@ -100,6 +106,13 @@ import { GetOpenInterestParamsV5, GetOptionDeliveryPriceParamsV5, GetOrderbookParamsV5, + GetP2PAccountCoinsBalanceParamsV5, + GetP2PCounterpartyUserInfoParamsV5, + GetP2POnlineAdsParamsV5, + GetP2POrderMessagesParamsV5, + GetP2POrdersParamsV5, + GetP2PPendingOrdersParamsV5, + GetP2PPersonalAdsParamsV5, GetPreUpgradeClosedPnlParamsV5, GetPreUpgradeOptionDeliveryRecordParamsV5, GetPreUpgradeOrderHistoryParamsV5, @@ -133,6 +146,7 @@ import { LongShortRatioV5, MMPModifyParamsV5, MMPStateV5, + MarkP2POrderAsPaidParamsV5, MovePositionHistoryV5, MovePositionParamsV5, MovePositionResultV5, @@ -144,6 +158,17 @@ import { OrderResultV5, OrderSideV5, OrderbookResponseV5, + P2PAccountCoinsBalanceV5, + P2PAdDetailV5, + P2PCounterpartyUserInfoV5, + P2PCreateAdResponseV5, + P2POnlineAdsResponseV5, + P2POrderDetailV5, + P2POrderMessageV5, + P2POrdersResponseV5, + P2PPersonalAdsResponseV5, + P2PUserInfoV5, + P2PUserPaymentV5, PositionInfoParamsV5, PositionV5, PreUpgradeOptionsDelivery, @@ -159,6 +184,7 @@ import { RepaymentHistoryV5, RequestConvertQuoteParamsV5, RiskLimitV5, + SendP2POrderMessageParamsV5, SetAutoAddMarginParamsV5, SetCollateralCoinParamsV5, SetLeverageParamsV5, @@ -171,6 +197,7 @@ import { SpotLeveragedTokenOrderHistoryV5, SpotMarginStateV5, SubMemberV5, + SubmitStakeRedeemParams, SwitchIsolatedMarginParamsV5, SwitchPositionModeParamsV5, TPSLModeV5, @@ -184,6 +211,7 @@ import { UnpaidLoanOrderV5, UpdateApiKeyParamsV5, UpdateApiKeyResultV5, + UpdateP2PAdParamsV5, VIPMarginDataV5, VaspEntityV5, VipBorrowableCoinsV5, @@ -193,17 +221,6 @@ import { WithdrawableAmountV5, WithdrawalRecordV5, } from './types'; -import { - GetEarnOrderHistoryParams, - GetEarnPositionParams, - SubmitStakeRedeemParams, -} from './types/request/v5-earn'; -import { - EarnOrderHistory, - EarnPosition, - EarnProduct, -} from './types/response/v5-earn'; - import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -2625,4 +2642,201 @@ export class RestClientV5 extends BaseRestClient { > { return this.getPrivate('/v5/earn/position', params); } + + /** + * + ****** P2P TRADING + * + */ + + /** + * + * General P2P + */ + + /** + * Get coin balance of all account types under the master account, and sub account. + * + * Note: this field is mandatory for accountType=UNIFIED, and supports up to 10 coins each request + */ + getP2PAccountCoinsBalance( + params: GetP2PAccountCoinsBalanceParamsV5, + ): Promise> { + return this.getPrivate( + '/v5/asset/transfer/query-account-coins-balance', + params, + ); + } + + /** + * + * Advertisement P2P + */ + + /** + * Get market online ads list + */ + getP2POnlineAds( + params: GetP2POnlineAdsParamsV5, + ): Promise> { + return this.post('/v5/p2p/item/online', params); + } + + /** + * Post new P2P advertisement + */ + createP2PAd( + params: CreateP2PAdParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/item/create', params); + } + + /** + * Cancel P2P advertisement + */ + cancelP2PAd(params: { itemId: string }): Promise< + APIResponseV3WithTime<{ + securityRiskToken: string; + riskTokenType: string; + riskVersion: string; + needSecurityRisk: boolean; + }> + > { + return this.postPrivate('/v5/p2p/item/cancel', params); + } + + /** + * Update or relist P2P advertisement + */ + updateP2PAd( + params: UpdateP2PAdParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/item/update', params); + } + + /** + * Get personal P2P ads list + * + */ + getP2PPersonalAds( + params: GetP2PPersonalAdsParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/item/personal/list', params); + } + + /** + * Get P2P ad details + */ + getP2PAdDetail(params: { + itemId: string; + }): Promise> { + return this.postPrivate('/v5/p2p/item/info', params); + } + + /** + * + * Orders P2P + */ + + /** + * Get all P2P orders + * + */ + getP2POrders( + params: GetP2POrdersParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/order/simplifyList', params); + } + + /** + * Get P2P order details + * + */ + getP2POrderDetail(params: { + orderId: string; + }): Promise> { + return this.postPrivate('/v5/p2p/order/info', params); + } + + /** + * Get pending P2P orders + */ + getP2PPendingOrders( + params: GetP2PPendingOrdersParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/order/pending/simplifyList', params); + } + + /** + * Mark P2P order as paid + */ + markP2POrderAsPaid( + params: MarkP2POrderAsPaidParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/order/pay', params); + } + + /** + * Release digital assets in a P2P order + */ + releaseP2POrder(params: { + orderId: string; + }): Promise> { + return this.postPrivate('/v5/p2p/order/finish', params); + } + + /** + * Send chat message in a P2P order + */ + sendP2POrderMessage( + params: SendP2POrderMessageParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/order/message/send', params); + } + + /** + * Upload chat file for P2P order + */ + uploadP2PChatFile(params: { + upload_file: File; // Only supports: jpg, png, jpeg, pdf, mp4 + }): Promise> { + return this.postPrivate('/v5/p2p/oss/upload_file', params); + } + + /** + * Get chat messages in a P2P order + */ + getP2POrderMessages( + params: GetP2POrderMessagesParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/order/message/listpage', params); + } + + /** + * + * User P2P + */ + + /** + * Get P2P user account information + */ + getP2PUserInfo(): Promise> { + return this.postPrivate('/v5/p2p/user/personal/info'); + } + + /** + * Get counterparty user information in a P2P order + */ + getP2PCounterpartyUserInfo( + params: GetP2PCounterpartyUserInfoParamsV5, + ): Promise> { + return this.postPrivate('/v5/p2p/user/order/personal/info', params); + } + + /** + * Get user payment information + */ + getP2PUserPayments(): Promise> { + return this.postPrivate('/v5/p2p/user/payment/list'); + } } diff --git a/src/types/request/index.ts b/src/types/request/index.ts index 1c6b741..c9e73e1 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -1,19 +1,21 @@ export * from './account-asset'; -export * from './copy-trading'; export * from './contract'; -export * from './linear'; +export * from './copy-trading'; export * from './inverse'; -export * from './usdc-perp'; -export * from './usdc-options'; -export * from './usdc-shared'; +export * from './linear'; export * from './unified-margin'; +export * from './usdc-options'; +export * from './usdc-perp'; +export * from './usdc-shared'; export * from './v5-account'; export * from './v5-asset'; -export * from './v5-market'; -export * from './v5-position'; -export * from './v5-pre-upgrade'; -export * from './v5-trade'; -export * from './v5-user'; -export * from './v5-spot-leverage-token'; export * from './v5-broker'; export * from './v5-crypto-loan'; +export * from './v5-earn'; +export * from './v5-market'; +export * from './v5-p2p-trading'; +export * from './v5-position'; +export * from './v5-pre-upgrade'; +export * from './v5-spot-leverage-token'; +export * from './v5-trade'; +export * from './v5-user'; diff --git a/src/types/request/v5-p2p-trading.ts b/src/types/request/v5-p2p-trading.ts new file mode 100644 index 0000000..c616b46 --- /dev/null +++ b/src/types/request/v5-p2p-trading.ts @@ -0,0 +1,119 @@ +export interface GetP2PAccountCoinsBalanceParamsV5 { + memberId?: string; + accountType: string; + coin?: string; + withBonus?: 0 | 1; +} + +export interface GetP2POnlineAdsParamsV5 { + tokenId: string; + currencyId: string; + side: '0' | '1'; // 0: buy; 1: sell + page?: string; + size?: string; +} + +export interface P2PTradingPreferenceSetV5 { + hasUnPostAd?: 0 | 1; + isKyc?: 0 | 1; + isEmail?: 0 | 1; + isMobile?: 0 | 1; + hasRegisterTime?: 0 | 1; + registerTimeThreshold?: number; + orderFinishNumberDay30?: number; + completeRateDay30?: string; + nationalLimit?: string; + hasOrderFinishNumberDay30?: 0 | 1; + hasCompleteRateDay30?: 0 | 1; + hasNationalLimit?: 0 | 1; +} + +export interface CreateP2PAdParamsV5 { + tokenId: string; + currencyId: string; + side: '0' | '1'; // 0: buy; 1: sell + priceType: '0' | '1'; // 0: fixed rate; 1: floating rate + premium: string; + price: string; + minAmount: string; + maxAmount: string; + remark: string; + tradingPreferenceSet: P2PTradingPreferenceSetV5; + paymentIds: string[]; + quantity: string; + paymentPeriod: string; + itemType: 'ORIGIN' | 'BULK'; +} + +export interface UpdateP2PAdParamsV5 { + id: string; + priceType: '0' | '1'; // 0: fixed rate; 1: floating rate + premium: string; + price: string; + minAmount: string; + maxAmount: string; + remark: string; + tradingPreferenceSet: P2PTradingPreferenceSetV5; + paymentIds: string[]; + actionType: 'MODIFY' | 'ACTIVE'; // MODIFY: modify adv; ACTIVE: reonline adv + quantity: string; + paymentPeriod: string; + itemType?: 'ORIGIN' | 'BULK'; + subsidyAd?: boolean; + securityRiskToken?: string; +} + +export interface GetP2PPersonalAdsParamsV5 { + itemId?: string; + status?: '1' | '2'; // 1: Sold Out; 2: Available + side?: '0' | '1'; // 0: buy; 1: sell + tokenId?: string; + page?: string; + size?: string; + currencyId?: string; +} + +export interface GetP2POrdersParamsV5 { + status?: number; + beginTime?: string; + endTime?: string; + tokenId?: string; + side?: number[]; + page: number; + size: number; +} + +export interface GetP2PPendingOrdersParamsV5 { + status?: number; + beginTime?: string; + endTime?: string; + tokenId?: string; + side?: number[]; + page: number; + size: number; +} + +export interface MarkP2POrderAsPaidParamsV5 { + orderId: string; + paymentType: string; + paymentId: string; +} + +export interface SendP2POrderMessageParamsV5 { + message: string; + contentType: string; + orderId: string; + msgUuid?: string; + fileName?: string; +} + +export interface GetP2POrderMessagesParamsV5 { + orderId: string; + currentPage?: string; + size: string; +} + +export interface GetP2PCounterpartyUserInfoParamsV5 { + originalUid: string; + orderId: string; +} diff --git a/src/types/response/index.ts b/src/types/response/index.ts index ca2cf2a..cd0ca61 100644 --- a/src/types/response/index.ts +++ b/src/types/response/index.ts @@ -2,15 +2,17 @@ export * from './account-asset'; export * from './contract'; export * from './shared'; export * from './spot'; -export * from './usdt-perp'; export * from './unified-margin'; +export * from './usdt-perp'; export * from './v5-account'; export * from './v5-asset'; +export * from './v5-broker'; +export * from './v5-crypto-loan'; export * from './v5-market'; +export * from './v5-p2p-trading'; export * from './v5-position'; +export * from './v5-preupgrade'; +export * from './v5-spot-leverage-token'; export * from './v5-trade'; export * from './v5-user'; -export * from './v5-spot-leverage-token'; -export * from './v5-broker'; -export * from './v5-preupgrade'; -export * from './v5-crypto-loan'; +export * from './v5-earn'; diff --git a/src/types/response/v5-p2p-trading.ts b/src/types/response/v5-p2p-trading.ts new file mode 100644 index 0000000..b465223 --- /dev/null +++ b/src/types/response/v5-p2p-trading.ts @@ -0,0 +1,603 @@ +import { P2PTradingPreferenceSetV5 } from '../request/v5-p2p-trading'; + +export interface P2PCoinBalanceV5 { + coin: string; + transferBalance: string; + walletBalance: string; + bonus: string; +} + +export interface P2PAccountCoinsBalanceV5 { + memberId: string; + accountType: string; + balance: P2PCoinBalanceV5[]; +} + +export interface P2POnlineAdV5 { + id: string; + nickName: string; + tokenId: string; + currencyId: string; + side: string; + price: string; + lastQuantity: string; + minAmount: string; + maxAmount: string; + payments: string[]; + recentOrderNum: number; + recentExecuteRate: number; + isOnline: boolean; + authTag: string[]; + paymentPeriod: number; + accountId: number; + userId: number; + priceType: number; + premium: string; + quantity: string; + frozenQuantity: string; + executedQuantity: string; + remark: string; + status: number; + createDate: string; + orderNum: string; + finishNum: string; + fee: string; + lastLogoutTime: string; + blocked: string; + makerContact: boolean; + symbolInfo: { + id: string; + exchangeId: string; + orgId: string; + tokenId: string; + currencyId: string; + status: string; + lowerLimitAlarm: number; + upperLimitAlarm: number; + itemDownRange: string; + itemUpRange: string; + currencyMinQuote: string; + currencyMaxQuote: string; + currencyLowerMaxQuote: string; + tokenMinQuote: string; + tokenMaxQuote: string; + kycCurrencyLimit: string; + itemSideLimit: string; + buyFeeRate: string; + sellFeeRate: string; + orderAutoCancelMinute: number; + orderFinishMinute: number; + tradeSide: number; + currency: { + id: string; + exchangeId: string; + orgId: string; + currencyId: string; + scale: number; + }; + token: { + id: string; + exchangeId: string; + orgId: string; + tokenId: string; + scale: number; + sequence: number; + }; + buyAd: number; + sellAd: number; + }; + tradingPreferenceSet: { + hasUnPostAd: number; + isKyc: number; + isEmail: number; + isMobile: number; + hasRegisterTime: number; + registerTimeThreshold: number; + orderFinishNumberDay30: number; + completeRateDay30: number; + nationalLimit: number; + hasOrderFinishNumberDay30: number; + hasCompleteRateDay30: number; + hasNationalLimit: number; + }; + version: number; + authStatus: number; + recommend: boolean; + recommendTag: string; + userType: string; + itemType: string; +} + +export interface P2POnlineAdsResponseV5 { + count: number; + items: P2POnlineAdV5[]; +} + +export interface P2PCreateAdResponseV5 { + itemId: string; + securityRiskToken: string; + riskTokenType: string; + riskVersion: string; + needSecurityRisk: boolean; +} + +export interface P2PPaymentTermV5 { + id: string; + realName: string; + paymentType: number; + bankName: string; + branchName: string; + accountNo: string; + qrcode: string; + visible: number; + payMessage: string; + firstName: string; + lastName: string; + secondLastName: string; + clabe: string; + debitCardNumber: string; + mobile: string; + businessName: string; + concept: string; + paymentExt1: string; + paymentExt2: string; + paymentExt3: string; + paymentExt4: string; + paymentExt5: string; + paymentExt6: string; + paymentTemplateVersion: number; + paymentConfig: { + paymentType: number; + paymentName: string; + paymentDialect: string; + }; + realNameVerified: boolean; +} + +export interface P2PAdDetailV5 { + id: string; + accountId: string; + userId: string; + nickName: string; + tokenId: string; + tokenName: string; + currencyId: string; + side: number; + priceType: number; + price: string; + premium: string; + lastQuantity: string; + quantity: string; + frozenQuantity: string; + executedQuantity: string; + minAmount: string; + maxAmount: string; + remark: string; + status: number; + createDate: string; + payments: string[]; + orderNum: number; + finishNum: number; + recentOrderNum: number; + recentExecuteRate: number; + fee: string; + isOnline: boolean; + lastLogoutTime: string; + symbolInfo: { + id: string; + exchangeId: string; + orgId: string; + tokenId: string; + currencyId: string; + status: number; + lowerLimitAlarm: number; + upperLimitAlarm: number; + itemDownRange: string; + itemUpRange: string; + currencyMinQuote: string; + currencyMaxQuote: string; + currencyLowerMaxQuote: string; + tokenMinQuote: string; + tokenMaxQuote: string; + kycCurrencyLimit: string; + itemSideLimit: number; + buyFeeRate: string; + sellFeeRate: string; + orderAutoCancelMinute: number; + orderFinishMinute: number; + tradeSide: number; + currency: { + id: string; + exchangeId: string; + orgId: string; + currencyId: string; + scale: number; + }; + token: { + id: string; + exchangeId: string; + orgId: string; + tokenId: string; + scale: number; + sequence: number; + }; + buyAd: { + paymentPeriods: number[]; + }; + sellAd: { + paymentPeriods: number[]; + }; + }; + tradingPreferenceSet: P2PTradingPreferenceSetV5; + paymentTerms: P2PPaymentTermV5[]; + version: number; + updateDate: string; + feeRate: string; + paymentPeriod: number; + itemType: string; +} + +export interface P2PPersonalAdsResponseV5 { + count: number; + items: P2PAdDetailV5[]; + hiddenFlag: boolean; +} + +export interface P2POrderExtensionV5 { + isDelayWithdraw: boolean; + delayTime: string; + startTime: string; +} + +export interface P2POrderV5 { + id: string; + side: number; + tokenId: string; + orderType: string; + amount: string; + currencyId: string; + price: string; + notifyTokenQuantity?: string; + notifyTokenId?: string; + fee: string; + targetNickName: string; + targetUserId: string; + status: number; + selfUnreadMsgCount: string; + createDate: string; + transferLastSeconds: string; + appealLastSeconds: string; + userId: string; + sellerRealName: string; + buyerRealName: string; + judgeInfo: { + autoJudgeUnlockTime: string; + dissentResult: string; + preDissent: string; + postDissent: string; + }; + unreadMsgCount: string; + extension: P2POrderExtensionV5; + bulkOrderFlag: boolean; +} + +export interface P2POrdersResponseV5 { + count: number; + items: P2POrderV5[]; +} + +export interface P2PPaymentConfigItemV5 { + view: boolean; + name: string; + label: string; + placeholder: string; + type: string; + maxLength: string; + required: boolean; +} + +export interface P2PPaymentConfigV5 { + paymentType: string; + checkType: number; + sort: number; + paymentName: string; + addTips: string; + itemTips: string; + online: number; + items: P2PPaymentConfigItemV5[]; +} + +export interface P2PPaymentTermDetailV5 { + id: string; + realName: string; + paymentType: number; + bankName: string; + branchName: string; + accountNo: string; + qrcode: string; + visible: number; + payMessage: string; + firstName: string; + lastName: string; + secondLastName: string; + clabe: string; + debitCardNumber: string; + mobile: string; + businessName: string; + concept: string; + online: string; + paymentExt1: string; + paymentExt2: string; + paymentExt3: string; + paymentExt4: string; + paymentExt5: string; + paymentExt6: string; + paymentTemplateVersion: number; + paymentConfigVo: P2PPaymentConfigV5; + ruPaymentPrompt: boolean; +} + +export interface P2PAppraiseInfoV5 { + anonymous: string; + appraiseContent: string; + appraiseId: string; + appraiseType: string; + modifyFlag: string; + updateDate: string; +} + +export interface P2PJudgeInfoV5 { + autoJudgeUnlockTime: string; + dissentResult: string; + preDissent: string; + postDissent: string; +} + +export interface P2POrderDetailV5 { + id: string; + side: number; + itemId: string; + accountId: string; + userId: string; + nickName: string; + makerUserId: string; + targetAccountId: string; + targetUserId: string; + targetNickName: string; + targetFirstName: string; + targetSecondName: string; + targetUserAuthStatus: number; + targetConnectInformation: string; + payerRealName: string; + sellerRealName: string; + buyerRealName: string; + tokenId: string; + tokenName: string; + currencyId: string; + price: string; + quantity: string; + amount: string; + payCode: string; + paymentType: number; + transferDate: string; + status: number; + createDate: string; + paymentTermList: P2PPaymentTermDetailV5[]; + remark: string; + transferLastSeconds: string; + recentOrderNum: number; + recentExecuteRate: number; + appealLastSeconds: string; + appealContent: string; + appealType: number; + appealNickName: string; + canAppeal: string; + totalAppealTimes: string; + appealedTimes: string; + paymentTermResult: P2PPaymentTermDetailV5; + orderFinishMinute: number; + confirmedPayTerm: P2PPaymentTermDetailV5; + makerFee: string; + takerFee: string; + fee: string; + showContact: boolean; + tokenBalance: string; + fiatBalance: string; + unreadMsgCount: string; + updateDate: string; + extension: P2POrderExtensionV5; + selfUnreadMsgCount: string; + judgeType: string; + canReport: boolean; + canReportDisagree: boolean; + canReportType: string[]; + canReportDisagreeType: string[]; + appraiseStatus: string; + appraiseInfo: P2PAppraiseInfoV5; + canReportDisagreeTypes: string[]; + canReportTypes: string[]; + orderType: string; + middleToken: string; + beforePrice: string; + beforeQuantity: string; + beforeToken: string; + alternative: string; + appealUserId: string; + notifyTokenId: string; + notifyTokenQuantity: string; + cancelResponsible: string; + chainType: string; + chainAddress: string; + tradeHashCode: string; + estimatedGasFee: string; + gasFeeTokenId: string; + tradingFeeTokenId: string; + onChainInfo: string; + transactionId: string; + displayRefund: string; + chainWithdrawLastSeconds: string; + chainTransferLastSeconds: string; + orderSource: string; + cancelReason: string; + sellerCancelExamineRemainTime: string; + needSellerExamineCancel: boolean; + couponCurrencyAmount: string; + totalCurrencyAmount: string; + usedCoupon: boolean; + couponTokenId: string; + couponQuantity: string; + completedOrderAppealCount: number; + totalCompletedOrderAppealCount: number; + realOrderStatus: number; + appealVersion: number; + judgeInfo: P2PJudgeInfoV5; + helpType: string; + appealFlowStatus: string; + appealSubStatus: string; + bulkOrderFlag: boolean; + targetUserType: string; + targetUserDisplays: string[]; + appealProcessChangeFlag: boolean; + appealNegotiationNode: number; +} + +export interface P2POrderMessageV5 { + id: string; + message: string; + userId: string; + msgType: number; + msgCode: number; + createDate: string; + contentType: string; + orderId: string; + msgUuid: string; + nickName: string; + fileName: string; + accountId: string; + isRead: number; + read: number; + roleType: string; + onlyForCustomer: number; +} + +export interface P2PUserInfoV5 { + nickName: string; + defaultNickName: boolean; + isOnline: boolean; + kycLevel: string; + email: string; + mobile: string; + lastLogoutTime: string; + recentRate: string; + totalFinishCount: number; + totalFinishSellCount: number; + totalFinishBuyCount: number; + recentFinishCount: number; + averageReleaseTime: string; + averageTransferTime: string; + accountCreateDays: number; + firstTradeDays: number; + realName: string; + recentTradeAmount: string; + totalTradeAmount: string; + registerTime: string; + authStatus: number; + kycCountryCode: string; + blocked: string; + goodAppraiseRate: string; + goodAppraiseCount: number; + badAppraiseCount: number; + accountId: number; + paymentCount: number; + contactCount: number; + vipLevel: number; + userCancelCountLimit: number; + paymentRealNameUneditable: boolean; + userId: string; + realNameEn: string; +} + +export interface P2PCounterpartyUserInfoV5 { + nickName: string; + defaultNickName: boolean; + whiteFlag: number; + contactConfig: boolean; + isOnline: boolean; + email: string; + mobile: string; + kycLevel: number; + lastLogoutTime: string; + recentRate: number; + totalFinishCount: number; + totalFinishSellCount: number; + totalFinishBuyCount: number; + recentFinishCount: number; + averageReleaseTime: string; + averageTransferTime: string; + accountCreateDays: number; + firstTradeDays: number; + realName: string; + recentTradeAmount: string; + totalTradeAmount: string; + executeNum: number; + orderNum: number; + hasUnPostAd: number; + registerTime: string; + authStatus: number; + kycCountryCode: string; + blocked: string; + goodAppraiseRate: string; + goodAppraiseCount: number; + badAppraiseCount: number; + accountId: string; + paymentCount: number; + contactCount: number; + realNameMask: string; + vipLevel: number; + vipProfit: []; + userTag: []; + userCancelCountLimit: number; + paymentRealNameUneditable: boolean; + lostRoleAffected: boolean; + userCurPrivilege: string[]; + userType: string; + userId: string; + realNameEn: string; + canSubOnline: boolean; + curPrivilegeInfo: []; + openApiSwitch: number; +} + +export interface P2PUserPaymentV5 { + id: string; + realName: string; + paymentType: string; + bankName: string; + branchName: string; + accountNo: string; + qrcode: string; + visible: number; + payMessage: string; + firstName: string; + lastName: string; + secondLastName: string; + clabe: string; + debitCardNumber: string; + mobile: string; + businessName: string; + concept: string; + online: string; + countNo: string; + paymentExt1: string; + paymentExt2: string; + paymentExt3: string; + paymentExt4: string; + paymentExt5: string; + paymentExt6: string; + paymentTemplateVersion: number; + hasPaymentTemplateChanged: boolean; + paymentConfigVo: P2PPaymentConfigV5; + realNameVerified: boolean; + channel: string; + currencyBalance: string[]; +}