MCPcopy Create free account
hub / github.com/ccxt/ccxt / createSubAccount

Method createSubAccount

js/src/pacifica.js:2978–3038  ·  view source on GitHub ↗

* @method * @name pacifica#createSubAccount * @description creates a sub-account under the main account * @param {string} name unused argument * @param {object} [params] extra parameters specific to the exchange API endpoint * @param {int} [params.expiryWindow] time to live

(name, params = {})

Source from the content-addressed store, hash-verified

2976 * @returns {object} a response object
2977 */
2978 async createSubAccount(name, params = {}) {
2979 const finalHeaders = {};
2980 let agentAddress = undefined;
2981 [agentAddress, params] = this.handleOption('createSubAccount', 'agentAddress', undefined);
2982 let originAddress = undefined;
2983 [originAddress, params] = this.handleOriginAndSingleAddress('createSubAccount', params);
2984 if (originAddress === undefined) {
2985 throw new ArgumentsRequired(this.id + ' createSubAccount() requires "originAddress" in params or "walletAddress" in requiredCredentials');
2986 }
2987 if (agentAddress !== undefined) {
2988 finalHeaders['agent_wallet'] = agentAddress;
2989 }
2990 let subAccountAddress = undefined;
2991 [subAccountAddress, params] = this.handleOptionAndParams(params, 'createSubAccount', 'subAccountAddress');
2992 let subAccountPrivateKey = undefined;
2993 [subAccountPrivateKey, params] = this.handleOptionAndParams(params, 'createSubAccount', 'subAccountPrivateKey');
2994 if (subAccountAddress === undefined) {
2995 throw new ArgumentsRequired(this.id + ' createSubAccount() requires a "subAccountAddress"!');
2996 }
2997 if (subAccountPrivateKey === undefined) {
2998 throw new ArgumentsRequired(this.id + ' createSubAccount() requires a "subAccountPrivateKey"!');
2999 }
3000 const timestamp = this.milliseconds();
3001 let expiryWindow = undefined;
3002 [expiryWindow, params] = this.handleOptionAndParams2(params, 'createSubAccount', 'expiryWindow', 'expiry_window', 5000);
3003 const subaccountSignatureHeader = {
3004 'timestamp': timestamp,
3005 'expiry_window': expiryWindow,
3006 'type': 'subaccount_initiate',
3007 };
3008 const subSigPayload = {
3009 'account': originAddress,
3010 };
3011 const subaccountSignature = this.signMessage(subaccountSignatureHeader, subSigPayload, subAccountPrivateKey);
3012 const mainSignatureHeader = {
3013 'timestamp': timestamp,
3014 'expiry_window': expiryWindow,
3015 'type': 'subaccount_confirm',
3016 };
3017 const mainSigPayload = {
3018 'signature': subaccountSignature,
3019 };
3020 const main_signature = this.signMessage(mainSignatureHeader, mainSigPayload, this.privateKey);
3021 finalHeaders['main_account'] = originAddress;
3022 finalHeaders['subaccount'] = subAccountAddress;
3023 finalHeaders['sub_signature'] = subaccountSignature;
3024 finalHeaders['main_signature'] = main_signature;
3025 finalHeaders['timestamp'] = timestamp;
3026 finalHeaders['expiry_window'] = expiryWindow;
3027 const request = finalHeaders;
3028 const response = await this.privatePostAccountSubaccountCreate(request);
3029 //
3030 // {
3031 // "success": true,
3032 // "data": null,
3033 // "error": null,
3034 // "code": null,
3035 // }

Callers

nothing calls this directly

Calls 7

signMessageMethod · 0.95
handleOptionMethod · 0.45
handleOptionAndParamsMethod · 0.45
millisecondsMethod · 0.45

Tested by

no test coverage detected