Skip to content

Commit 5402a3f

Browse files
authored
Merge pull request #27 from cryptomkt/feat/update-june-2024
Feat/update june 2024
2 parents c5fcece + e2c9d9d commit 5402a3f

File tree

14 files changed

+300
-18
lines changed

14 files changed

+300
-18
lines changed

lib/client.ts

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ACCOUNT,
33
CONTINGENCY,
44
IDENTIFY_BY,
5+
ORDER_BY,
56
ORDER_TYPE,
67
PERIOD,
78
SIDE,
@@ -52,6 +53,26 @@ export class Client {
5253
this.httpClient = new HttpClient(this.apiUrl, this.apiVersion, apiKey, apiSecret, window)
5354
}
5455

56+
/**
57+
* Changes the window used in authenticated calls
58+
*
59+
* @param {number} window acceptable time between request and server execution in millis
60+
*/
61+
changeWindow(window: number) {
62+
this.httpClient.changeWindow(window)
63+
}
64+
65+
66+
/**
67+
* Changes the user credentials used for authentication in calls
68+
*
69+
* @param {string} apiKey the user public key used in new calls
70+
* @param {string} apiSecret the user secret key used in new calls
71+
*/
72+
changeCredentials(apiKey: string, apiSecret: string) {
73+
this.httpClient.changeCredentials(apiKey, apiSecret)
74+
}
75+
5576
async publicGet(endpoint: string, params: any) {
5677
const parsedParams = fromCamelCaseToSnakeCase(params)
5778
const response = this.httpClient.publicGet(endpoint, parsedParams);
@@ -1160,6 +1181,22 @@ Accepted values: never, optionally, required
11601181
return this.post("wallet/crypto/fees/estimate", feeRequests);
11611182
}
11621183

1184+
1185+
/**
1186+
* Get estimates of withdrawal fees
1187+
*
1188+
* Requires the "Payment information" API key Access Right.
1189+
*
1190+
* https://api.exchange.cryptomkt.com/#bulk-estimate-withdrawal-fee
1191+
*
1192+
* @param {FeeRequest[]} feeRequests A list of fee requests
1193+
*
1194+
* @return The list of requested fees
1195+
*/
1196+
async getBulkEstimateWithdrawalFees(feeRequests: FeeRequest[]): Promise<Fee[]> {
1197+
return this.post("wallet/crypto/fee/estimate/bulk", feeRequests);
1198+
}
1199+
11631200
/**
11641201
* Get an estimate of a withdrawal fee
11651202
*
@@ -1183,6 +1220,44 @@ Accepted values: never, optionally, required
11831220
return response["fee"];
11841221
}
11851222

1223+
// /**
1224+
// * Get estimates of deposit fees
1225+
// *
1226+
// * Requires the "Payment information" API key Access Right.
1227+
// *
1228+
// * https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
1229+
// *
1230+
// * @param {FeeRequest[]} feeRequests A list of fee requests
1231+
// *
1232+
// * @return The list of requested fees
1233+
// */
1234+
// async getBulkEstimateDepositFees(feeRequests: FeeRequest[]): Promise<Fee[]> {
1235+
// return this.post("wallet/crypto/fee/deposit/estimate/bulk", feeRequests);
1236+
// }
1237+
1238+
// /**
1239+
// * Get an estimate of a deposit fee
1240+
// *
1241+
// * Requires the "Payment information" API key Access Right.
1242+
// *
1243+
// * https://api.exchange.cryptomkt.com/#estimate-deposit-fee
1244+
// *
1245+
// * @param {object} params
1246+
// * @param {string} params.currency the currency code for deposit
1247+
// * @param {string} params.amount the expected deposit amount
1248+
// * @param {string} [params.netwrokCode] Optional. Network code
1249+
// *
1250+
// * @return The expected fee
1251+
// */
1252+
// async getEstimateDepositFee(params: {
1253+
// currency: string;
1254+
// amount: string;
1255+
// networkCode?: string;
1256+
// }): Promise<string> {
1257+
// const response = await this.get("wallet/crypto/fee/deposit/estimate", params);
1258+
// return response["fee"];
1259+
// }
1260+
11861261
/**
11871262
* Converts between currencies
11881263
*
@@ -1301,9 +1376,9 @@ Accepted values: wallet, spot. Must not be the same as source
13011376
* @param {TRANSACTION_STATUS[]} [params.statuses] Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
13021377
* @param {string[]} [params.currencies] Optional. List of currencies of the transactions
13031378
* @param {string[]} [params.networks] Optional. List of network codes
1304-
* @param {SORT_BY} [params.orderBy] Optional. Defines the sorting type.'createdAt' or 'id'. Default is 'createdAt'
1305-
* @param {string} [params.from] Optional. Interval initial value when ordering by 'createdAt'. As Datetime
1306-
* @param {string} [params.till] Optional. Interval end value when ordering by 'createdAt'. As Datetime
1379+
* @param {ORDER_BY} [params.orderBy] Optional. Defines the sorting type.'CREATED_AT', 'UPDATED_AT', 'LAST_ACTIVITY_AT' or 'ID'. Default is 'CREATED_AT'
1380+
* @param {string} [params.from] Optional. Interval initial value (inclusive). The value type depends on orderBy.
1381+
* @param {string} [params.till] Optional. Interval end value (inclusive). The value type depends on orderBy.
13071382
* @param {string} [params.idFrom] Optional. Interval initial value when ordering by id. Min is 0
13081383
* @param {string} [params.idTill] Optional. Interval end value when ordering by id. Min is 0
13091384
* @param {string} [params.sort] Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
@@ -1320,7 +1395,7 @@ Accepted values: wallet, spot. Must not be the same as source
13201395
statuses?: TRANSACTION_STATUS[];
13211396
currencies?: string[],
13221397
networks?: string[],
1323-
orderBy?: SORT_BY;
1398+
orderBy?: ORDER_BY;
13241399
from?: string;
13251400
till?: string;
13261401
idFrom?: string;

lib/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ export enum SORT {
2727

2828
export enum SORT_BY {
2929
TIMESTAMP = "timestamp",
30+
ID = "id",
31+
}
32+
33+
34+
export enum ORDER_BY {
3035
CREATED_AT = "created_at",
36+
UPDATED_AT = "updated_at",
37+
LAST_ACTIVITY_AT = "last_activity_at",
3138
ID = "id",
3239
}
3340

lib/hmac.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export class HMAC {
1616
this.window = window
1717
}
1818

19+
changeWindow(window: number) {
20+
this.window = window;
21+
}
22+
23+
changeCredentials(apiKey: string, apiSecret: string) {
24+
this.apiKey = apiKey;
25+
this.apiSecret = apiSecret;
26+
}
27+
1928
/**+
2029
*
2130
* @param {URL} url

lib/httpClient.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ export class HttpClient {
1717
this.hmac = new HMAC(apiKey, apiSecret, window)
1818
}
1919

20+
21+
changeWindow(window: number) {
22+
this.hmac.changeWindow(window)
23+
}
24+
25+
changeCredentials(apiKey: string, apiSecret: string) {
26+
this.hmac.changeCredentials(apiKey, apiSecret)
27+
}
28+
2029
async makeRequest(
2130
method: HTTP_METHOD,
2231
endpoint: string,

lib/models/Fee.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export interface Fee {
22
fee: string;
33
currency: string;
44
amount: string;
5-
networkFee: string;
5+
networkFee?: string;
66
}

lib/models/Network.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ export interface Network {
1414
lowProcessingTime: string;
1515
highProcessingTime: string;
1616
avgProcessingTime: string;
17+
code: string;
18+
networkName: string;
19+
isEnsAvailable: boolean;
20+
crypto_paymentIdName: string;
21+
cryptoExplorer: string;
22+
contractAddress: string;
23+
isMultichain: boolean;
24+
assetId: Map<string, string>;
1725
}

lib/models/Transactions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface Transaction {
66
subtype: string;
77
createdAt: string;
88
updatedAt: string;
9+
lastActivityAt: string;
910
native: NativeTransaction;
1011
commitRisk: CommitRisk;
1112
}

lib/websocket/walletClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AuthClient } from "./authClient";
22
import { Balance, Transaction } from "../models";
33
import {
44
NOTIFICATION_TYPE,
5+
ORDER_BY,
56
SORT,
67
SORT_BY,
78
TRANSACTION_STATUS,
@@ -94,11 +95,11 @@ export class WalletClient extends AuthClient {
9495
* @param {TRANSACTION_TYPE[]} [params.transactionTypes] Optional. List of types to query. valid types are: 'DEPOSIT', 'WITHDRAW', 'TRANSFER' and 'SWAP'
9596
* @param {TRANSACTION_SUBTYPE[]} [params.transactionSubtyes] Optional. List of subtypes to query. valid subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN', 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO', 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT', 'WALLET_TO_SPOT', 'SPOT_TO_WALLET', 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET', 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and 'INSTANT_EXCHANGE'
9697
* @param {TRANSACTION_STATUS[]} [params.transactionStatuses] Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
97-
* @param {string} [params.from] Optional. Interval initial value when ordering by 'createdAt'. As Datetime
98-
* @param {string} [params.till] Optional. Interval end value when ordering by 'createdAt'. As Datetime
98+
* @param {string} [params.from] Optional. Interval initial value (inclusive). The value type depends on order_by.
99+
* @param {string} [params.till] Optional. Interval end value (inclusive). The value type depends on order_by.
99100
* @param {string} [params.idFrom] Optional. Interval initial value when ordering by id. Min is 0
100101
* @param {string} [params.idTill] Optional. Interval end value when ordering by id. Min is 0
101-
* @param {SORT_BY} [params.orderBy] Optional. sorting parameter.'createdAt' or 'id'. Default is 'createdAt'
102+
* @param {ORDER_BY} [params.orderBy] Optional. Defines the sorting type.'CREATED_AT', 'updatedAt', 'last or 'id'. Default is 'createdAt'
102103
* @param {SORT} [params.sort] Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
103104
* @param {number} [params.limit] Optional. Transactions per query. Defaul is 100. Max is 1000
104105
* @param {number} [params.offset] Optional. Default is 0. Max is 100000
@@ -115,7 +116,7 @@ export class WalletClient extends AuthClient {
115116
till?: string;
116117
idFrom?: number;
117118
idTill?: number;
118-
orderBy?: SORT_BY;
119+
orderBy?: ORDER_BY;
119120
sort?: SORT;
120121
limit?: number;
121122
offset?: number;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from "assert";
2+
import "mocha";
3+
import { Client } from "../../lib/client";
4+
5+
import { CONTINGENCY, ORDER_TYPE, SIDE, TIME_IN_FORCE } from "../../lib/constants";
6+
import {
7+
SECOND,
8+
timeout,
9+
emptyList,
10+
goodBalance,
11+
goodList,
12+
goodOrder,
13+
goodTradingCommission,
14+
listSize,
15+
} from "../testHelpers";
16+
const keys = require("../../../../keys.json");
17+
18+
describe("change credentials test", () => {
19+
let client = new Client(keys.apiKey, keys.apiSecret);
20+
function sleep(ms: number) {
21+
return new Promise((resolve) => setTimeout(resolve, ms));
22+
}
23+
const second = 1000;
24+
beforeEach(async function () {
25+
await sleep(second / 20);
26+
});
27+
describe("change credentials", () => {
28+
it("spot balance", async function () {
29+
this.timeout(0);
30+
let balances = client.getWalletBalances();
31+
assert((await balances).length > 0, "empty balances");
32+
if (!goodList(goodOrder, balances)) assert(false, "not good balances");
33+
client.changeCredentials("", "");
34+
try {
35+
balances = client.getWalletBalances();
36+
assert(false, "should not fail");
37+
} catch (CryptomarketSDKException) {
38+
39+
}
40+
client.changeCredentials(keys.apiKey, keys.apiSecret);
41+
balances = client.getWalletBalances();
42+
assert((await balances).length > 0, "empty balances");
43+
if (!goodList(goodOrder, balances)) assert(false, "not good balances");
44+
});
45+
});
46+
});

test/rest/changeWindow.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from "assert";
2+
import "mocha";
3+
import { Client } from "../../lib/client";
4+
5+
import { CONTINGENCY, ORDER_TYPE, SIDE, TIME_IN_FORCE } from "../../lib/constants";
6+
import {
7+
SECOND,
8+
timeout,
9+
emptyList,
10+
goodBalance,
11+
goodList,
12+
goodOrder,
13+
goodTradingCommission,
14+
listSize,
15+
} from "../testHelpers";
16+
const keys = require("../../../../keys.json");
17+
18+
describe("change window test", () => {
19+
let client = new Client(keys.apiKey, keys.apiSecret);
20+
function sleep(ms: number) {
21+
return new Promise((resolve) => setTimeout(resolve, ms));
22+
}
23+
const second = 1000;
24+
beforeEach(async function () {
25+
await sleep(second / 20);
26+
});
27+
describe("change window", () => {
28+
it("spot balance", async function () {
29+
this.timeout(0);
30+
let balances = client.getWalletBalances();
31+
assert((await balances).length > 0, "empty balances");
32+
if (!goodList(goodOrder, balances)) assert(false, "not good balances");
33+
client.changeWindow(100);
34+
try {
35+
balances = client.getWalletBalances();
36+
assert(false, "should not fail");
37+
} catch (CryptomarketSDKException) {
38+
39+
}
40+
client.changeWindow(10_000);
41+
balances = client.getWalletBalances();
42+
assert((await balances).length > 0, "empty balances");
43+
if (!goodList(goodOrder, balances)) assert(false, "not good balances");
44+
});
45+
});
46+
});

0 commit comments

Comments
 (0)