@t2000/sdk 0.16.18 → 0.16.19
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.cjs +19 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2962,6 +2962,20 @@ var PortfolioManager = class {
|
|
|
2962
2962
|
this.data.positions[asset] = pos;
|
|
2963
2963
|
this.save();
|
|
2964
2964
|
}
|
|
2965
|
+
closePosition(asset) {
|
|
2966
|
+
this.load();
|
|
2967
|
+
const pos = this.data.positions[asset];
|
|
2968
|
+
if (pos) {
|
|
2969
|
+
pos.totalAmount = 0;
|
|
2970
|
+
pos.costBasis = 0;
|
|
2971
|
+
pos.avgPrice = 0;
|
|
2972
|
+
pos.earning = false;
|
|
2973
|
+
pos.earningProtocol = void 0;
|
|
2974
|
+
pos.earningApy = void 0;
|
|
2975
|
+
this.data.positions[asset] = pos;
|
|
2976
|
+
this.save();
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2965
2979
|
isEarning(asset) {
|
|
2966
2980
|
this.load();
|
|
2967
2981
|
const pos = this.data.positions[asset];
|
|
@@ -4280,6 +4294,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4280
4294
|
tx: swapResult.tx,
|
|
4281
4295
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4282
4296
|
});
|
|
4297
|
+
if (params.usdAmount === "all") {
|
|
4298
|
+
this.portfolio.closePosition(params.asset);
|
|
4299
|
+
}
|
|
4283
4300
|
const updatedPos = this.portfolio.getPosition(params.asset);
|
|
4284
4301
|
const position = {
|
|
4285
4302
|
asset: params.asset,
|
|
@@ -4497,12 +4514,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4497
4514
|
let totalGas = 0;
|
|
4498
4515
|
let gasMethod = "self-funded";
|
|
4499
4516
|
for (const pos of stratPositions) {
|
|
4517
|
+
const fullAmount = pos.totalAmount;
|
|
4500
4518
|
const result = await this.investSell({ asset: pos.asset, usdAmount: "all" });
|
|
4501
4519
|
const pnl = this.portfolio.recordStrategySell(params.strategy, {
|
|
4502
4520
|
id: `strat_sell_${Date.now()}_${pos.asset}`,
|
|
4503
4521
|
type: "sell",
|
|
4504
4522
|
asset: pos.asset,
|
|
4505
|
-
amount:
|
|
4523
|
+
amount: fullAmount,
|
|
4506
4524
|
price: result.price,
|
|
4507
4525
|
usdValue: result.usdValue,
|
|
4508
4526
|
fee: result.fee,
|