@gbozee/ultimate 0.0.2-27 → 0.0.2-29
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/index.d.ts +21 -0
- package/dist/index.js +256 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -151,6 +151,18 @@ export interface BaseExchange {
|
|
|
151
151
|
}): Promise<any>;
|
|
152
152
|
getDelistedSpotSymbols(): Promise<any>;
|
|
153
153
|
getOpenPositions(): Promise<any>;
|
|
154
|
+
crossAccountTransfer(payload: {
|
|
155
|
+
from: {
|
|
156
|
+
owner: string;
|
|
157
|
+
wallet: string;
|
|
158
|
+
};
|
|
159
|
+
to: {
|
|
160
|
+
owner: string;
|
|
161
|
+
wallet: string;
|
|
162
|
+
};
|
|
163
|
+
asset: string;
|
|
164
|
+
amount: number;
|
|
165
|
+
}): Promise<any>;
|
|
154
166
|
}
|
|
155
167
|
export interface BaseSystemFields {
|
|
156
168
|
id: string;
|
|
@@ -604,6 +616,7 @@ declare class ExchangeAccount$1 {
|
|
|
604
616
|
place?: boolean;
|
|
605
617
|
update_db?: boolean;
|
|
606
618
|
raw?: boolean;
|
|
619
|
+
use_current?: boolean;
|
|
607
620
|
}): Promise<any>;
|
|
608
621
|
getPositionConfig(payload: {
|
|
609
622
|
symbol: string;
|
|
@@ -720,6 +733,7 @@ declare class ExchangeAccount$1 {
|
|
|
720
733
|
place?: boolean;
|
|
721
734
|
raw?: boolean;
|
|
722
735
|
tp?: boolean;
|
|
736
|
+
stop?: boolean;
|
|
723
737
|
}): Promise<any>;
|
|
724
738
|
verifyStopLoss(payload: {
|
|
725
739
|
symbol: string;
|
|
@@ -795,6 +809,7 @@ declare class ExchangeAccount$1 {
|
|
|
795
809
|
kind: "long" | "short";
|
|
796
810
|
place?: boolean;
|
|
797
811
|
tp?: boolean;
|
|
812
|
+
stop?: boolean;
|
|
798
813
|
raw?: boolean;
|
|
799
814
|
cancel?: boolean;
|
|
800
815
|
}): Promise<any>;
|
|
@@ -804,14 +819,17 @@ declare class App {
|
|
|
804
819
|
proxyOptions?: {
|
|
805
820
|
proxy?: any;
|
|
806
821
|
ignore_proxy?: boolean;
|
|
822
|
+
canWithdraw?: boolean;
|
|
807
823
|
};
|
|
808
824
|
private getCredentials;
|
|
809
825
|
constructor(app_db: AppDatabase, getCredentials: (account: string, exchange: string) => {
|
|
810
826
|
api_key: string;
|
|
811
827
|
api_secret: string;
|
|
828
|
+
email: string;
|
|
812
829
|
}, proxyOptions?: {
|
|
813
830
|
proxy?: any;
|
|
814
831
|
ignore_proxy?: boolean;
|
|
832
|
+
canWithdraw?: boolean;
|
|
815
833
|
});
|
|
816
834
|
getExchangeAccount(account: ExchangeType): Promise<ExchangeAccount$1>;
|
|
817
835
|
syncAccount(payload: {
|
|
@@ -927,14 +945,17 @@ export declare function initApp(payload: {
|
|
|
927
945
|
getCredentials: (account: string, exchange: string) => {
|
|
928
946
|
api_key: string;
|
|
929
947
|
api_secret: string;
|
|
948
|
+
email: string;
|
|
930
949
|
};
|
|
931
950
|
proxy?: any;
|
|
932
951
|
ignore_proxy?: boolean;
|
|
952
|
+
canWithdraw?: boolean;
|
|
933
953
|
}): Promise<App>;
|
|
934
954
|
export declare function initialize(payload: {
|
|
935
955
|
password?: string;
|
|
936
956
|
proxy?: any;
|
|
937
957
|
ignore_proxy?: boolean;
|
|
958
|
+
canWithdraw?: boolean;
|
|
938
959
|
}): Promise<App>;
|
|
939
960
|
|
|
940
961
|
export {
|
package/dist/index.js
CHANGED
|
@@ -33796,6 +33796,193 @@ function createGapPairs(arr, gap, item) {
|
|
|
33796
33796
|
}
|
|
33797
33797
|
|
|
33798
33798
|
// src/exchanges/binance.ts
|
|
33799
|
+
var CONSTANTS = {
|
|
33800
|
+
SPOT_TO_FIAT: "MAIN_C2C",
|
|
33801
|
+
SPOT_TO_USDT_FUTURE: "MAIN_UMFUTURE",
|
|
33802
|
+
SPOT_TO_COIN_FUTURE: "MAIN_CMFUTURE",
|
|
33803
|
+
SPOT_TO_MARGIN_CROSS: "MAIN_MARGIN",
|
|
33804
|
+
SPOT_TO_MINING: "MAIN_MINING",
|
|
33805
|
+
FIAT_TO_SPOT: "C2C_MAIN",
|
|
33806
|
+
FIAT_TO_USDT_FUTURE: "C2C_UMFUTURE",
|
|
33807
|
+
FIAT_TO_MINING: "C2C_MINING",
|
|
33808
|
+
USDT_FUTURE_TO_SPOT: "UMFUTURE_MAIN",
|
|
33809
|
+
USDT_FUTURE_TO_FIAT: "UMFUTURE_C2C",
|
|
33810
|
+
USDT_FUTURE_TO_MARGIN_CROSS: "UMFUTURE_MARGIN",
|
|
33811
|
+
COIN_FUTURE_TO_SPOT: "CMFUTURE_MAIN",
|
|
33812
|
+
MARGIN_CROSS_TO_SPOT: "MARGIN_MAIN",
|
|
33813
|
+
MARGIN_CROSS_TO_USDT_FUTURE: "MARGIN_UMFUTURE",
|
|
33814
|
+
MINING_TO_SPOT: "MINING_MAIN",
|
|
33815
|
+
MINING_TO_USDT_FUTURE: "MINING_UMFUTURE",
|
|
33816
|
+
MINING_TO_FIAT: "MINING_C2C"
|
|
33817
|
+
};
|
|
33818
|
+
|
|
33819
|
+
class AccountService {
|
|
33820
|
+
getCredentials;
|
|
33821
|
+
proxyAgent;
|
|
33822
|
+
constructor(payload) {
|
|
33823
|
+
this.getCredentials = payload.getCredentials;
|
|
33824
|
+
this.proxyAgent = payload.proxyAgent;
|
|
33825
|
+
}
|
|
33826
|
+
async getAccount(owner) {
|
|
33827
|
+
const credentials = this.getCredentials(owner, "binance");
|
|
33828
|
+
const email = credentials.email;
|
|
33829
|
+
const is_sub_account = owner !== "main_account";
|
|
33830
|
+
return {
|
|
33831
|
+
email,
|
|
33832
|
+
owner,
|
|
33833
|
+
is_sub_account: Boolean(is_sub_account),
|
|
33834
|
+
getFutureAccountClient: (...args) => initClient(credentials, {
|
|
33835
|
+
type: "main",
|
|
33836
|
+
proxyAgent: this.proxyAgent
|
|
33837
|
+
})
|
|
33838
|
+
};
|
|
33839
|
+
}
|
|
33840
|
+
async crossAccountTransfer(symbol, params) {
|
|
33841
|
+
const { to, from, asset, amount } = params;
|
|
33842
|
+
if (to && from && asset && amount) {
|
|
33843
|
+
const toAccount = await this.getAccount(to.owner);
|
|
33844
|
+
const fromAccount = await this.getAccount(from.owner);
|
|
33845
|
+
const mainAccount = await this.getAccount("main_account");
|
|
33846
|
+
const [mainFutureClient, toFutureClient] = await Promise.all([
|
|
33847
|
+
mainAccount.getFutureAccountClient(symbol),
|
|
33848
|
+
toAccount.getFutureAccountClient(symbol)
|
|
33849
|
+
]);
|
|
33850
|
+
const [fromSpotClient, fromFutureClient] = await Promise.all([
|
|
33851
|
+
fromAccount.getFutureAccountClient(symbol),
|
|
33852
|
+
fromAccount.getFutureAccountClient(symbol)
|
|
33853
|
+
]);
|
|
33854
|
+
const isSubAccountTransfer = toAccount.is_sub_account && fromAccount.is_sub_account;
|
|
33855
|
+
const is_coin = !["USDT", "USDC", "BUSD"].includes(asset.toUpperCase());
|
|
33856
|
+
if (from.owner === to.owner) {
|
|
33857
|
+
if (from.wallet === "spot" && to.wallet === "future") {
|
|
33858
|
+
const type = is_coin ? CONSTANTS.SPOT_TO_COIN_FUTURE : CONSTANTS.SPOT_TO_USDT_FUTURE;
|
|
33859
|
+
await fromFutureClient.submitUniversalTransfer({
|
|
33860
|
+
asset: asset.toUpperCase(),
|
|
33861
|
+
amount,
|
|
33862
|
+
type,
|
|
33863
|
+
fromSymbol: symbol,
|
|
33864
|
+
toSymbol: symbol
|
|
33865
|
+
});
|
|
33866
|
+
} else {
|
|
33867
|
+
const type = is_coin ? CONSTANTS.COIN_FUTURE_TO_SPOT : CONSTANTS.USDT_FUTURE_TO_SPOT;
|
|
33868
|
+
await fromFutureClient.submitUniversalTransfer({
|
|
33869
|
+
asset: asset.toUpperCase(),
|
|
33870
|
+
amount,
|
|
33871
|
+
type,
|
|
33872
|
+
fromSymbol: symbol,
|
|
33873
|
+
toSymbol: symbol
|
|
33874
|
+
});
|
|
33875
|
+
}
|
|
33876
|
+
} else {
|
|
33877
|
+
if (from.wallet === "future") {
|
|
33878
|
+
const futureType = is_coin ? 2 : 1;
|
|
33879
|
+
const rr = await mainFutureClient.subAccountFuturesAssetTransfer({
|
|
33880
|
+
email: toAccount.email,
|
|
33881
|
+
toEmail: toAccount.email,
|
|
33882
|
+
fromEmail: fromAccount.email,
|
|
33883
|
+
futuresType: futureType,
|
|
33884
|
+
asset: asset.toUpperCase(),
|
|
33885
|
+
amount
|
|
33886
|
+
});
|
|
33887
|
+
console.log({
|
|
33888
|
+
rr
|
|
33889
|
+
});
|
|
33890
|
+
if (to.wallet === "spot") {
|
|
33891
|
+
const type = is_coin ? CONSTANTS.COIN_FUTURE_TO_SPOT : CONSTANTS.USDT_FUTURE_TO_SPOT;
|
|
33892
|
+
await toFutureClient.submitUniversalTransfer({
|
|
33893
|
+
asset: asset.toUpperCase(),
|
|
33894
|
+
amount,
|
|
33895
|
+
type,
|
|
33896
|
+
fromSymbol: symbol,
|
|
33897
|
+
toSymbol: symbol
|
|
33898
|
+
});
|
|
33899
|
+
}
|
|
33900
|
+
return rr;
|
|
33901
|
+
}
|
|
33902
|
+
if (from.wallet === "spot" && to.wallet === "spot") {
|
|
33903
|
+
if (isSubAccountTransfer) {
|
|
33904
|
+
await fromSpotClient.subAccountTransferToSameMaster({
|
|
33905
|
+
toEmail: toAccount.email,
|
|
33906
|
+
amount,
|
|
33907
|
+
asset: asset.toUpperCase()
|
|
33908
|
+
});
|
|
33909
|
+
} else {
|
|
33910
|
+
const type = is_coin ? CONSTANTS.SPOT_TO_COIN_FUTURE : CONSTANTS.SPOT_TO_USDT_FUTURE;
|
|
33911
|
+
await fromFutureClient.submitUniversalTransfer({
|
|
33912
|
+
asset: asset.toUpperCase(),
|
|
33913
|
+
amount,
|
|
33914
|
+
type,
|
|
33915
|
+
fromSymbol: symbol,
|
|
33916
|
+
toSymbol: symbol
|
|
33917
|
+
});
|
|
33918
|
+
const future_type = is_coin ? 2 : 1;
|
|
33919
|
+
await mainFutureClient.subAccountFuturesAssetTransfer({
|
|
33920
|
+
toEmail: toAccount.email,
|
|
33921
|
+
fromEmail: fromAccount.email,
|
|
33922
|
+
futuresType: future_type,
|
|
33923
|
+
asset: asset.toUpperCase(),
|
|
33924
|
+
amount
|
|
33925
|
+
});
|
|
33926
|
+
const _type_second = is_coin ? CONSTANTS.COIN_FUTURE_TO_SPOT : CONSTANTS.USDT_FUTURE_TO_SPOT;
|
|
33927
|
+
await toFutureClient.submitUniversalTransfer({
|
|
33928
|
+
asset: asset.toUpperCase(),
|
|
33929
|
+
amount,
|
|
33930
|
+
type: _type_second,
|
|
33931
|
+
fromSymbol: symbol,
|
|
33932
|
+
toSymbol: symbol
|
|
33933
|
+
});
|
|
33934
|
+
}
|
|
33935
|
+
}
|
|
33936
|
+
if (from.wallet === "spot" && to.wallet === "future") {
|
|
33937
|
+
if (isSubAccountTransfer) {
|
|
33938
|
+
await fromSpotClient.subAccountTransferToSameMaster({
|
|
33939
|
+
toEmail: toAccount.email,
|
|
33940
|
+
amount,
|
|
33941
|
+
asset: asset.toUpperCase()
|
|
33942
|
+
});
|
|
33943
|
+
const type = is_coin ? CONSTANTS.SPOT_TO_COIN_FUTURE : CONSTANTS.SPOT_TO_USDT_FUTURE;
|
|
33944
|
+
await toFutureClient.submitUniversalTransfer({
|
|
33945
|
+
asset: asset.toUpperCase(),
|
|
33946
|
+
amount,
|
|
33947
|
+
type,
|
|
33948
|
+
fromSymbol: symbol,
|
|
33949
|
+
toSymbol: symbol
|
|
33950
|
+
});
|
|
33951
|
+
} else {
|
|
33952
|
+
if (!mainAccount.is_sub_account) {
|
|
33953
|
+
const type = is_coin ? CONSTANTS.SPOT_TO_COIN_FUTURE : CONSTANTS.SPOT_TO_USDT_FUTURE;
|
|
33954
|
+
await mainFutureClient.submitUniversalTransfer({
|
|
33955
|
+
asset: asset.toUpperCase(),
|
|
33956
|
+
amount,
|
|
33957
|
+
type,
|
|
33958
|
+
fromSymbol: symbol,
|
|
33959
|
+
toSymbol: symbol
|
|
33960
|
+
});
|
|
33961
|
+
}
|
|
33962
|
+
if (!toAccount.is_sub_account) {
|
|
33963
|
+
const type = is_coin ? CONSTANTS.SPOT_TO_COIN_FUTURE : CONSTANTS.SPOT_TO_USDT_FUTURE;
|
|
33964
|
+
await fromFutureClient.submitUniversalTransfer({
|
|
33965
|
+
asset: asset.toUpperCase(),
|
|
33966
|
+
amount,
|
|
33967
|
+
type,
|
|
33968
|
+
fromSymbol: symbol,
|
|
33969
|
+
toSymbol: symbol
|
|
33970
|
+
});
|
|
33971
|
+
}
|
|
33972
|
+
const future_type = is_coin ? 2 : 1;
|
|
33973
|
+
await mainFutureClient.subAccountFuturesAssetTransfer({
|
|
33974
|
+
toEmail: toAccount.email,
|
|
33975
|
+
fromEmail: fromAccount.email,
|
|
33976
|
+
futuresType: future_type,
|
|
33977
|
+
asset: asset.toUpperCase(),
|
|
33978
|
+
amount
|
|
33979
|
+
});
|
|
33980
|
+
}
|
|
33981
|
+
}
|
|
33982
|
+
}
|
|
33983
|
+
}
|
|
33984
|
+
}
|
|
33985
|
+
}
|
|
33799
33986
|
async function initClient(credentials, options) {
|
|
33800
33987
|
const { proxyAgent, type = "future" } = options || {};
|
|
33801
33988
|
try {
|
|
@@ -34346,10 +34533,16 @@ async function getAllOpenOrders(payload) {
|
|
|
34346
34533
|
class BinanceExchange {
|
|
34347
34534
|
client;
|
|
34348
34535
|
main_client;
|
|
34536
|
+
getCredentials;
|
|
34537
|
+
proxyAgent;
|
|
34349
34538
|
constructor(client, main_client) {
|
|
34350
34539
|
this.client = client;
|
|
34351
34540
|
this.main_client = main_client;
|
|
34352
34541
|
}
|
|
34542
|
+
setAccountDetails(payload) {
|
|
34543
|
+
this.getCredentials = payload.getCredentials;
|
|
34544
|
+
this.proxyAgent = payload.proxyAgent;
|
|
34545
|
+
}
|
|
34353
34546
|
async placeStopOrders(payload) {
|
|
34354
34547
|
if (payload.place) {
|
|
34355
34548
|
return placeStopOrder(this.client, {
|
|
@@ -34617,6 +34810,22 @@ class BinanceExchange {
|
|
|
34617
34810
|
const response = await this.client.getPositionsV3();
|
|
34618
34811
|
return Array.from(new Set(response.map((x) => x.symbol)));
|
|
34619
34812
|
}
|
|
34813
|
+
async crossAccountTransfer(payload) {
|
|
34814
|
+
const { from, to, asset, amount } = payload;
|
|
34815
|
+
if (this.getCredentials) {
|
|
34816
|
+
const instance = new AccountService({
|
|
34817
|
+
getCredentials: this.getCredentials,
|
|
34818
|
+
proxyAgent: this.proxyAgent
|
|
34819
|
+
});
|
|
34820
|
+
const result = await instance.crossAccountTransfer("BTCUSDT", {
|
|
34821
|
+
from: { owner: from.owner, wallet: from.wallet },
|
|
34822
|
+
to: { owner: to.owner, wallet: to.wallet },
|
|
34823
|
+
asset,
|
|
34824
|
+
amount
|
|
34825
|
+
});
|
|
34826
|
+
return result;
|
|
34827
|
+
}
|
|
34828
|
+
}
|
|
34620
34829
|
}
|
|
34621
34830
|
function getPricePlaces(target) {
|
|
34622
34831
|
const numStr = target.toString();
|
|
@@ -35287,6 +35496,8 @@ class BybitExchange {
|
|
|
35287
35496
|
async getDelistedSpotSymbols() {
|
|
35288
35497
|
return [];
|
|
35289
35498
|
}
|
|
35499
|
+
async crossAccountTransfer(payload) {
|
|
35500
|
+
}
|
|
35290
35501
|
}
|
|
35291
35502
|
|
|
35292
35503
|
// src/helpers/accounts.ts
|
|
@@ -35523,7 +35734,10 @@ function processPosition(codeNode, input, kind) {
|
|
|
35523
35734
|
}
|
|
35524
35735
|
async function reduceMajorPositionCalculation(input, exchange_instance) {
|
|
35525
35736
|
try {
|
|
35526
|
-
|
|
35737
|
+
let conditionsCheck = input.position.tp_quantity !== input.quantity || input.position.take_profit !== to_f(input.stop, input.price_places);
|
|
35738
|
+
if (input.opposite_position.stop_quantity) {
|
|
35739
|
+
conditionsCheck = conditionsCheck || input.opposite_position.stop_quantity !== input.to_place.quantity;
|
|
35740
|
+
}
|
|
35527
35741
|
console.log("conditionsCheck for ", input.position.kind, conditionsCheck);
|
|
35528
35742
|
console.log("opposite_check", {
|
|
35529
35743
|
kind: input.opposite_position.kind,
|
|
@@ -36339,9 +36553,13 @@ class ExchangeAccount {
|
|
|
36339
36553
|
return result;
|
|
36340
36554
|
}
|
|
36341
36555
|
if (action === "place_stop_orders" && payload.place) {
|
|
36556
|
+
const instance = await this.syncAccount({
|
|
36557
|
+
symbol: payload.symbol,
|
|
36558
|
+
kind: app_config.kind
|
|
36559
|
+
});
|
|
36342
36560
|
let result = await this.exchange.placeStopOrders({
|
|
36343
36561
|
symbol: payload.symbol,
|
|
36344
|
-
quantity: trades[0].avg_size,
|
|
36562
|
+
quantity: payload.use_current ? instance.quantity : trades[0].avg_size,
|
|
36345
36563
|
kind: app_config.kind,
|
|
36346
36564
|
stop: payload.stop,
|
|
36347
36565
|
price_places: app_config.price_places,
|
|
@@ -36368,13 +36586,13 @@ class ExchangeAccount {
|
|
|
36368
36586
|
if (db_position) {
|
|
36369
36587
|
const config = db_position.expand?.config;
|
|
36370
36588
|
const params = {
|
|
36371
|
-
entry: payload.params.entry !== undefined ? payload.params.entry : config
|
|
36372
|
-
stop: payload.params.stop !== undefined ? payload.params.stop : config
|
|
36373
|
-
risk_reward: payload.params.risk_reward !== undefined ? payload.params.risk_reward : config
|
|
36374
|
-
risk: payload.params.risk !== undefined ? payload.params.risk : config
|
|
36375
|
-
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config
|
|
36589
|
+
entry: payload.params.entry !== undefined ? payload.params.entry : config?.entry,
|
|
36590
|
+
stop: payload.params.stop !== undefined ? payload.params.stop : config?.stop,
|
|
36591
|
+
risk_reward: payload.params.risk_reward !== undefined ? payload.params.risk_reward : config?.risk_reward,
|
|
36592
|
+
risk: payload.params.risk !== undefined ? payload.params.risk : config?.risk,
|
|
36593
|
+
profit_percent: payload.params.profit_percent !== undefined ? payload.params.profit_percent : config?.profit_percent,
|
|
36376
36594
|
place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
|
|
36377
|
-
profit: payload.params.profit !== undefined ? payload.params.profit : config
|
|
36595
|
+
profit: payload.params.profit !== undefined ? payload.params.profit : config?.profit
|
|
36378
36596
|
};
|
|
36379
36597
|
return await this.app_db.createOrUpdatePositionConfig(db_position, params);
|
|
36380
36598
|
}
|
|
@@ -36685,7 +36903,7 @@ class ExchangeAccount {
|
|
|
36685
36903
|
return null;
|
|
36686
36904
|
}
|
|
36687
36905
|
async triggerTradeFromConfig(payload) {
|
|
36688
|
-
const { symbol, kind, place = true } = payload;
|
|
36906
|
+
const { symbol, kind, place = true, stop } = payload;
|
|
36689
36907
|
const position2 = await this.syncAccount({
|
|
36690
36908
|
symbol,
|
|
36691
36909
|
kind
|
|
@@ -36693,14 +36911,16 @@ class ExchangeAccount {
|
|
|
36693
36911
|
if (position2?.config) {
|
|
36694
36912
|
const config = position2.expand.config;
|
|
36695
36913
|
let entry = payload.tp ? position2.entry || config.entry : config.entry;
|
|
36696
|
-
|
|
36914
|
+
const v = stop ? "place_stop_orders" : "place_limit_orders";
|
|
36915
|
+
return await this.placeSharedOrder(v, {
|
|
36697
36916
|
symbol,
|
|
36698
36917
|
entry,
|
|
36699
36918
|
stop: config.stop,
|
|
36700
36919
|
risk_reward: config.risk_reward,
|
|
36701
36920
|
risk: config.risk,
|
|
36702
36921
|
place,
|
|
36703
|
-
raw: payload.raw
|
|
36922
|
+
raw: payload.raw,
|
|
36923
|
+
use_current: Boolean(stop)
|
|
36704
36924
|
});
|
|
36705
36925
|
}
|
|
36706
36926
|
}
|
|
@@ -37446,7 +37666,7 @@ class ExchangeAccount {
|
|
|
37446
37666
|
return 0;
|
|
37447
37667
|
}
|
|
37448
37668
|
async placeTrade(payload) {
|
|
37449
|
-
const { symbol, kind, place, tp, raw: _raw, cancel } = payload;
|
|
37669
|
+
const { symbol, kind, place, tp, raw: _raw, cancel, stop } = payload;
|
|
37450
37670
|
if (cancel) {
|
|
37451
37671
|
await this.cancelOrders({
|
|
37452
37672
|
symbol,
|
|
@@ -37457,7 +37677,8 @@ class ExchangeAccount {
|
|
|
37457
37677
|
return await this.triggerTradeFromConfig({
|
|
37458
37678
|
symbol,
|
|
37459
37679
|
kind,
|
|
37460
|
-
raw: payload.raw
|
|
37680
|
+
raw: payload.raw,
|
|
37681
|
+
stop
|
|
37461
37682
|
});
|
|
37462
37683
|
}
|
|
37463
37684
|
await this.syncAccount({
|
|
@@ -37502,17 +37723,25 @@ function getExchangeKlass(exchange) {
|
|
|
37502
37723
|
if (!client) {
|
|
37503
37724
|
throw new Error(`Failed to initialize ${exchange} client`);
|
|
37504
37725
|
}
|
|
37505
|
-
|
|
37726
|
+
const instance = new func(client, main_client);
|
|
37727
|
+
if (payload.canWithdraw) {
|
|
37728
|
+
instance.setAccountDetails({
|
|
37729
|
+
getCredentials: payload.getCredentials,
|
|
37730
|
+
proxyAgent: payload.proxyAgent
|
|
37731
|
+
});
|
|
37732
|
+
}
|
|
37733
|
+
return instance;
|
|
37506
37734
|
};
|
|
37507
37735
|
}
|
|
37508
37736
|
async function getExchangeAccount(payload) {
|
|
37509
|
-
const { account, app_db, proxyOptions = {} } = payload;
|
|
37737
|
+
const { account, app_db, proxyOptions = {}, canWithdraw = false } = payload;
|
|
37510
37738
|
const _proxyAgent = await app_db.getProxyForAccount(account);
|
|
37511
37739
|
const proxyAgent = proxyOptions?.ignore_proxy ? null : proxyOptions?.proxy || _proxyAgent;
|
|
37512
37740
|
const exchange_instance = await getExchangeKlass(account.exchange)({
|
|
37513
37741
|
account: account.owner,
|
|
37514
37742
|
getCredentials: payload.getCredentials,
|
|
37515
|
-
proxyAgent
|
|
37743
|
+
proxyAgent,
|
|
37744
|
+
canWithdraw
|
|
37516
37745
|
});
|
|
37517
37746
|
return new ExchangeAccount(payload.account, {
|
|
37518
37747
|
exchange: exchange_instance,
|
|
@@ -37535,7 +37764,8 @@ class App {
|
|
|
37535
37764
|
account,
|
|
37536
37765
|
app_db: this.app_db,
|
|
37537
37766
|
getCredentials: this.getCredentials,
|
|
37538
|
-
proxyOptions: this.proxyOptions
|
|
37767
|
+
proxyOptions: this.proxyOptions,
|
|
37768
|
+
canWithdraw: this.proxyOptions?.canWithdraw
|
|
37539
37769
|
});
|
|
37540
37770
|
}
|
|
37541
37771
|
async syncAccount(payload) {
|
|
@@ -37914,7 +38144,8 @@ async function initApp(payload) {
|
|
|
37914
38144
|
}
|
|
37915
38145
|
return {
|
|
37916
38146
|
api_key: credential?.api_key,
|
|
37917
|
-
api_secret: credential?.api_secret
|
|
38147
|
+
api_secret: credential?.api_secret,
|
|
38148
|
+
email: credential?.email
|
|
37918
38149
|
};
|
|
37919
38150
|
};
|
|
37920
38151
|
}
|
|
@@ -37924,7 +38155,8 @@ async function initApp(payload) {
|
|
|
37924
38155
|
}
|
|
37925
38156
|
const app = new App(app_db, _getCredentials, {
|
|
37926
38157
|
proxy: payload.proxy,
|
|
37927
|
-
ignore_proxy: payload.ignore_proxy
|
|
38158
|
+
ignore_proxy: payload.ignore_proxy,
|
|
38159
|
+
canWithdraw: payload.canWithdraw
|
|
37928
38160
|
});
|
|
37929
38161
|
return app;
|
|
37930
38162
|
}
|
|
@@ -37960,11 +38192,12 @@ function getCredentials(account, exchange) {
|
|
|
37960
38192
|
}
|
|
37961
38193
|
return {
|
|
37962
38194
|
api_key: apiKey,
|
|
37963
|
-
api_secret: apiSecret
|
|
38195
|
+
api_secret: apiSecret,
|
|
38196
|
+
email: process.env.POCKETBASE_EMAIL
|
|
37964
38197
|
};
|
|
37965
38198
|
}
|
|
37966
38199
|
async function initialize(payload) {
|
|
37967
|
-
const { password, proxy, ignore_proxy } = payload;
|
|
38200
|
+
const { password, proxy, ignore_proxy, canWithdraw } = payload;
|
|
37968
38201
|
const app = await initApp({
|
|
37969
38202
|
db: {
|
|
37970
38203
|
host: process.env.POCKETBASE_HOST,
|
|
@@ -37974,7 +38207,8 @@ async function initialize(payload) {
|
|
|
37974
38207
|
password,
|
|
37975
38208
|
getCredentials,
|
|
37976
38209
|
proxy,
|
|
37977
|
-
ignore_proxy
|
|
38210
|
+
ignore_proxy,
|
|
38211
|
+
canWithdraw
|
|
37978
38212
|
});
|
|
37979
38213
|
return app;
|
|
37980
38214
|
}
|