strategy-tools 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cetus/CetusStrategyApiConnection.d.ts +2 -2
- package/dist/cetus/CetusStrategyApiConnection.js.map +1 -1
- package/dist/cetus/types.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/__mocks__/jose.js +0 -17
- package/jest.config.js +0 -19
- package/src/Signer.ts +0 -4
- package/src/binance/BinanceApiSigner.ts +0 -20
- package/src/binance/BinanceConnection.ts +0 -86
- package/src/binance/BinanceSapiSigner.ts +0 -21
- package/src/binance/BinanceTypes.ts +0 -168
- package/src/binance/connection/BinanceOperationConnection.ts +0 -122
- package/src/binance/connection/BinanceRfqConnection.ts +0 -1
- package/src/cetus/CetusStrategyApiConnection.ts +0 -21
- package/src/cetus/types.ts +0 -35
- package/src/index.ts +0 -7
- package/test/binance/BinanceOperationConnection.test.ts +0 -73
- package/test/binance/BinanceSigner.test.ts +0 -45
- package/test/cetus/CetusStrategyApiConnection.test.ts +0 -39
- package/tsconfig.json +0 -23
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiResponse, ExternalApiConnection, StandardKeyGroup } from "itrm-tools";
|
|
2
|
-
import { CetusStrategy,
|
|
2
|
+
import { CetusStrategy, CetusRate } from "./types";
|
|
3
3
|
export declare class CetusStrategyApiConnection extends ExternalApiConnection {
|
|
4
4
|
constructor(apiUrl: string, keys: StandardKeyGroup);
|
|
5
5
|
getStrategies(params: {
|
|
@@ -8,5 +8,5 @@ export declare class CetusStrategyApiConnection extends ExternalApiConnection {
|
|
|
8
8
|
account: string;
|
|
9
9
|
}): Promise<CetusStrategy[]>;
|
|
10
10
|
saveMemory(strategy: CetusStrategy): Promise<ApiResponse<null>>;
|
|
11
|
-
getRates(): Promise<
|
|
11
|
+
getRates(): Promise<CetusRate[]>;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CetusStrategyApiConnection.js","sourceRoot":"","sources":["../../src/cetus/CetusStrategyApiConnection.ts"],"names":[],"mappings":";;;AAAA,2CAAiG;AAGjG,MAAa,0BAA2B,SAAQ,kCAAqB;IACjE,YAAY,MAAc,EAAE,IAAsB;QAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAuD;QAC9E,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC,OAAO,CAAkB,0BAAa,CAAC,GAAG,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAC;IAC7F,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,QAAuB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAc,0BAAa,CAAC,GAAG,EAAE,kBAAkB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACtH,CAAC;IAEM,KAAK,CAAC,QAAQ;QACjB,OAAO,IAAI,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"CetusStrategyApiConnection.js","sourceRoot":"","sources":["../../src/cetus/CetusStrategyApiConnection.ts"],"names":[],"mappings":";;;AAAA,2CAAiG;AAGjG,MAAa,0BAA2B,SAAQ,kCAAqB;IACjE,YAAY,MAAc,EAAE,IAAsB;QAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAuD;QAC9E,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC,OAAO,CAAkB,0BAAa,CAAC,GAAG,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAC;IAC7F,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,QAAuB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAc,0BAAa,CAAC,GAAG,EAAE,kBAAkB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACtH,CAAC;IAEM,KAAK,CAAC,QAAQ;QACjB,OAAO,IAAI,CAAC,OAAO,CAAc,0BAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACrE,CAAC;CACJ;AAjBD,gEAiBC"}
|
package/dist/cetus/types.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { BinanceConnection as BinanceConnection } from './binance/BinanceConnect
|
|
|
3
3
|
export { BinanceOperationConnection as BinanceOperationConnection } from './binance/connection/BinanceOperationConnection';
|
|
4
4
|
export { BinanceParams as BinanceParams, BinanceResponse as BinanceResponse, BinanceAccountResponse as BinanceAccountResponse, BinanceSymbolStatus as BinanceSymbolStatus, BinanceOrderSide as BinanceOrderSide, BinanceOrderType as BinanceOrderType, BinanceTimeInForce as BinanceTimeInForce, BinanceOrder as BinanceOrder, BinanceOrderStatus as BinanceOrderStatus, BinanceCancelRestrictions as BinanceCancelRestrictions } from './binance/BinanceTypes';
|
|
5
5
|
export { CetusStrategyApiConnection as CetusStrategyApiConnection } from './cetus/CetusStrategyApiConnection';
|
|
6
|
-
export { CetusStrategy as CetusStrategy, StrategyStatus as StrategyStatus,
|
|
6
|
+
export { CetusStrategy as CetusStrategy, StrategyStatus as StrategyStatus, CetusRate as CetusRate } from './cetus/types';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAkF;AAAzE,oHAAA,gBAAgB,OAAoB;AAC7C,iEAAqF;AAA5E,sHAAA,iBAAiB,OAAqB;AAC/C,8FAA2H;AAAlH,wIAAA,0BAA0B,OAA8B;AACjE,uDAAgc;AAAjU,mHAAA,mBAAmB,OAAuB;AAAE,gHAAA,gBAAgB,OAAoB;AAAE,gHAAA,gBAAgB,OAAoB;AAAE,kHAAA,kBAAkB,OAAsB;AAAgC,kHAAA,kBAAkB,OAAsB;AAAE,yHAAA,yBAAyB,OAA6B;AAE/Z,iFAA8G;AAArG,wIAAA,0BAA0B,OAA8B;AACjE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAkF;AAAzE,oHAAA,gBAAgB,OAAoB;AAC7C,iEAAqF;AAA5E,sHAAA,iBAAiB,OAAqB;AAC/C,8FAA2H;AAAlH,wIAAA,0BAA0B,OAA8B;AACjE,uDAAgc;AAAjU,mHAAA,mBAAmB,OAAuB;AAAE,gHAAA,gBAAgB,OAAoB;AAAE,gHAAA,gBAAgB,OAAoB;AAAE,kHAAA,kBAAkB,OAAsB;AAAgC,kHAAA,kBAAkB,OAAsB;AAAE,yHAAA,yBAAyB,OAA6B;AAE/Z,iFAA8G;AAArG,wIAAA,0BAA0B,OAA8B;AACjE,uCAAwH;AAA/E,uGAAA,cAAc,OAAkB"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strategy-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Librería para el desarrollo de estrategias de Cetus",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
11
|
"build": "rimraf ./dist && tsc --skipLibCheck",
|
|
8
12
|
"publish-lib": "npm run build && npm publish",
|
package/__mocks__/jose.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
JWTPayload: class {},
|
|
3
|
-
SignJWT: class {
|
|
4
|
-
setProtectedHeader() { return this; }
|
|
5
|
-
setIssuedAt() { return this; }
|
|
6
|
-
setExpirationTime() { return this; }
|
|
7
|
-
sign() { return Promise.resolve("mocked.jwt.token"); }
|
|
8
|
-
},
|
|
9
|
-
jwtVerify: jest.fn().mockResolvedValue({
|
|
10
|
-
payload: {
|
|
11
|
-
userId: "mock-user-id",
|
|
12
|
-
rolesByPlatform: {},
|
|
13
|
-
status: "active",
|
|
14
|
-
application: "test"
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
};
|
package/jest.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
preset: "jest-puppeteer",
|
|
3
|
-
transform: {
|
|
4
|
-
'^.+\\.ts?$': [
|
|
5
|
-
'ts-jest',
|
|
6
|
-
{
|
|
7
|
-
transpilation: true,
|
|
8
|
-
}
|
|
9
|
-
],
|
|
10
|
-
},
|
|
11
|
-
testEnvironment: 'jest-environment-node',
|
|
12
|
-
testRegex: '/test/.*\\.(test|spec)?\\.(ts|tsx)$',
|
|
13
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
14
|
-
automock: false,
|
|
15
|
-
resetMocks: false,
|
|
16
|
-
moduleNameMapper: {
|
|
17
|
-
'^jose$': '<rootDir>/__mocks__/jose.js'
|
|
18
|
-
}
|
|
19
|
-
};
|
package/src/Signer.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const { KJUR, hextob64 } = require('jsrsasign');
|
|
2
|
-
//import { Signer } from "itrm-tools";
|
|
3
|
-
import { Signer } from "../Signer";
|
|
4
|
-
import { BinanceParams } from "./BinanceTypes";
|
|
5
|
-
|
|
6
|
-
export class BinanceApiSigner implements Signer<BinanceParams, string, string> {
|
|
7
|
-
public sign(params: BinanceParams, key: string): string {
|
|
8
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
9
|
-
const signer = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
|
|
10
|
-
signer.init(key);
|
|
11
|
-
signer.updateString(queryString);
|
|
12
|
-
const signatureHex = signer.sign();
|
|
13
|
-
const signature = hextob64(signatureHex);
|
|
14
|
-
return encodeURIComponent(signature);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public verify(input: BinanceParams, key: string, signature: string): boolean {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { BinanceApiSigner } from "./BinanceApiSigner";
|
|
2
|
-
import { BinanceSapiSignerBinanceApiSigner } from "./BinanceSapiSigner";
|
|
3
|
-
import { BinanceAccountResponse, BinanceParams, BinanceResponse } from "./BinanceTypes";
|
|
4
|
-
import { RequestAxiosCall } from "itrm-tools";
|
|
5
|
-
|
|
6
|
-
export interface BinanceConfig {
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
secretKey: string;
|
|
9
|
-
privateKey: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export class BinanceConnection {
|
|
13
|
-
protected config: BinanceConfig;
|
|
14
|
-
private apiSigner: BinanceApiSigner = new BinanceApiSigner();
|
|
15
|
-
private sapiSigner: BinanceSapiSignerBinanceApiSigner = new BinanceSapiSignerBinanceApiSigner();
|
|
16
|
-
|
|
17
|
-
constructor(config: BinanceConfig) {
|
|
18
|
-
this.config= config;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async getAccount(params: { omitZeroBalances?: boolean; recvWindow?: number; }): Promise<BinanceAccountResponse> {
|
|
22
|
-
let response = await this.sendGetRequest('/api/v3/account', params);
|
|
23
|
-
return {
|
|
24
|
-
makerCommission: response.makerCommission!,
|
|
25
|
-
takerCommission: response.takerCommission!,
|
|
26
|
-
buyerCommission: response.buyerCommission!,
|
|
27
|
-
sellerCommission: response.sellerCommission!,
|
|
28
|
-
commissionRates: {
|
|
29
|
-
maker: parseFloat(response.commissionRates!.maker),
|
|
30
|
-
taker: parseFloat(response.commissionRates!.taker),
|
|
31
|
-
buyer: parseFloat(response.commissionRates!.buyer),
|
|
32
|
-
seller: parseFloat(response.commissionRates!.seller)
|
|
33
|
-
},
|
|
34
|
-
canTrade: response.canTrade!,
|
|
35
|
-
canWithdraw: response.canWithdraw!,
|
|
36
|
-
canDeposit: response.canDeposit!,
|
|
37
|
-
brokered: response.brokered!,
|
|
38
|
-
requireSelfTradePrevention: response.requireSelfTradePrevention!,
|
|
39
|
-
preventSor: response.preventSor!,
|
|
40
|
-
updateTime: response.updateTime!,
|
|
41
|
-
accountType: response.accountType!,
|
|
42
|
-
balances: this.parseBalances(response.balances!),
|
|
43
|
-
permissions: response.permissions!,
|
|
44
|
-
uid: response.uid!
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private parseBalances(balances: { asset: string; free: string; locked: string; }[]) {
|
|
49
|
-
let result = [];
|
|
50
|
-
for (let balance of balances)
|
|
51
|
-
result.push({
|
|
52
|
-
asset: balance.asset,
|
|
53
|
-
free: parseFloat(balance.free),
|
|
54
|
-
locked: parseFloat(balance.locked)
|
|
55
|
-
});
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected async sendGetRequest(endpoint: string, params: BinanceParams) {
|
|
60
|
-
params.timestamp = Date.now();
|
|
61
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
62
|
-
const url = `${this.config.baseUrl}${endpoint}?${queryString}&signature=${this.apiSigner.sign(params, this.config.privateKey)}`;
|
|
63
|
-
return await RequestAxiosCall.get<BinanceResponse>(url, { headers: { "X-MBX-APIKEY": this.config.secretKey } });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
protected async sendPostRequest(endpoint: string, params: BinanceParams) {
|
|
67
|
-
params.timestamp = Date.now();
|
|
68
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
69
|
-
const requestBody = `${queryString}&signature=${this.apiSigner.sign(params, this.config.privateKey)}`;
|
|
70
|
-
return await RequestAxiosCall.post<BinanceResponse>(`${this.config.baseUrl}${endpoint}`, requestBody, { headers: { "X-MBX-APIKEY": this.config.secretKey } });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
protected async sendDeleteRequest(endpoint: string, params: BinanceParams) {
|
|
74
|
-
params.timestamp = Date.now();
|
|
75
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
76
|
-
const url = `${this.config.baseUrl}${endpoint}?${queryString}&signature=${this.apiSigner.sign(params, this.config.privateKey)}`;
|
|
77
|
-
return await RequestAxiosCall.delete<BinanceResponse>(url, { headers: { "X-MBX-APIKEY": this.config.secretKey } });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
protected async sendSapiPostRequest(endpoint: string, params: BinanceParams) {
|
|
81
|
-
params.timestamp = Date.now();
|
|
82
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString().replace(/\%40/g, '@');
|
|
83
|
-
const requestBody = `${queryString}&signature=${this.apiSigner.sign(params, this.config.privateKey)}`;
|
|
84
|
-
return await RequestAxiosCall.post<BinanceResponse>(`${this.config.baseUrl}${endpoint}`, requestBody, { headers: { "X-MBX-APIKEY": this.config.secretKey } });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BinanceParams } from "./BinanceTypes";
|
|
2
|
-
import { HmacSHA256, enc } from "crypto-js";
|
|
3
|
-
import { Signer } from "../Signer";
|
|
4
|
-
|
|
5
|
-
export class BinanceSapiSignerBinanceApiSigner implements Signer<BinanceParams, string, string> {
|
|
6
|
-
public sign(params: BinanceParams, key: string): string {
|
|
7
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
8
|
-
const signature = HmacSHA256(queryString, key).toString(enc.Hex);
|
|
9
|
-
/*const signer = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
|
|
10
|
-
signer.init(key);
|
|
11
|
-
signer.updateString(queryString);
|
|
12
|
-
const signatureHex = signer.sign();
|
|
13
|
-
const signature = hextob64(signatureHex);*/
|
|
14
|
-
console.log(">>> signature:", signature);
|
|
15
|
-
return encodeURIComponent(signature);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public verify(input: BinanceParams, key: string, signature: string): boolean {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
export interface BinanceParams {
|
|
2
|
-
quoteId?: string;
|
|
3
|
-
rfqId?: string;
|
|
4
|
-
baseAsset?: string;
|
|
5
|
-
quoteAsset?: string;
|
|
6
|
-
quantity?: number;
|
|
7
|
-
price?: number;
|
|
8
|
-
settleTime?: number;
|
|
9
|
-
omitZeroBalances?: boolean;
|
|
10
|
-
recvWindow?: number;
|
|
11
|
-
timestamp?: number;
|
|
12
|
-
symbol?: string;
|
|
13
|
-
side?: BinanceOrderSide;
|
|
14
|
-
type?: BinanceOrderType;
|
|
15
|
-
timeInForce?: BinanceTimeInForce;
|
|
16
|
-
quoteOrderQty?: number;
|
|
17
|
-
orderId?: number;
|
|
18
|
-
origClientOrderId?: string;
|
|
19
|
-
newClientOrderId?: string;
|
|
20
|
-
cancelRestrictions?: BinanceCancelRestrictions;
|
|
21
|
-
toEmail?: string;
|
|
22
|
-
asset?: string;
|
|
23
|
-
amount?: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export interface BinanceResponse {
|
|
27
|
-
makerCommission?: number;
|
|
28
|
-
takerCommission?: number;
|
|
29
|
-
buyerCommission?: number,
|
|
30
|
-
sellerCommission?: number,
|
|
31
|
-
commissionRates?: {
|
|
32
|
-
maker: string;
|
|
33
|
-
taker: string;
|
|
34
|
-
buyer: string;
|
|
35
|
-
seller: string;
|
|
36
|
-
},
|
|
37
|
-
canTrade?: boolean;
|
|
38
|
-
canWithdraw?: boolean;
|
|
39
|
-
canDeposit?: boolean;
|
|
40
|
-
brokered?: boolean;
|
|
41
|
-
requireSelfTradePrevention?: boolean;
|
|
42
|
-
preventSor?: boolean;
|
|
43
|
-
updateTime?: number;
|
|
44
|
-
accountType?: string;
|
|
45
|
-
balances?: {
|
|
46
|
-
asset: string;
|
|
47
|
-
free: string;
|
|
48
|
-
locked: string;
|
|
49
|
-
} [];
|
|
50
|
-
permissions?: string[];
|
|
51
|
-
uid?: number;
|
|
52
|
-
symbol?: string;
|
|
53
|
-
orderId?: number;
|
|
54
|
-
orderListId?: number;
|
|
55
|
-
clientOrderId?: string;
|
|
56
|
-
transactTime?: number;
|
|
57
|
-
price?: string;
|
|
58
|
-
origQty?: string;
|
|
59
|
-
executedQty?: string;
|
|
60
|
-
origQuoteOrderQty?: string;
|
|
61
|
-
cummulativeQuoteQty?: string;
|
|
62
|
-
status?: BinanceOrderStatus;
|
|
63
|
-
timeInForce?: BinanceTimeInForce;
|
|
64
|
-
type?: BinanceOrderType;
|
|
65
|
-
side?: BinanceOrderSide;
|
|
66
|
-
workingTime?: number;
|
|
67
|
-
fills?: {
|
|
68
|
-
qty: string;
|
|
69
|
-
price: string;
|
|
70
|
-
tradeId: number;
|
|
71
|
-
commission: string;
|
|
72
|
-
commissionAsset: string;
|
|
73
|
-
}[];
|
|
74
|
-
selfTradePreventionMode?: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface BinanceAccountResponse {
|
|
78
|
-
makerCommission: number;
|
|
79
|
-
takerCommission: number;
|
|
80
|
-
buyerCommission: number;
|
|
81
|
-
sellerCommission: number;
|
|
82
|
-
commissionRates: {
|
|
83
|
-
maker: number;
|
|
84
|
-
taker: number;
|
|
85
|
-
buyer: number;
|
|
86
|
-
seller: number;
|
|
87
|
-
};
|
|
88
|
-
canTrade: boolean;
|
|
89
|
-
canWithdraw: boolean;
|
|
90
|
-
canDeposit: boolean;
|
|
91
|
-
brokered: boolean;
|
|
92
|
-
requireSelfTradePrevention: boolean;
|
|
93
|
-
preventSor: boolean;
|
|
94
|
-
updateTime: number;
|
|
95
|
-
accountType: string;
|
|
96
|
-
balances: {
|
|
97
|
-
asset: string;
|
|
98
|
-
free: number;
|
|
99
|
-
locked: number;
|
|
100
|
-
}[];
|
|
101
|
-
permissions: string[];
|
|
102
|
-
uid: number;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface BinanceOrder {
|
|
106
|
-
symbol: string;
|
|
107
|
-
orderId: number;
|
|
108
|
-
orderListId: number;
|
|
109
|
-
clientOrderId: string;
|
|
110
|
-
transactTime: number;
|
|
111
|
-
price: number;
|
|
112
|
-
origQty: number;
|
|
113
|
-
executedQty: number;
|
|
114
|
-
origQuoteOrderQty: number;
|
|
115
|
-
cummulativeQuoteQty: number;
|
|
116
|
-
status: BinanceOrderStatus;
|
|
117
|
-
timeInForce: BinanceTimeInForce;
|
|
118
|
-
type: BinanceOrderType;
|
|
119
|
-
side: BinanceOrderSide;
|
|
120
|
-
workingTime: number;
|
|
121
|
-
fills: {
|
|
122
|
-
qty: number;
|
|
123
|
-
price: number;
|
|
124
|
-
tradeId: number;
|
|
125
|
-
commission: number;
|
|
126
|
-
commissionAsset: string;
|
|
127
|
-
}[];
|
|
128
|
-
selfTradePreventionMode: string;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export enum BinanceSymbolStatus {
|
|
132
|
-
TRADING = 'TRADING',
|
|
133
|
-
BREAK = 'BREAK',
|
|
134
|
-
HALT = 'HALT'
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export enum BinanceOrderSide {
|
|
138
|
-
BUY = 'BUY',
|
|
139
|
-
SELL = 'SELL'
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export enum BinanceOrderType {
|
|
143
|
-
LIMIT = 'LIMIT',
|
|
144
|
-
MARKET = 'MARKET',
|
|
145
|
-
STOP_LOSS = 'STOP_LOSS',
|
|
146
|
-
STOP_LOSS_LIMIT = 'STOP_LOSS_LIMIT',
|
|
147
|
-
TAKE_PROFIT = 'TAKE_PROFIT',
|
|
148
|
-
TAKE_PROFIT_LIMIT = 'TAKE_PROFIT_LIMIT',
|
|
149
|
-
LIMIT_MAKER = 'LIMIT_MAKER'
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export enum BinanceTimeInForce {
|
|
153
|
-
GOOD_TILL_CANCELED = 'GTC',
|
|
154
|
-
INMEDIATE_OR_CANCEL = 'IOC',
|
|
155
|
-
FILL_OR_KILL = 'FOK'
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export enum BinanceOrderStatus {
|
|
159
|
-
NEW = 'NEW',
|
|
160
|
-
FILLED = 'FILLED',
|
|
161
|
-
CANCELED = 'CANCELED',
|
|
162
|
-
PARTIALLY_FILLED = 'PARTIALLY_FILLED'
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export enum BinanceCancelRestrictions {
|
|
166
|
-
ONLY_NEW = 'ONLY_NEW',
|
|
167
|
-
ONLY_PARTIALLY_FILLED = 'ONLY_PARTIALLY_FILLED'
|
|
168
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { RequestAxiosCall } from "itrm-tools";
|
|
2
|
-
import { BinanceConfig, BinanceConnection } from "../BinanceConnection";
|
|
3
|
-
import { BinanceCancelRestrictions, BinanceOrder, BinanceOrderSide, BinanceOrderType, BinanceParams, BinanceResponse, BinanceSymbolStatus, BinanceTimeInForce } from "../BinanceTypes";
|
|
4
|
-
|
|
5
|
-
export interface BinanceBookTicker {
|
|
6
|
-
symbol: string;
|
|
7
|
-
bidPrice: number;
|
|
8
|
-
bidQty: number;
|
|
9
|
-
askPrice: number;
|
|
10
|
-
askQty: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class BinanceOperationConnection extends BinanceConnection {
|
|
14
|
-
constructor(config: BinanceConfig) {
|
|
15
|
-
super(config);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public async getBookTicker(symbols: string[]) {
|
|
19
|
-
const url = `${this.config.baseUrl}/api/v3/ticker/bookTicker?symbols=${JSON.stringify(symbols)}`;
|
|
20
|
-
let response = await RequestAxiosCall.get<{ symbol: string; bidPrice: string; bidQty: string; askPrice: string; askQty: string; }[]>(url);
|
|
21
|
-
let result: BinanceBookTicker[] = [];
|
|
22
|
-
for (let value of response)
|
|
23
|
-
result.push({
|
|
24
|
-
symbol: value.symbol,
|
|
25
|
-
askPrice: parseFloat(value.askPrice),
|
|
26
|
-
askQty: parseFloat(value.askQty),
|
|
27
|
-
bidPrice: parseFloat(value.bidPrice),
|
|
28
|
-
bidQty: parseFloat(value.bidQty)
|
|
29
|
-
});
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async createOrder(params: {
|
|
34
|
-
symbol: string;
|
|
35
|
-
side: BinanceOrderSide;
|
|
36
|
-
type: BinanceOrderType;
|
|
37
|
-
timeInForce: BinanceTimeInForce;
|
|
38
|
-
quantity?: number;
|
|
39
|
-
quoteOrderQty?: number;
|
|
40
|
-
price?: number;
|
|
41
|
-
recvWindow?: number;
|
|
42
|
-
}): Promise<BinanceOrder> {
|
|
43
|
-
let response = await this.sendPostRequest('/api/v3/order', params);
|
|
44
|
-
return this.parseOrder(response);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private parseOrder(response: BinanceResponse) {
|
|
48
|
-
return {
|
|
49
|
-
symbol: response.symbol!,
|
|
50
|
-
orderId: response.orderId!,
|
|
51
|
-
orderListId: response.orderListId!,
|
|
52
|
-
clientOrderId: response.clientOrderId!,
|
|
53
|
-
transactTime: response.transactTime!,
|
|
54
|
-
price: parseFloat(response.price!),
|
|
55
|
-
origQty: parseFloat(response.origQty!),
|
|
56
|
-
executedQty: parseFloat(response.executedQty!),
|
|
57
|
-
origQuoteOrderQty: parseFloat(response.origQuoteOrderQty!),
|
|
58
|
-
cummulativeQuoteQty: parseFloat(response.cummulativeQuoteQty!),
|
|
59
|
-
status: response.status!,
|
|
60
|
-
timeInForce: response.timeInForce!,
|
|
61
|
-
type: response.type!,
|
|
62
|
-
side: response.side!,
|
|
63
|
-
workingTime: response.workingTime!,
|
|
64
|
-
fills: response.fills ? this.parseOrderFills(response.fills!) : [],
|
|
65
|
-
selfTradePreventionMode: response.selfTradePreventionMode!
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private parseOrderFills(fills: { qty: string; price: string; tradeId: number; commission: string; commissionAsset: string; }[]): { qty: number; price: number; tradeId: number; commission: number; commissionAsset: string; }[] {
|
|
70
|
-
let result = [];
|
|
71
|
-
for (let fill of fills)
|
|
72
|
-
result.push({
|
|
73
|
-
qty: parseFloat(fill.qty),
|
|
74
|
-
price: parseFloat(fill.price),
|
|
75
|
-
tradeId: fill.tradeId,
|
|
76
|
-
commission: parseFloat(fill.commission),
|
|
77
|
-
commissionAsset: fill.commissionAsset
|
|
78
|
-
});
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public async cancelOrder(params: {
|
|
83
|
-
symbol: string;
|
|
84
|
-
orderId?: number;
|
|
85
|
-
origClientOrderId?: string;
|
|
86
|
-
newClientOrderId?: string;
|
|
87
|
-
cancelRestrictions?: BinanceCancelRestrictions;
|
|
88
|
-
recvWindow?: number
|
|
89
|
-
}) {
|
|
90
|
-
let response = await this.sendDeleteRequest('/api/v3/order', params);
|
|
91
|
-
return this.parseOrder(response);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public async getOrder(params: {
|
|
95
|
-
symbol: string;
|
|
96
|
-
orderId?: number;
|
|
97
|
-
origClientOrderId?: string;
|
|
98
|
-
recvWindow?: number;
|
|
99
|
-
}) {
|
|
100
|
-
let response = await this.sendGetRequest('/api/v3/order', params);
|
|
101
|
-
return this.parseOrder(response);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public async getOpenOrders(params: { symbol?: string; recvWindow?: number }) {
|
|
105
|
-
let response = (await this.sendGetRequest('/api/v3/openOrders', params) as BinanceResponse[]);
|
|
106
|
-
let result = [];
|
|
107
|
-
for (let order of response)
|
|
108
|
-
result.push(this.parseOrder(order));
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public async transferToSubaccountOfSameMaster(params: {
|
|
113
|
-
toEmail: string;
|
|
114
|
-
asset: string;
|
|
115
|
-
amount: number;
|
|
116
|
-
recvWindow?: number;
|
|
117
|
-
}) {
|
|
118
|
-
//const signature = CryptoJS.HmacSHA256(queryString, SUB_ACCOUNT_SECRET).toString();
|
|
119
|
-
let response = (await this.sendSapiPostRequest('/sapi/v1/sub-account/transfer/subToSub', params));
|
|
120
|
-
return response;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export class BinanceRfqConnection {}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, ExternalApiConnection, RequestMethod, StandardKeyGroup } from "itrm-tools";
|
|
2
|
-
import { CetusStrategy, StrategyRate } from "./types";
|
|
3
|
-
|
|
4
|
-
export class CetusStrategyApiConnection extends ExternalApiConnection {
|
|
5
|
-
constructor(apiUrl: string, keys: StandardKeyGroup) {
|
|
6
|
-
super("cetus", apiUrl, keys);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public async getStrategies(params: { name: string; pair: string; account: string }) {
|
|
10
|
-
const queryString = new URLSearchParams(params as any).toString();
|
|
11
|
-
return this.request<CetusStrategy[]>(RequestMethod.GET, `/v1/strategies?${queryString}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public async saveMemory(strategy: CetusStrategy) {
|
|
15
|
-
return this.request<ApiResponse>(RequestMethod.PUT, `/v1/strategies/${strategy.id}`, { memory: strategy.memory });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public async getRates() {
|
|
19
|
-
return this.request<StrategyRate[]>(RequestMethod.GET, `/v1/rates`);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/cetus/types.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export interface CetusStrategy {
|
|
2
|
-
id: number;
|
|
3
|
-
name: string;
|
|
4
|
-
settings: any;
|
|
5
|
-
memory: any;
|
|
6
|
-
account: string;
|
|
7
|
-
intermediary: string;
|
|
8
|
-
pair: CetusPair;
|
|
9
|
-
status: StrategyStatus;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export enum StrategyStatus {
|
|
13
|
-
RUNNING = "RUNNING",
|
|
14
|
-
BUY_ONLY = "BUY_ONLY",
|
|
15
|
-
SELL_ONLY = "SELL_ONLY",
|
|
16
|
-
STOPPED = "STOPPED"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export enum CetusPair {
|
|
20
|
-
USDCOP = "USDCOP"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface StrategyRate {
|
|
24
|
-
symbol: string;
|
|
25
|
-
source: string;
|
|
26
|
-
date: string;
|
|
27
|
-
bid?: string;
|
|
28
|
-
ask?: string;
|
|
29
|
-
prevDayClose?: string;
|
|
30
|
-
spot?: {
|
|
31
|
-
time: string;
|
|
32
|
-
price: string;
|
|
33
|
-
volume: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { BinanceApiSigner as BinanceApiSigner } from './binance/BinanceApiSigner';
|
|
2
|
-
export { BinanceConnection as BinanceConnection } from './binance/BinanceConnection';
|
|
3
|
-
export { BinanceOperationConnection as BinanceOperationConnection } from './binance/connection/BinanceOperationConnection';
|
|
4
|
-
export { BinanceParams as BinanceParams, BinanceResponse as BinanceResponse, BinanceAccountResponse as BinanceAccountResponse, BinanceSymbolStatus as BinanceSymbolStatus, BinanceOrderSide as BinanceOrderSide, BinanceOrderType as BinanceOrderType, BinanceTimeInForce as BinanceTimeInForce, BinanceOrder as BinanceOrder, BinanceOrderStatus as BinanceOrderStatus, BinanceCancelRestrictions as BinanceCancelRestrictions } from './binance/BinanceTypes';
|
|
5
|
-
|
|
6
|
-
export { CetusStrategyApiConnection as CetusStrategyApiConnection } from './cetus/CetusStrategyApiConnection';
|
|
7
|
-
export { CetusStrategy as CetusStrategy, StrategyStatus as StrategyStatus, StrategyRate as StrategyRate } from './cetus/types'
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BinanceOperationConnection, BinanceAccountResponse, BinanceOrderSide, BinanceOrderType, BinanceTimeInForce, BinanceOrder, BinanceOrderStatus } from "../../dist";
|
|
2
|
-
import 'dotenv/config';
|
|
3
|
-
|
|
4
|
-
const BINANCE_SECRET_KEY = process.env.BINANCE_SECRET_KEY || "";
|
|
5
|
-
const BINANCE_PRIVATE_KEY = process.env.BINANCE_PRIVATE_KEY || "";
|
|
6
|
-
const BINANCE_BASE_URL = process.env.BINANCE_BASE_URL || "";
|
|
7
|
-
const SUBACCOUNT_TO_EMAIL = process.env.SUBACCOUNT_TO_EMAIL || "";
|
|
8
|
-
|
|
9
|
-
describe('testing Binance Signer', () => {
|
|
10
|
-
const connection = new BinanceOperationConnection({
|
|
11
|
-
baseUrl: BINANCE_BASE_URL,
|
|
12
|
-
privateKey: BINANCE_PRIVATE_KEY,
|
|
13
|
-
secretKey: BINANCE_SECRET_KEY
|
|
14
|
-
});
|
|
15
|
-
var order: BinanceOrder | undefined;
|
|
16
|
-
test("> test GET account", async () => {
|
|
17
|
-
let response = await connection.getAccount({ recvWindow: 30000, omitZeroBalances: true });
|
|
18
|
-
//console.log("> response:", response);
|
|
19
|
-
expect(typeof response.accountType).toBe("string");
|
|
20
|
-
}, 30000);
|
|
21
|
-
test("> test GET book ticker", async () => {
|
|
22
|
-
let symbols = ["USDCUSDT", "USDTCOP"];
|
|
23
|
-
let response = await connection.getBookTicker(symbols);
|
|
24
|
-
//console.log("> response:", response);
|
|
25
|
-
expect(response.length).toBe(symbols.length);
|
|
26
|
-
for (let i = 0; i < symbols.length; i++) {
|
|
27
|
-
expect(response[i]).toBeDefined();
|
|
28
|
-
expect(response[i].symbol).toBe(symbols[i]);
|
|
29
|
-
}
|
|
30
|
-
}, 30000);
|
|
31
|
-
test("> test POST order", async () => {
|
|
32
|
-
let tickers = await connection.getBookTicker(["USDTCOP"]);
|
|
33
|
-
order = await connection.createOrder({
|
|
34
|
-
symbol: 'USDTCOP',
|
|
35
|
-
side: BinanceOrderSide.SELL,
|
|
36
|
-
type: BinanceOrderType.LIMIT,
|
|
37
|
-
timeInForce: BinanceTimeInForce.GOOD_TILL_CANCELED,
|
|
38
|
-
price: tickers[0].askPrice,
|
|
39
|
-
quantity: 10,
|
|
40
|
-
recvWindow: 30000
|
|
41
|
-
});
|
|
42
|
-
console.log("> order:", order);
|
|
43
|
-
}, 30000);
|
|
44
|
-
test("> test GET open orders", async () => {
|
|
45
|
-
let orders = await connection.getOpenOrders({ recvWindow: 30000 });
|
|
46
|
-
console.log("> open orders:", orders);
|
|
47
|
-
for (let order of orders)
|
|
48
|
-
expect(order.status).not.toBe(BinanceOrderStatus.CANCELED);
|
|
49
|
-
}, 30000);
|
|
50
|
-
test("> test DELETE order", async () => {
|
|
51
|
-
if (order) {
|
|
52
|
-
let response = await connection.cancelOrder({ orderId: order.orderId, symbol: order.symbol, recvWindow: 30000 });
|
|
53
|
-
console.log("> cancel order response:", response);
|
|
54
|
-
expect(response.status).toBe(BinanceOrderStatus.CANCELED);
|
|
55
|
-
}
|
|
56
|
-
}, 30000);
|
|
57
|
-
test("> test POST transfer to subaccount of the same master", async () => {
|
|
58
|
-
try {
|
|
59
|
-
let account = await connection.getAccount({ recvWindow: 30000 });
|
|
60
|
-
for (let balance of account.balances)
|
|
61
|
-
if (balance.asset === 'COP') {
|
|
62
|
-
console.log("> balance to transfer:", balance);
|
|
63
|
-
let response = await connection.transferToSubaccountOfSameMaster({
|
|
64
|
-
amount: balance.free,
|
|
65
|
-
asset: balance.asset,
|
|
66
|
-
toEmail: SUBACCOUNT_TO_EMAIL,
|
|
67
|
-
recvWindow: 30000
|
|
68
|
-
});
|
|
69
|
-
console.log("> response:", response);
|
|
70
|
-
}
|
|
71
|
-
} catch (err) { console.log("> error:", err); }
|
|
72
|
-
}, 90000);
|
|
73
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BinanceOrderSide, BinanceParams, BinanceApiSigner } from "../../dist";
|
|
2
|
-
const { KJUR, hextob64 } = require('jsrsasign');
|
|
3
|
-
|
|
4
|
-
const PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDBZYTY8h87zTnN\npXLY8aFyQKyqtPLgLGVNz8kft4MzCSHRc956oakGPAgkqREUeYePsOgqvLkobv/c\nbXCfLK2g+7VzSewdJngDAibhm4/vHPUQZWMJQdEj1/HvWoUDnDaEWdxmzJ7cYHqU\nJm/QWKfGe0h/XTnwfmm+EoEjgpH3POCVTIhIe44xc/IawB8QgtfWtdcqDuVaVPG1\nV9a8wOBWUEnbg8tMVLk2q7fLQuQAeCJ5tthTHBvxnWJN+W3BAKnvAyp3PGHLD7sc\nHSbEJGqgY/3OpPySrn223STAJKO/VbOoaMGpC40gfEzvIqXzdiY28OpR2iIjVzXu\nxourugl9AgMBAAECggEABUBP7KIaZgHLDYHuDeT1uMf3yETUiXC7KXM4Z1OQzOx1\nDh5izpqgH8q2f+RVUeSA4U5w52QrdOUarm4MTk4kwsfC5AgAUMRQIujGjH6wWFJF\ndzYBi+lNF/ePmquvC+uMcWiNOv9YWuyFt4sZoyMdHx8O12J9JcIQ9ffDqOatNvTU\noE0+ZsgkMNZI2g6aMk4c8h9UC/kK1e7/Ob1qjPawUvHlRtgbzKhv5ACj05RsK6gm\nOisaIzIZY6R6y7QqDjQcmthIVE8dFGCduAELExK/s05IHHWCfb8hOeTPJfjgRZ2E\nThKy7omWumJD7B6c55Jw26+p2iOSOKQzo0yHis0zkwKBgQDi+N4+9h0RjSe/Tv/v\n0Q6TA2Ei32+eQlKOpee2hVWB8j+Ss1vlwq0e94Dp7BfE9Ip+sg9kMvczpG2sm1lU\nN5RSzs9TQHp+rQnJffYtkcN+6Dd/4pkOP7UsSexf9/858B7xaSRxW1QQNEN3Zlax\nOlB6yWhCC0Osy6EKtgqMElXvLwKBgQDaIWByUX/wPKZMyRiM6hmsJ88/ywFGO+03\nb7t3jqLt8c7wc2lVIp3QIZl1JmpiSj7wDWEPz9X81rxqEpYQa7EiHpB2PRhvdGIl\nB9oj+oOfrmTTRMqNr1ClOJH1XcH4ctBXau2Qpa8/7gVui/ThfcFD1HaGfzU6i4Mz\ntZTRu2EHEwKBgCbgC2jrTJVKAQnSZSHVQ9LIXGXVsU+A+pT2M5behYPJUzw0PkQ/\nMNnB+LGYP4X7gJEsvFgkJpUQz7wlq4oyLtR0GayfuZti1e9OBNFPSxW8fm0ICcEY\nBlb8nmDdoDhzOUmOAbDsvJw952RXAfg/DbPKNXJCbaf2BLJJ9cqCBXf/AoGAdxeD\n9cZDaKFkVkXwzna9n314rKakQnlTcVHic0r/75N23VbVqnKk4M6HXyujJ5jLtfpI\nBP7/IPUIl40gO0Tgx/USAEwo/Cj5sKgR1FTg6hyn1aUYRbTy/dHd9q3Cyme9Eg1C\nORgMj4Xfl1R4VWh4TRVBxPrMz/L9pgy8fKmmNtsCgYA2QODa38wUkXUc/UiITHG7\nK55+oDy4PYGXt/IxcFe9O9Jac20HweecqI7WufCidRwXNo0veFV4sNhwR/vEV8xd\nSSbNPEx6yyRaLGQk9PjDb/Q7R6ujoUkyc3JIdhpHvNv4Dg8d9CvKhfpWO1O99aTL\nOYlYvFINXEfNvjaDvIWyGQ==\n-----END PRIVATE KEY-----";
|
|
5
|
-
|
|
6
|
-
describe('testing Binance Signer', () => {
|
|
7
|
-
const binanceApiSigner = new BinanceApiSigner();
|
|
8
|
-
test("> test GET params", async () => {
|
|
9
|
-
const params: BinanceParams = {
|
|
10
|
-
quoteId: "9131bdc6cd264542aeb572ecea2113f1",
|
|
11
|
-
timestamp: Date.now()
|
|
12
|
-
};
|
|
13
|
-
const queryString = `quoteId=${params.quoteId}×tamp=${params.timestamp}`;
|
|
14
|
-
|
|
15
|
-
const signer = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
|
|
16
|
-
signer.init(PRIVATE_KEY);
|
|
17
|
-
signer.updateString(queryString);
|
|
18
|
-
const signatureHex = signer.sign();
|
|
19
|
-
const signature = hextob64(signatureHex);
|
|
20
|
-
|
|
21
|
-
const encodedSignature = encodeURIComponent(signature);
|
|
22
|
-
expect(binanceApiSigner.sign(params, PRIVATE_KEY)).toMatch(encodedSignature);
|
|
23
|
-
});
|
|
24
|
-
test("> test POST params", async () => {
|
|
25
|
-
const params: BinanceParams = {
|
|
26
|
-
rfqId: "a98d77089cec4d55a918ae20a6994747",
|
|
27
|
-
baseAsset: 'USDC',
|
|
28
|
-
quoteAsset: 'USDT',
|
|
29
|
-
side: BinanceOrderSide.SELL,
|
|
30
|
-
quantity: 1,
|
|
31
|
-
price: 1.1,
|
|
32
|
-
settleTime: 5000,
|
|
33
|
-
timestamp: Date.now()
|
|
34
|
-
};
|
|
35
|
-
const queryString = new URLSearchParams(params as URLSearchParams).toString();
|
|
36
|
-
const signer = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
|
|
37
|
-
signer.init(PRIVATE_KEY);
|
|
38
|
-
signer.updateString(queryString);
|
|
39
|
-
const signatureHex = signer.sign();
|
|
40
|
-
const signature = hextob64(signatureHex);
|
|
41
|
-
|
|
42
|
-
const encodedSignature = encodeURIComponent(signature);
|
|
43
|
-
expect(binanceApiSigner.sign(params, PRIVATE_KEY)).toMatch(encodedSignature);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { CetusStrategy, CetusStrategyApiConnection } from "../../dist";
|
|
2
|
-
|
|
3
|
-
const API_URL = "http://localhost:8309";
|
|
4
|
-
const PUBLIC_KEY = "24df533e3b1ffa697bb98201ca7eeb9c6a25b0d5322b3817280fd78ac61f499b";
|
|
5
|
-
const SECRET_KEY = "WFCbWEDq4hJLrVjYZAOVWZlZou+Wly6Zpn9IR1DCoQzG4uireyxuYbqZeIj1JmLbbehzth+wIXU0Trve54fI1Q==";
|
|
6
|
-
const SIGN_KEY = "EYox9cKS3ZPk5KC6zGXYrxjOS9g5S21ik7CHcKtuip6cuhtsNYKM6kSrWH5R7d4qGTB07M/S1V7QC9G6VHyJRA==";
|
|
7
|
-
|
|
8
|
-
const STRATEGY_SEARCH = { name: "CMA Streamer", pair: "USDCOP", account: "CETUS" };
|
|
9
|
-
|
|
10
|
-
describe('testing Binance Signer', () => {
|
|
11
|
-
const connection = new CetusStrategyApiConnection(API_URL, { publicKey: PUBLIC_KEY, secretKey: SECRET_KEY, signKey: SIGN_KEY });
|
|
12
|
-
test("> test GET Strategies", async () => {
|
|
13
|
-
let strategies = await connection.getStrategies(STRATEGY_SEARCH);
|
|
14
|
-
for (let strategy of strategies) {
|
|
15
|
-
expect(strategy.id).toBeGreaterThan(0);
|
|
16
|
-
expect(strategy.name).toBe("CMA Streamer");
|
|
17
|
-
expect(strategy.account).toBe("CETUS");
|
|
18
|
-
expect(strategy.pair).toBe("USDCOP");
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
test("> test PUT strategies", async () => {
|
|
22
|
-
let strategy = (await connection.getStrategies(STRATEGY_SEARCH))[0];
|
|
23
|
-
expect(strategy).toBeDefined();
|
|
24
|
-
if (strategy) {
|
|
25
|
-
strategy.memory.rand = Math.random();
|
|
26
|
-
console.log("> strategy:", strategy);
|
|
27
|
-
let response = await connection.saveMemory(strategy);
|
|
28
|
-
expect(response.success).toBeTruthy();
|
|
29
|
-
let modifiedStrategy = (await connection.getStrategies(STRATEGY_SEARCH))[0];
|
|
30
|
-
expect(modifiedStrategy.memory.rand).toBe(strategy.memory.rand);
|
|
31
|
-
}
|
|
32
|
-
}, 15000);
|
|
33
|
-
test("> test GET rates", async () => {
|
|
34
|
-
let rates = await connection.getRates();
|
|
35
|
-
for (let rate of rates) {
|
|
36
|
-
expect(rate).toBeDefined();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "nodenext",
|
|
4
|
-
"target": "esnext",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"moduleResolution": "nodenext",
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"emitDecoratorMetadata": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"rootDir": "./src",
|
|
12
|
-
"allowJs": false,
|
|
13
|
-
"strict": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
},
|
|
16
|
-
"include": [
|
|
17
|
-
"src/**/*.ts"
|
|
18
|
-
],
|
|
19
|
-
"exclude": [
|
|
20
|
-
"node_modules",
|
|
21
|
-
"**/*.spec.ts"
|
|
22
|
-
]
|
|
23
|
-
}
|