diff --git a/ts/src/test/Exchange/base/test.crossBorrowRate.ts b/ts/src/test/Exchange/base/test.crossBorrowRate.ts new file mode 100644 index 000000000000..f2225c08744a --- /dev/null +++ b/ts/src/test/Exchange/base/test.crossBorrowRate.ts @@ -0,0 +1,22 @@ +import { Exchange } from "../../../../ccxt"; +import testSharedMethods from './test.sharedMethods.js'; + +function testCrossBorrowRate (exchange: Exchange, skippedProperties: object, method: string, entry: object, requestedCode: string) { + const format = { + 'info': {}, // Or [] + 'currency': 'USDT', + 'timestamp': 1638230400000, + 'datetime': '2021-11-30T00:00:00.000Z', + 'rate': exchange.parseNumber ('0.0006'), // Interest rate + 'period': 86400000, // Amount of time the interest rate is based on in milliseconds + }; + testSharedMethods.assertStructure (exchange, skippedProperties, method, entry, format); + testSharedMethods.assertTimestampAndDatetime (exchange, skippedProperties, method, entry); + testSharedMethods.assertCurrencyCode (exchange, skippedProperties, method, entry, entry['currency'], requestedCode); + // + // assert (borrowRate['period'] === 86400000 || borrowRate['period'] === 3600000) // Milliseconds in an hour or a day + testSharedMethods.assertGreater (exchange, skippedProperties, method, entry, 'period', '0'); + testSharedMethods.assertGreater (exchange, skippedProperties, method, entry, 'rate', '0'); +} + +export default testCrossBorrowRate; diff --git a/ts/src/test/Exchange/base/test.isolatedBorrowRate.ts b/ts/src/test/Exchange/base/test.isolatedBorrowRate.ts new file mode 100644 index 000000000000..0686e1760eb5 --- /dev/null +++ b/ts/src/test/Exchange/base/test.isolatedBorrowRate.ts @@ -0,0 +1,28 @@ +import { Exchange } from "../../../../ccxt"; +import testSharedMethods from './test.sharedMethods.js'; + +function testFetchIsolatedBorrowRate (exchange: Exchange, skippedProperties: object, method: string, entry: object, requestedCode: string) { + const format = { + 'info': {}, // Or [] + 'symbol': 'BTC/USDT', + 'base': 'BTC', + 'baseRate': exchange.parseNumber ('0.0006'), // Interest rate, + 'quote': 'USDT', + 'quoteRate': exchange.parseNumber ('0.0006'), // Interest rate, + 'timestamp': 1638230400000, + 'datetime': '2021-11-30T00:00:00.000Z', + 'period': 86400000, // Amount of time the interest rate is based on in milliseconds + }; + testSharedMethods.assertStructure (exchange, skippedProperties, method, entry, format); + testSharedMethods.assertTimestampAndDatetime (exchange, skippedProperties, method, entry); + testSharedMethods.assertCurrencyCode (exchange, skippedProperties, method, entry, entry['base'], requestedCode); + testSharedMethods.assertCurrencyCode (exchange, skippedProperties, method, entry, entry['quote'], requestedCode); + testSharedMethods.assertSymbol (exchange, skippedProperties, method, entry, 'symbol', requestedCode); + // + // assert (borrowRate['period'] === 86400000 || borrowRate['period'] === 3600000) // Milliseconds in an hour or a day + testSharedMethods.assertGreater (exchange, skippedProperties, method, entry, 'period', '0'); + testSharedMethods.assertGreater (exchange, skippedProperties, method, entry, 'baseRate', '0'); + testSharedMethods.assertGreater (exchange, skippedProperties, method, entry, 'quoteRate', '0'); +} + +export default testFetchIsolatedBorrowRate; diff --git a/ts/src/test/Exchange/test.fetchCrossBorrowRates.ts b/ts/src/test/Exchange/test.fetchCrossBorrowRates.ts new file mode 100644 index 000000000000..a80aeef8531a --- /dev/null +++ b/ts/src/test/Exchange/test.fetchCrossBorrowRates.ts @@ -0,0 +1,16 @@ +import { Exchange } from "../../../ccxt"; +import testSharedMethods from './base/test.sharedMethods.js'; +import testCrossBorrowRate from './base/test.crossBorrowRate.js'; + +async function testFetchCrossBorrowRates (exchange: Exchange, skippedProperties: object, symbol: string) { + const method = 'fetchCrossBorrowRates'; + const borrowRates = await exchange.fetchCrossBorrowRates (symbol); + const codes = Object.keys (borrowRates); + testSharedMethods.assertNonEmtpyArray (exchange, skippedProperties, method, codes); + for (let i = 0; i < codes.length; i++) { + const code = codes[i]; + testCrossBorrowRate (exchange, skippedProperties, method, borrowRates[code], symbol); + } +} + +export default testFetchCrossBorrowRates; diff --git a/ts/src/test/Exchange/test.fetchIsolatedBorrowRates.ts b/ts/src/test/Exchange/test.fetchIsolatedBorrowRates.ts new file mode 100644 index 000000000000..b664ea67f3e6 --- /dev/null +++ b/ts/src/test/Exchange/test.fetchIsolatedBorrowRates.ts @@ -0,0 +1,16 @@ +import { Exchange } from "../../../ccxt"; +import testSharedMethods from './base/test.sharedMethods.js'; +import testIsolatedBorrowRate from './base/test.isolatedBorrowRate.js'; + +async function testFetchIsolatedBorrowRates (exchange: Exchange, skippedProperties: object, symbol: string) { + const method = 'fetchIsolatedBorrowRates'; + const borrowRates = await exchange.fetchIsolatedBorrowRates (symbol); + const codes = Object.keys (borrowRates); + testSharedMethods.assertNonEmtpyArray (exchange, skippedProperties, method, codes); + for (let i = 0; i < codes.length; i++) { + const code = codes[i]; + testIsolatedBorrowRate (exchange, skippedProperties, method, borrowRates[code], symbol); + } +} + +export default testFetchIsolatedBorrowRates;