Skip to content

Commit

Permalink
test: tests for fetch(Cross|Isolated)BorrowRate(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
samgermain committed Apr 25, 2024
1 parent bd99a05 commit 7611553
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 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;
28 changes: 28 additions & 0 deletions 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;
16 changes: 16 additions & 0 deletions 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;
16 changes: 16 additions & 0 deletions 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;

0 comments on commit 7611553

Please sign in to comment.