@zeroexcore/trader 1.0.0
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/README.md +125 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +28 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/book.d.ts +3 -0
- package/dist/commands/book.d.ts.map +1 -0
- package/dist/commands/book.js +44 -0
- package/dist/commands/book.js.map +1 -0
- package/dist/commands/diagnose.d.ts +3 -0
- package/dist/commands/diagnose.d.ts.map +1 -0
- package/dist/commands/diagnose.js +148 -0
- package/dist/commands/diagnose.js.map +1 -0
- package/dist/commands/nft/floor.d.ts +3 -0
- package/dist/commands/nft/floor.d.ts.map +1 -0
- package/dist/commands/nft/floor.js +30 -0
- package/dist/commands/nft/floor.js.map +1 -0
- package/dist/commands/nft/index.d.ts +3 -0
- package/dist/commands/nft/index.d.ts.map +1 -0
- package/dist/commands/nft/index.js +14 -0
- package/dist/commands/nft/index.js.map +1 -0
- package/dist/commands/nft/listings.d.ts +3 -0
- package/dist/commands/nft/listings.d.ts.map +1 -0
- package/dist/commands/nft/listings.js +37 -0
- package/dist/commands/nft/listings.js.map +1 -0
- package/dist/commands/nft/popular.d.ts +3 -0
- package/dist/commands/nft/popular.d.ts.map +1 -0
- package/dist/commands/nft/popular.js +32 -0
- package/dist/commands/nft/popular.js.map +1 -0
- package/dist/commands/nft/portfolio.d.ts +3 -0
- package/dist/commands/nft/portfolio.d.ts.map +1 -0
- package/dist/commands/nft/portfolio.js +43 -0
- package/dist/commands/nft/portfolio.js.map +1 -0
- package/dist/commands/nft/search.d.ts +3 -0
- package/dist/commands/nft/search.d.ts.map +1 -0
- package/dist/commands/nft/search.js +36 -0
- package/dist/commands/nft/search.js.map +1 -0
- package/dist/commands/nft.d.ts +3 -0
- package/dist/commands/nft.d.ts.map +1 -0
- package/dist/commands/nft.js +165 -0
- package/dist/commands/nft.js.map +1 -0
- package/dist/commands/nfts/floor.d.ts +3 -0
- package/dist/commands/nfts/floor.d.ts.map +1 -0
- package/dist/commands/nfts/floor.js +30 -0
- package/dist/commands/nfts/floor.js.map +1 -0
- package/dist/commands/nfts/index.d.ts +3 -0
- package/dist/commands/nfts/index.d.ts.map +1 -0
- package/dist/commands/nfts/index.js +14 -0
- package/dist/commands/nfts/index.js.map +1 -0
- package/dist/commands/nfts/listings.d.ts +3 -0
- package/dist/commands/nfts/listings.d.ts.map +1 -0
- package/dist/commands/nfts/listings.js +37 -0
- package/dist/commands/nfts/listings.js.map +1 -0
- package/dist/commands/nfts/popular.d.ts +3 -0
- package/dist/commands/nfts/popular.d.ts.map +1 -0
- package/dist/commands/nfts/popular.js +32 -0
- package/dist/commands/nfts/popular.js.map +1 -0
- package/dist/commands/nfts/positions.d.ts +3 -0
- package/dist/commands/nfts/positions.d.ts.map +1 -0
- package/dist/commands/nfts/positions.js +23 -0
- package/dist/commands/nfts/positions.js.map +1 -0
- package/dist/commands/nfts/search.d.ts +3 -0
- package/dist/commands/nfts/search.d.ts.map +1 -0
- package/dist/commands/nfts/search.js +36 -0
- package/dist/commands/nfts/search.js.map +1 -0
- package/dist/commands/perps/index.d.ts +3 -0
- package/dist/commands/perps/index.d.ts.map +1 -0
- package/dist/commands/perps/index.js +10 -0
- package/dist/commands/perps/index.js.map +1 -0
- package/dist/commands/perps/info.d.ts +3 -0
- package/dist/commands/perps/info.d.ts.map +1 -0
- package/dist/commands/perps/info.js +51 -0
- package/dist/commands/perps/info.js.map +1 -0
- package/dist/commands/perps/markets.d.ts +3 -0
- package/dist/commands/perps/markets.d.ts.map +1 -0
- package/dist/commands/perps/markets.js +43 -0
- package/dist/commands/perps/markets.js.map +1 -0
- package/dist/commands/perps/pool.d.ts +3 -0
- package/dist/commands/perps/pool.d.ts.map +1 -0
- package/dist/commands/perps/pool.js +33 -0
- package/dist/commands/perps/pool.js.map +1 -0
- package/dist/commands/perps/positions.d.ts +3 -0
- package/dist/commands/perps/positions.d.ts.map +1 -0
- package/dist/commands/perps/positions.js +68 -0
- package/dist/commands/perps/positions.js.map +1 -0
- package/dist/commands/perps/show.d.ts +3 -0
- package/dist/commands/perps/show.d.ts.map +1 -0
- package/dist/commands/perps/show.js +37 -0
- package/dist/commands/perps/show.js.map +1 -0
- package/dist/commands/perps.d.ts +3 -0
- package/dist/commands/perps.d.ts.map +1 -0
- package/dist/commands/perps.js +186 -0
- package/dist/commands/perps.js.map +1 -0
- package/dist/commands/portfolio.d.ts +3 -0
- package/dist/commands/portfolio.d.ts.map +1 -0
- package/dist/commands/portfolio.js +89 -0
- package/dist/commands/portfolio.js.map +1 -0
- package/dist/commands/positions/close.d.ts +3 -0
- package/dist/commands/positions/close.d.ts.map +1 -0
- package/dist/commands/positions/close.js +31 -0
- package/dist/commands/positions/close.js.map +1 -0
- package/dist/commands/positions/filter.d.ts +3 -0
- package/dist/commands/positions/filter.d.ts.map +1 -0
- package/dist/commands/positions/filter.js +20 -0
- package/dist/commands/positions/filter.js.map +1 -0
- package/dist/commands/positions/index.d.ts +3 -0
- package/dist/commands/positions/index.d.ts.map +1 -0
- package/dist/commands/positions/index.js +22 -0
- package/dist/commands/positions/index.js.map +1 -0
- package/dist/commands/positions/list.d.ts +3 -0
- package/dist/commands/positions/list.d.ts.map +1 -0
- package/dist/commands/positions/list.js +38 -0
- package/dist/commands/positions/list.js.map +1 -0
- package/dist/commands/positions/note.d.ts +3 -0
- package/dist/commands/positions/note.d.ts.map +1 -0
- package/dist/commands/positions/note.js +19 -0
- package/dist/commands/positions/note.js.map +1 -0
- package/dist/commands/positions/open.d.ts +3 -0
- package/dist/commands/positions/open.d.ts.map +1 -0
- package/dist/commands/positions/open.js +47 -0
- package/dist/commands/positions/open.js.map +1 -0
- package/dist/commands/positions/show.d.ts +3 -0
- package/dist/commands/positions/show.d.ts.map +1 -0
- package/dist/commands/positions/show.js +46 -0
- package/dist/commands/positions/show.js.map +1 -0
- package/dist/commands/positions/stats.d.ts +3 -0
- package/dist/commands/positions/stats.d.ts.map +1 -0
- package/dist/commands/positions/stats.js +27 -0
- package/dist/commands/positions/stats.js.map +1 -0
- package/dist/commands/positions/tag.d.ts +3 -0
- package/dist/commands/positions/tag.d.ts.map +1 -0
- package/dist/commands/positions/tag.js +19 -0
- package/dist/commands/positions/tag.js.map +1 -0
- package/dist/commands/positions/update.d.ts +3 -0
- package/dist/commands/positions/update.d.ts.map +1 -0
- package/dist/commands/positions/update.js +35 -0
- package/dist/commands/positions/update.js.map +1 -0
- package/dist/commands/positions.d.ts +3 -0
- package/dist/commands/positions.d.ts.map +1 -0
- package/dist/commands/positions.js +247 -0
- package/dist/commands/positions.js.map +1 -0
- package/dist/commands/predict/browse.d.ts +3 -0
- package/dist/commands/predict/browse.d.ts.map +1 -0
- package/dist/commands/predict/browse.js +46 -0
- package/dist/commands/predict/browse.js.map +1 -0
- package/dist/commands/predict/buy.d.ts +3 -0
- package/dist/commands/predict/buy.d.ts.map +1 -0
- package/dist/commands/predict/buy.js +79 -0
- package/dist/commands/predict/buy.js.map +1 -0
- package/dist/commands/predict/claim.d.ts +3 -0
- package/dist/commands/predict/claim.d.ts.map +1 -0
- package/dist/commands/predict/claim.js +58 -0
- package/dist/commands/predict/claim.js.map +1 -0
- package/dist/commands/predict/close.d.ts +3 -0
- package/dist/commands/predict/close.d.ts.map +1 -0
- package/dist/commands/predict/close.js +56 -0
- package/dist/commands/predict/close.js.map +1 -0
- package/dist/commands/predict/index.d.ts +3 -0
- package/dist/commands/predict/index.d.ts.map +1 -0
- package/dist/commands/predict/index.js +20 -0
- package/dist/commands/predict/index.js.map +1 -0
- package/dist/commands/predict/list.d.ts +3 -0
- package/dist/commands/predict/list.d.ts.map +1 -0
- package/dist/commands/predict/list.js +46 -0
- package/dist/commands/predict/list.js.map +1 -0
- package/dist/commands/predict/market.d.ts +3 -0
- package/dist/commands/predict/market.d.ts.map +1 -0
- package/dist/commands/predict/market.js +37 -0
- package/dist/commands/predict/market.js.map +1 -0
- package/dist/commands/predict/positions.d.ts +3 -0
- package/dist/commands/predict/positions.d.ts.map +1 -0
- package/dist/commands/predict/positions.js +71 -0
- package/dist/commands/predict/positions.js.map +1 -0
- package/dist/commands/predict/search.d.ts +3 -0
- package/dist/commands/predict/search.d.ts.map +1 -0
- package/dist/commands/predict/search.js +32 -0
- package/dist/commands/predict/search.js.map +1 -0
- package/dist/commands/predict/sell.d.ts +3 -0
- package/dist/commands/predict/sell.d.ts.map +1 -0
- package/dist/commands/predict/sell.js +65 -0
- package/dist/commands/predict/sell.js.map +1 -0
- package/dist/commands/predict/show.d.ts +3 -0
- package/dist/commands/predict/show.d.ts.map +1 -0
- package/dist/commands/predict/show.js +37 -0
- package/dist/commands/predict/show.js.map +1 -0
- package/dist/commands/predict/watch.d.ts +3 -0
- package/dist/commands/predict/watch.d.ts.map +1 -0
- package/dist/commands/predict/watch.js +73 -0
- package/dist/commands/predict/watch.js.map +1 -0
- package/dist/commands/predict.d.ts +3 -0
- package/dist/commands/predict.d.ts.map +1 -0
- package/dist/commands/predict.js +484 -0
- package/dist/commands/predict.js.map +1 -0
- package/dist/commands/shared.d.ts +18 -0
- package/dist/commands/shared.d.ts.map +1 -0
- package/dist/commands/shared.js +51 -0
- package/dist/commands/shared.js.map +1 -0
- package/dist/commands/tokens/add.d.ts +3 -0
- package/dist/commands/tokens/add.d.ts.map +1 -0
- package/dist/commands/tokens/add.js +17 -0
- package/dist/commands/tokens/add.js.map +1 -0
- package/dist/commands/tokens/browse.d.ts +3 -0
- package/dist/commands/tokens/browse.d.ts.map +1 -0
- package/dist/commands/tokens/browse.js +19 -0
- package/dist/commands/tokens/browse.js.map +1 -0
- package/dist/commands/tokens/index.d.ts +3 -0
- package/dist/commands/tokens/index.d.ts.map +1 -0
- package/dist/commands/tokens/index.js +22 -0
- package/dist/commands/tokens/index.js.map +1 -0
- package/dist/commands/tokens/info.d.ts +3 -0
- package/dist/commands/tokens/info.d.ts.map +1 -0
- package/dist/commands/tokens/info.js +13 -0
- package/dist/commands/tokens/info.js.map +1 -0
- package/dist/commands/tokens/list.d.ts +3 -0
- package/dist/commands/tokens/list.d.ts.map +1 -0
- package/dist/commands/tokens/list.js +16 -0
- package/dist/commands/tokens/list.js.map +1 -0
- package/dist/commands/tokens/positions.d.ts +3 -0
- package/dist/commands/tokens/positions.d.ts.map +1 -0
- package/dist/commands/tokens/positions.js +25 -0
- package/dist/commands/tokens/positions.js.map +1 -0
- package/dist/commands/tokens/quote.d.ts +3 -0
- package/dist/commands/tokens/quote.d.ts.map +1 -0
- package/dist/commands/tokens/quote.js +50 -0
- package/dist/commands/tokens/quote.js.map +1 -0
- package/dist/commands/tokens/remove.d.ts +3 -0
- package/dist/commands/tokens/remove.d.ts.map +1 -0
- package/dist/commands/tokens/remove.js +17 -0
- package/dist/commands/tokens/remove.js.map +1 -0
- package/dist/commands/tokens/search.d.ts +3 -0
- package/dist/commands/tokens/search.d.ts.map +1 -0
- package/dist/commands/tokens/search.js +19 -0
- package/dist/commands/tokens/search.js.map +1 -0
- package/dist/commands/tokens/swap.d.ts +3 -0
- package/dist/commands/tokens/swap.d.ts.map +1 -0
- package/dist/commands/tokens/swap.js +88 -0
- package/dist/commands/tokens/swap.js.map +1 -0
- package/dist/commands/trade/index.d.ts +3 -0
- package/dist/commands/trade/index.d.ts.map +1 -0
- package/dist/commands/trade/index.js +8 -0
- package/dist/commands/trade/index.js.map +1 -0
- package/dist/commands/trade/info.d.ts +3 -0
- package/dist/commands/trade/info.d.ts.map +1 -0
- package/dist/commands/trade/info.js +37 -0
- package/dist/commands/trade/info.js.map +1 -0
- package/dist/commands/trade/quote.d.ts +3 -0
- package/dist/commands/trade/quote.d.ts.map +1 -0
- package/dist/commands/trade/quote.js +56 -0
- package/dist/commands/trade/quote.js.map +1 -0
- package/dist/commands/trade/search.d.ts +3 -0
- package/dist/commands/trade/search.d.ts.map +1 -0
- package/dist/commands/trade/search.js +22 -0
- package/dist/commands/trade/search.js.map +1 -0
- package/dist/commands/trade/swap.d.ts +3 -0
- package/dist/commands/trade/swap.d.ts.map +1 -0
- package/dist/commands/trade/swap.js +70 -0
- package/dist/commands/trade/swap.js.map +1 -0
- package/dist/commands/trade.d.ts +5 -0
- package/dist/commands/trade.d.ts.map +1 -0
- package/dist/commands/trade.js +167 -0
- package/dist/commands/trade.js.map +1 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +45 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +86 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +169 -0
- package/dist/config.js.map +1 -0
- package/dist/utils/amounts.d.ts +40 -0
- package/dist/utils/amounts.d.ts.map +1 -0
- package/dist/utils/amounts.js +113 -0
- package/dist/utils/amounts.js.map +1 -0
- package/dist/utils/helius.d.ts +39 -0
- package/dist/utils/helius.d.ts.map +1 -0
- package/dist/utils/helius.js +253 -0
- package/dist/utils/helius.js.map +1 -0
- package/dist/utils/jupiter.d.ts +42 -0
- package/dist/utils/jupiter.d.ts.map +1 -0
- package/dist/utils/jupiter.js +106 -0
- package/dist/utils/jupiter.js.map +1 -0
- package/dist/utils/nft.d.ts +75 -0
- package/dist/utils/nft.d.ts.map +1 -0
- package/dist/utils/nft.js +168 -0
- package/dist/utils/nft.js.map +1 -0
- package/dist/utils/perps/doves-idl.d.ts +380 -0
- package/dist/utils/perps/doves-idl.d.ts.map +1 -0
- package/dist/utils/perps/doves-idl.js +379 -0
- package/dist/utils/perps/doves-idl.js.map +1 -0
- package/dist/utils/perps/idl.json +7241 -0
- package/dist/utils/perps/index.d.ts +45 -0
- package/dist/utils/perps/index.d.ts.map +1 -0
- package/dist/utils/perps/index.js +102 -0
- package/dist/utils/perps/index.js.map +1 -0
- package/dist/utils/perps/jupiter-perpetuals-idl.d.ts +7243 -0
- package/dist/utils/perps/jupiter-perpetuals-idl.d.ts.map +1 -0
- package/dist/utils/perps/jupiter-perpetuals-idl.js +7242 -0
- package/dist/utils/perps/jupiter-perpetuals-idl.js.map +1 -0
- package/dist/utils/positions.d.ts +198 -0
- package/dist/utils/positions.d.ts.map +1 -0
- package/dist/utils/positions.js +595 -0
- package/dist/utils/positions.js.map +1 -0
- package/dist/utils/prediction.d.ts +196 -0
- package/dist/utils/prediction.d.ts.map +1 -0
- package/dist/utils/prediction.js +187 -0
- package/dist/utils/prediction.js.map +1 -0
- package/dist/utils/solana.d.ts +9 -0
- package/dist/utils/solana.d.ts.map +1 -0
- package/dist/utils/solana.js +45 -0
- package/dist/utils/solana.js.map +1 -0
- package/dist/utils/token-book.d.ts +9 -0
- package/dist/utils/token-book.d.ts.map +1 -0
- package/dist/utils/token-book.js +69 -0
- package/dist/utils/token-book.js.map +1 -0
- package/dist/utils/token-info.d.ts +48 -0
- package/dist/utils/token-info.d.ts.map +1 -0
- package/dist/utils/token-info.js +332 -0
- package/dist/utils/token-info.js.map +1 -0
- package/dist/utils/wallet.d.ts +31 -0
- package/dist/utils/wallet.d.ts.map +1 -0
- package/dist/utils/wallet.js +181 -0
- package/dist/utils/wallet.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,eAAO,MAAM,gBAAgB,SACY,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { listCommand } from './list.js';
|
|
3
|
+
import { openCommand } from './open.js';
|
|
4
|
+
import { closeCommand } from './close.js';
|
|
5
|
+
import { noteCommand } from './note.js';
|
|
6
|
+
import { tagCommand } from './tag.js';
|
|
7
|
+
import { showCommand } from './show.js';
|
|
8
|
+
import { filterCommand } from './filter.js';
|
|
9
|
+
import { statsCommand } from './stats.js';
|
|
10
|
+
import { updateCommand } from './update.js';
|
|
11
|
+
export const positionsCommand = new Command('positions')
|
|
12
|
+
.description('Track trading positions');
|
|
13
|
+
positionsCommand.addCommand(listCommand);
|
|
14
|
+
positionsCommand.addCommand(openCommand);
|
|
15
|
+
positionsCommand.addCommand(closeCommand);
|
|
16
|
+
positionsCommand.addCommand(noteCommand);
|
|
17
|
+
positionsCommand.addCommand(tagCommand);
|
|
18
|
+
positionsCommand.addCommand(showCommand);
|
|
19
|
+
positionsCommand.addCommand(filterCommand);
|
|
20
|
+
positionsCommand.addCommand(statsCommand);
|
|
21
|
+
positionsCommand.addCommand(updateCommand);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/positions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;KACrD,WAAW,CAAC,yBAAyB,CAAC,CAAC;AAE1C,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AACzC,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AACzC,gBAAgB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAC1C,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AACzC,gBAAgB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AACxC,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AACzC,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC3C,gBAAgB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAC1C,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,WAAW,SAmCpB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { calculateTotalPnL, getAllPositions, getOpenPositions } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const listCommand = new Command('list')
|
|
5
|
+
.description('List all open positions')
|
|
6
|
+
.option('-a, --all', 'Show all positions including closed')
|
|
7
|
+
.action((options) => {
|
|
8
|
+
const pos = options.all ? getAllPositions() : getOpenPositions();
|
|
9
|
+
output(pos, () => {
|
|
10
|
+
if (pos.length === 0) {
|
|
11
|
+
return '# Positions\n\nNo positions found.';
|
|
12
|
+
}
|
|
13
|
+
let md = '# Positions\n\n';
|
|
14
|
+
for (const p of pos) {
|
|
15
|
+
md += `## ${p.tokenSymbol} (${p.type.toUpperCase()})\n`;
|
|
16
|
+
md += `- ID: ${p.id}\n`;
|
|
17
|
+
md += `- Status: ${p.status}\n`;
|
|
18
|
+
md += `- Entry: $${p.entryPrice} x ${p.entryAmount} = $${p.entryValueUsd.toFixed(2)}\n`;
|
|
19
|
+
if (p.exitPrice) {
|
|
20
|
+
md += `- Exit: $${p.exitPrice} x ${p.exitAmount} = $${p.exitValueUsd?.toFixed(2)}\n`;
|
|
21
|
+
}
|
|
22
|
+
if (p.pnl !== undefined) {
|
|
23
|
+
md += `- PnL: $${p.pnl.toFixed(2)} (${p.pnlPercent?.toFixed(2)}%)\n`;
|
|
24
|
+
}
|
|
25
|
+
if (p.notes)
|
|
26
|
+
md += `- Notes: ${p.notes}\n`;
|
|
27
|
+
if (p.tags?.length)
|
|
28
|
+
md += `- Tags: ${p.tags.join(', ')}\n`;
|
|
29
|
+
md += '\n';
|
|
30
|
+
}
|
|
31
|
+
if (options.all) {
|
|
32
|
+
const { realized, count } = calculateTotalPnL();
|
|
33
|
+
md += `---\n\n**Total Realized PnL:** $${realized.toFixed(2)} from ${count} closed positions\n`;
|
|
34
|
+
}
|
|
35
|
+
return md;
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/positions/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,yBAAyB,CAAC;KACtC,MAAM,CAAC,WAAW,EAAE,qCAAqC,CAAC;KAC1D,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAEjE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE;QACf,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,oCAAoC,CAAC;QAC9C,C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CAAC,CAAC,CAAC,SAAS,KAAK,qBAAqB,CAAC;QAClG,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,WAAW,SAgBpB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getPosition, updatePositionNotes } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const noteCommand = new Command('note')
|
|
5
|
+
.argument('<position-id>', 'Position ID')
|
|
6
|
+
.argument('<note>', 'Note text')
|
|
7
|
+
.description('Add a note to a position')
|
|
8
|
+
.option('-a, --append', 'Append to existing notes instead of replacing')
|
|
9
|
+
.action((positionId, note, options) => {
|
|
10
|
+
updatePositionNotes(positionId, note, options.append);
|
|
11
|
+
const position = getPosition(positionId);
|
|
12
|
+
if (position) {
|
|
13
|
+
output({ positionId, notes: position.notes }, () => `# Note Updated\n\nPosition: ${positionId}\nNotes: ${position.notes}`);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=note.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note.js","sourceRoot":"","sources":["../../../src/commands/positions/note.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC;KACxC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC/B,WAAW,CAAC,0BAA0B,CAAC;KACvC,MAAM,CAAC,cAAc,EAAE,+CAA+C,CAAC;KACvE,MAAM,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IACpC,mBAAmB,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IACzC,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CACJ,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,EACrC,GAAG,EAAE,CAAC,+BAA+B,UAAU,YAAY,QAAQ,CAAC,KAAK,EAAE,CAC5E,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,8BAA8B,UAAU,EAAE,CAAC,CAAC;IACxG,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,WAAW,SAuCpB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { openPosition } from '../../utils/positions.js';
|
|
3
|
+
import { resolveToken } from '../../utils/token-book.js';
|
|
4
|
+
import { output } from '../shared.js';
|
|
5
|
+
export const openCommand = new Command('open')
|
|
6
|
+
.argument('<type>', 'Position type (long/short)')
|
|
7
|
+
.argument('<token>', 'Token symbol or address')
|
|
8
|
+
.argument('<amount>', 'Entry amount')
|
|
9
|
+
.argument('<price>', 'Entry price')
|
|
10
|
+
.description('Open a new position')
|
|
11
|
+
.option('-t, --target <price>', 'Target price')
|
|
12
|
+
.option('-s, --stop <price>', 'Stop loss price')
|
|
13
|
+
.option('-n, --notes <notes>', 'Position notes')
|
|
14
|
+
.option('--tags <tags>', 'Comma-separated tags')
|
|
15
|
+
.option('--tx <signature>', 'Entry transaction signature')
|
|
16
|
+
.action((type, tokenOrTicker, amount, price, options) => {
|
|
17
|
+
const token = resolveToken(tokenOrTicker);
|
|
18
|
+
const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : undefined;
|
|
19
|
+
const position = openPosition({
|
|
20
|
+
type: type.toLowerCase(),
|
|
21
|
+
token,
|
|
22
|
+
tokenSymbol: tokenOrTicker.toUpperCase(),
|
|
23
|
+
entryPrice: parseFloat(price),
|
|
24
|
+
entryAmount: parseFloat(amount),
|
|
25
|
+
targetPrice: options.target ? parseFloat(options.target) : undefined,
|
|
26
|
+
stopLoss: options.stop ? parseFloat(options.stop) : undefined,
|
|
27
|
+
notes: options.notes,
|
|
28
|
+
tags,
|
|
29
|
+
entryTxSignature: options.tx,
|
|
30
|
+
});
|
|
31
|
+
output(position, () => {
|
|
32
|
+
let md = `# Position Opened\n\n`;
|
|
33
|
+
md += `**${position.tokenSymbol}** (${position.type.toUpperCase()})\n\n`;
|
|
34
|
+
md += `- ID: ${position.id}\n`;
|
|
35
|
+
md += `- Entry: $${position.entryPrice} x ${position.entryAmount} = $${position.entryValueUsd.toFixed(2)}\n`;
|
|
36
|
+
if (position.targetPrice)
|
|
37
|
+
md += `- Target: $${position.targetPrice}\n`;
|
|
38
|
+
if (position.stopLoss)
|
|
39
|
+
md += `- Stop: $${position.stopLoss}\n`;
|
|
40
|
+
if (position.notes)
|
|
41
|
+
md += `- Notes: ${position.notes}\n`;
|
|
42
|
+
if (position.tags?.length)
|
|
43
|
+
md += `- Tags: ${position.tags.join(', ')}\n`;
|
|
44
|
+
return md;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.js","sourceRoot":"","sources":["../../../src/commands/positions/open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,QAAQ,CAAC,QAAQ,EAAE,4BAA4B,CAAC;KAChD,QAAQ,CAAC,SAAS,EAAE,yBAAyB,CAAC;KAC9C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;KACpC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;KAClC,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,sBAAsB,EAAE,cAAc,CAAC;KAC9C,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAAC;KAC/C,MAAM,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/C,MAAM,CAAC,eAAe,EAAE,sBAAsB,CAAC;KAC/C,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC;KACzD,MAAM,CAAC,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IACtD,MAAM,KAAK,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,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D,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM;YAAE,EAAE,IAAI,WAAW,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACzE,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/show.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,WAAW,SAkCpB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getPosition } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const showCommand = new Command('show')
|
|
5
|
+
.argument('<position-id>', 'Position ID')
|
|
6
|
+
.description('Show details for a specific position')
|
|
7
|
+
.action((positionId) => {
|
|
8
|
+
const position = getPosition(positionId);
|
|
9
|
+
if (position) {
|
|
10
|
+
output(position, () => {
|
|
11
|
+
let md = `# Position Details\n\n`;
|
|
12
|
+
md += `**${position.tokenSymbol}** (${position.type.toUpperCase()})\n\n`;
|
|
13
|
+
md += `- ID: ${position.id}\n`;
|
|
14
|
+
md += `- Status: ${position.status}\n`;
|
|
15
|
+
md += `- Entry: $${position.entryPrice} x ${position.entryAmount} = $${position.entryValueUsd.toFixed(2)}\n`;
|
|
16
|
+
md += `- Date: ${position.entryDate}\n`;
|
|
17
|
+
if (position.exitPrice) {
|
|
18
|
+
md += `- Exit: $${position.exitPrice} x ${position.exitAmount} = $${position.exitValueUsd?.toFixed(2)}\n`;
|
|
19
|
+
md += `- Exit Date: ${position.exitDate}\n`;
|
|
20
|
+
}
|
|
21
|
+
if (position.currentPrice) {
|
|
22
|
+
md += `- Current Price: $${position.currentPrice} (updated: ${position.currentPriceUpdatedAt})\n`;
|
|
23
|
+
}
|
|
24
|
+
if (position.pnl !== undefined) {
|
|
25
|
+
md += `- PnL: $${position.pnl.toFixed(2)} (${position.pnlPercent?.toFixed(2)}%)\n`;
|
|
26
|
+
}
|
|
27
|
+
if (position.targetPrice)
|
|
28
|
+
md += `- Target: $${position.targetPrice}\n`;
|
|
29
|
+
if (position.stopLoss)
|
|
30
|
+
md += `- Stop: $${position.stopLoss}\n`;
|
|
31
|
+
if (position.notes)
|
|
32
|
+
md += `- Notes: ${position.notes}\n`;
|
|
33
|
+
if (position.tags?.length)
|
|
34
|
+
md += `- Tags: ${position.tags.join(', ')}\n`;
|
|
35
|
+
if (position.entryTxSignature)
|
|
36
|
+
md += `- Entry TX: ${position.entryTxSignature}\n`;
|
|
37
|
+
if (position.exitTxSignature)
|
|
38
|
+
md += `- Exit TX: ${position.exitTxSignature}\n`;
|
|
39
|
+
return md;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=show.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.js","sourceRoot":"","sources":["../../../src/commands/positions/show.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC;KACxC,WAAW,CAAC,sCAAsC,CAAC;KACnD,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;IACrB,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IACzC,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,C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AC,QAAQ,IAAI,CAAC;YAC/D,IAAI,QAAQ,CAAC,KAAK;gBAAE,EAAE,IAAI,YAAY,QAAQ,CAAC,KAAK,IAAI,CAAC;YACzD,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAE,EAAE,IAAI,WAAW,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACzE,IAAI,QAAQ,CAAC,gBAAgB;gBAAE,EAAE,IAAI,eAAe,QAAQ,CAAC,gBAAgB,IAAI,CAAC;YAClF,IAAI,QAAQ,CAAC,eAAe;gBAAE,EAAE,IAAI,cAAc,QAAQ,CAAC,eAAe,IAAI,CAAC;YAC/E,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,8BAA8B,UAAU,EAAE,CAAC,CAAC;IACxG,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,YAAY,SAqBrB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getPositionStats } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const statsCommand = new Command('stats')
|
|
5
|
+
.description('Show position statistics and performance')
|
|
6
|
+
.action(() => {
|
|
7
|
+
const stats = getPositionStats();
|
|
8
|
+
const totalPnl = stats.realizedPnl + stats.unrealizedPnl;
|
|
9
|
+
output(stats, () => {
|
|
10
|
+
let md = `# Position Stats\n\n`;
|
|
11
|
+
md += `Total: ${stats.totalPositions} (${stats.openPositions} open, ${stats.closedPositions} closed)\n`;
|
|
12
|
+
md += `Open value: $${stats.currentOpenValue.toFixed(2)}\n`;
|
|
13
|
+
md += `Unrealized PnL: $${stats.unrealizedPnl.toFixed(2)}\n`;
|
|
14
|
+
md += `Realized PnL: $${stats.realizedPnl.toFixed(2)}\n`;
|
|
15
|
+
md += `Total PnL: $${totalPnl.toFixed(2)}\n`;
|
|
16
|
+
if (stats.closedPositions > 0) {
|
|
17
|
+
md += `\nWin rate: ${stats.winRate.toFixed(1)}% (${stats.winCount}W/${stats.lossCount}L)\n`;
|
|
18
|
+
md += `Avg win: $${stats.avgWin.toFixed(2)} | Avg loss: $${stats.avgLoss.toFixed(2)}\n`;
|
|
19
|
+
if (stats.bestTrade)
|
|
20
|
+
md += `Best: ${stats.bestTrade.symbol} +$${stats.bestTrade.pnl.toFixed(2)}\n`;
|
|
21
|
+
if (stats.worstTrade)
|
|
22
|
+
md += `Worst: ${stats.worstTrade.symbol} $${stats.worstTrade.pnl.toFixed(2)}\n`;
|
|
23
|
+
}
|
|
24
|
+
return md;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/commands/positions/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,0CAA0C,CAAC;KACvD,MAAM,CAAC,GAAG,EAAE;IACX,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,aAAa,CAAC;IAEzD,MAAM,CAAC,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CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/tag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,UAAU,SAgBnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { addPositionTags, getPosition } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const tagCommand = new Command('tag')
|
|
5
|
+
.argument('<position-id>', 'Position ID')
|
|
6
|
+
.argument('<tags>', 'Comma-separated tags')
|
|
7
|
+
.description('Add tags to a position')
|
|
8
|
+
.action((positionId, tags) => {
|
|
9
|
+
const tagList = tags.split(',').map((t) => t.trim());
|
|
10
|
+
addPositionTags(positionId, tagList);
|
|
11
|
+
const position = getPosition(positionId);
|
|
12
|
+
if (position) {
|
|
13
|
+
output({ positionId, tags: position.tags }, () => `# Tags Updated\n\nPosition: ${positionId}\nTags: ${position.tags?.join(', ')}`);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../../src/commands/positions/tag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC;KACzC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC;KACxC,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;KAC1C,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IACzC,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CACJ,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACnC,GAAG,EAAE,CAAC,+BAA+B,UAAU,WAAW,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CACtF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,8BAA8B,UAAU,EAAE,CAAC,CAAC;IACxG,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/commands/positions/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,aAAa,SAmCtB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { updatePositionPrices } from '../../utils/positions.js';
|
|
3
|
+
import { output } from '../shared.js';
|
|
4
|
+
export const updateCommand = new Command('update')
|
|
5
|
+
.description('Update current prices for all open positions')
|
|
6
|
+
.action(async () => {
|
|
7
|
+
try {
|
|
8
|
+
const results = await updatePositionPrices();
|
|
9
|
+
if (results.length === 0) {
|
|
10
|
+
output({ message: 'No open positions to update', updated: 0 }, () => 'No open positions to update.');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const totalUnrealizedPnl = results.reduce((sum, r) => sum + r.unrealizedPnl, 0);
|
|
14
|
+
output({
|
|
15
|
+
updated: results.length,
|
|
16
|
+
totalUnrealizedPnl,
|
|
17
|
+
positions: results,
|
|
18
|
+
}, () => {
|
|
19
|
+
let md = `# Prices Updated\n\n`;
|
|
20
|
+
md += `Updated ${results.length} position(s)\n\n`;
|
|
21
|
+
for (const r of results) {
|
|
22
|
+
const pnlSign = r.unrealizedPnl >= 0 ? '+' : '';
|
|
23
|
+
md += `- **${r.tokenSymbol}**: $${r.currentPrice.toFixed(4)} (entry: $${r.entryPrice.toFixed(4)}, PnL: ${pnlSign}$${r.unrealizedPnl.toFixed(2)})\n`;
|
|
24
|
+
}
|
|
25
|
+
const emoji = totalUnrealizedPnl >= 0 ? '+' : '';
|
|
26
|
+
md += `\n**Total Unrealized PnL:** ${emoji}$${totalUnrealizedPnl.toFixed(2)}\n`;
|
|
27
|
+
return md;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
output({ error: error.message }, () => `Error: ${error.message}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/commands/positions/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,8CAA8C,CAAC;KAC3D,MAAM,CAAC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,OAAO,EAAE,CAAC;QACZ,CAAC,CACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/commands/positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkBpC,eAAO,MAAM,gBAAgB,SAAkE,CAAC"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { calculateTotalPnL, closePosition, getAllPositions, getOpenPositions, getPosition, getPositionStats, openPosition, updatePositionPrices, updatePositionNotes, addPositionTags, getPositionsByTag, } from '../utils/positions.js';
|
|
3
|
+
import { resolveToken } from '../utils/token-book.js';
|
|
4
|
+
import { output } from './shared.js';
|
|
5
|
+
export const positionsCommand = new Command('positions').description('Track trading positions');
|
|
6
|
+
positionsCommand
|
|
7
|
+
.command('list')
|
|
8
|
+
.description('List all open positions')
|
|
9
|
+
.option('-a, --all', 'Show all positions including closed')
|
|
10
|
+
.action((options) => {
|
|
11
|
+
const pos = options.all ? getAllPositions() : getOpenPositions();
|
|
12
|
+
output(pos, () => {
|
|
13
|
+
if (pos.length === 0) {
|
|
14
|
+
return '# Positions\n\nNo positions found.';
|
|
15
|
+
}
|
|
16
|
+
let md = '# Positions\n\n';
|
|
17
|
+
for (const p of pos) {
|
|
18
|
+
md += `## ${p.tokenSymbol} (${p.type.toUpperCase()})\n`;
|
|
19
|
+
md += `- ID: ${p.id}\n`;
|
|
20
|
+
md += `- Status: ${p.status}\n`;
|
|
21
|
+
md += `- Entry: $${p.entryPrice} x ${p.entryAmount} = $${p.entryValueUsd.toFixed(2)}\n`;
|
|
22
|
+
if (p.exitPrice) {
|
|
23
|
+
md += `- Exit: $${p.exitPrice} x ${p.exitAmount} = $${p.exitValueUsd?.toFixed(2)}\n`;
|
|
24
|
+
}
|
|
25
|
+
if (p.pnl !== undefined) {
|
|
26
|
+
md += `- PnL: $${p.pnl.toFixed(2)} (${p.pnlPercent?.toFixed(2)}%)\n`;
|
|
27
|
+
}
|
|
28
|
+
if (p.notes)
|
|
29
|
+
md += `- Notes: ${p.notes}\n`;
|
|
30
|
+
if (p.tags?.length)
|
|
31
|
+
md += `- Tags: ${p.tags.join(', ')}\n`;
|
|
32
|
+
md += '\n';
|
|
33
|
+
}
|
|
34
|
+
if (options.all) {
|
|
35
|
+
const { realized, count } = calculateTotalPnL();
|
|
36
|
+
md += `---\n\n**Total Realized PnL:** $${realized.toFixed(2)} from ${count} closed positions\n`;
|
|
37
|
+
}
|
|
38
|
+
return md;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
positionsCommand
|
|
42
|
+
.command('open <type> <token> <amount> <price>')
|
|
43
|
+
.description('Open a new position (type: long/short)')
|
|
44
|
+
.option('-t, --target <price>', 'Target price')
|
|
45
|
+
.option('-s, --stop <price>', 'Stop loss price')
|
|
46
|
+
.option('-n, --notes <notes>', 'Position notes')
|
|
47
|
+
.option('--tags <tags>', 'Comma-separated tags (e.g., "swing,momentum")')
|
|
48
|
+
.option('--tx <signature>', 'Entry transaction signature')
|
|
49
|
+
.action((type, tokenOrTicker, amount, price, options) => {
|
|
50
|
+
const token = resolveToken(tokenOrTicker);
|
|
51
|
+
const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : undefined;
|
|
52
|
+
const position = openPosition({
|
|
53
|
+
type: type.toLowerCase(),
|
|
54
|
+
token,
|
|
55
|
+
tokenSymbol: tokenOrTicker.toUpperCase(),
|
|
56
|
+
entryPrice: parseFloat(price),
|
|
57
|
+
entryAmount: parseFloat(amount),
|
|
58
|
+
targetPrice: options.target ? parseFloat(options.target) : undefined,
|
|
59
|
+
stopLoss: options.stop ? parseFloat(options.stop) : undefined,
|
|
60
|
+
notes: options.notes,
|
|
61
|
+
tags,
|
|
62
|
+
entryTxSignature: options.tx,
|
|
63
|
+
});
|
|
64
|
+
output(position, () => {
|
|
65
|
+
let md = `# Position Opened\n\n`;
|
|
66
|
+
md += `**${position.tokenSymbol}** (${position.type.toUpperCase()})\n\n`;
|
|
67
|
+
md += `- ID: ${position.id}\n`;
|
|
68
|
+
md += `- Entry: $${position.entryPrice} x ${position.entryAmount} = $${position.entryValueUsd.toFixed(2)}\n`;
|
|
69
|
+
if (position.targetPrice)
|
|
70
|
+
md += `- Target: $${position.targetPrice}\n`;
|
|
71
|
+
if (position.stopLoss)
|
|
72
|
+
md += `- Stop: $${position.stopLoss}\n`;
|
|
73
|
+
if (position.notes)
|
|
74
|
+
md += `- Notes: ${position.notes}\n`;
|
|
75
|
+
if (position.tags?.length)
|
|
76
|
+
md += `- Tags: ${position.tags.join(', ')}\n`;
|
|
77
|
+
return md;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
positionsCommand
|
|
81
|
+
.command('close <position-id> <exit-price> <exit-amount>')
|
|
82
|
+
.description('Close an open position')
|
|
83
|
+
.option('-n, --notes <notes>', 'Exit notes')
|
|
84
|
+
.option('--tx <signature>', 'Exit transaction signature')
|
|
85
|
+
.action((positionId, exitPrice, exitAmount, options) => {
|
|
86
|
+
const position = closePosition(positionId, parseFloat(exitPrice), parseFloat(exitAmount), {
|
|
87
|
+
exitTxSignature: options.tx,
|
|
88
|
+
notes: options.notes,
|
|
89
|
+
});
|
|
90
|
+
if (position) {
|
|
91
|
+
output(position, () => {
|
|
92
|
+
let md = `# Position Closed\n\n`;
|
|
93
|
+
md += `**${position.tokenSymbol}** (${position.type.toUpperCase()})\n\n`;
|
|
94
|
+
md += `- ID: ${position.id}\n`;
|
|
95
|
+
md += `- Entry: $${position.entryPrice} x ${position.entryAmount} = $${position.entryValueUsd.toFixed(2)}\n`;
|
|
96
|
+
md += `- Exit: $${position.exitPrice} x ${position.exitAmount} = $${position.exitValueUsd?.toFixed(2)}\n`;
|
|
97
|
+
md += `- PnL: $${position.pnl?.toFixed(2)} (${position.pnlPercent?.toFixed(2)}%)\n`;
|
|
98
|
+
return md;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
positionsCommand
|
|
106
|
+
.command('note <position-id> <note>')
|
|
107
|
+
.description('Add a note to a position')
|
|
108
|
+
.option('-a, --append', 'Append to existing notes instead of replacing')
|
|
109
|
+
.action((positionId, note, options) => {
|
|
110
|
+
updatePositionNotes(positionId, note, options.append);
|
|
111
|
+
const position = getPosition(positionId);
|
|
112
|
+
if (position) {
|
|
113
|
+
output({ positionId, notes: position.notes }, () => `# Note Updated\n\nPosition: ${positionId}\nNotes: ${position.notes}`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
positionsCommand
|
|
120
|
+
.command('tag <position-id> <tags>')
|
|
121
|
+
.description('Add tags to a position (comma-separated)')
|
|
122
|
+
.action((positionId, tags) => {
|
|
123
|
+
const tagList = tags.split(',').map((t) => t.trim());
|
|
124
|
+
addPositionTags(positionId, tagList);
|
|
125
|
+
const position = getPosition(positionId);
|
|
126
|
+
if (position) {
|
|
127
|
+
output({ positionId, tags: position.tags }, () => `# Tags Updated\n\nPosition: ${positionId}\nTags: ${position.tags?.join(', ')}`);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
positionsCommand
|
|
134
|
+
.command('show <position-id>')
|
|
135
|
+
.description('Show details for a specific position')
|
|
136
|
+
.action((positionId) => {
|
|
137
|
+
const position = getPosition(positionId);
|
|
138
|
+
if (position) {
|
|
139
|
+
output(position, () => {
|
|
140
|
+
let md = `# Position Details\n\n`;
|
|
141
|
+
md += `**${position.tokenSymbol}** (${position.type.toUpperCase()})\n\n`;
|
|
142
|
+
md += `- ID: ${position.id}\n`;
|
|
143
|
+
md += `- Status: ${position.status}\n`;
|
|
144
|
+
md += `- Entry: $${position.entryPrice} x ${position.entryAmount} = $${position.entryValueUsd.toFixed(2)}\n`;
|
|
145
|
+
md += `- Date: ${position.entryDate}\n`;
|
|
146
|
+
if (position.exitPrice) {
|
|
147
|
+
md += `- Exit: $${position.exitPrice} x ${position.exitAmount} = $${position.exitValueUsd?.toFixed(2)}\n`;
|
|
148
|
+
md += `- Exit Date: ${position.exitDate}\n`;
|
|
149
|
+
}
|
|
150
|
+
if (position.currentPrice) {
|
|
151
|
+
md += `- Current Price: $${position.currentPrice} (updated: ${position.currentPriceUpdatedAt})\n`;
|
|
152
|
+
}
|
|
153
|
+
if (position.pnl !== undefined) {
|
|
154
|
+
md += `- PnL: $${position.pnl.toFixed(2)} (${position.pnlPercent?.toFixed(2)}%)\n`;
|
|
155
|
+
}
|
|
156
|
+
if (position.targetPrice)
|
|
157
|
+
md += `- Target: $${position.targetPrice}\n`;
|
|
158
|
+
if (position.stopLoss)
|
|
159
|
+
md += `- Stop: $${position.stopLoss}\n`;
|
|
160
|
+
if (position.notes)
|
|
161
|
+
md += `- Notes: ${position.notes}\n`;
|
|
162
|
+
if (position.tags?.length)
|
|
163
|
+
md += `- Tags: ${position.tags.join(', ')}\n`;
|
|
164
|
+
if (position.entryTxSignature)
|
|
165
|
+
md += `- Entry TX: ${position.entryTxSignature}\n`;
|
|
166
|
+
if (position.exitTxSignature)
|
|
167
|
+
md += `- Exit TX: ${position.exitTxSignature}\n`;
|
|
168
|
+
return md;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
output({ error: 'Position not found', positionId }, () => `Error: Position not found: ${positionId}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
positionsCommand
|
|
176
|
+
.command('filter <tag>')
|
|
177
|
+
.description('List positions by tag')
|
|
178
|
+
.action((tag) => {
|
|
179
|
+
const pos = getPositionsByTag(tag);
|
|
180
|
+
output(pos, () => {
|
|
181
|
+
if (pos.length === 0) {
|
|
182
|
+
return `# Positions by Tag\n\nNo positions found with tag: ${tag}`;
|
|
183
|
+
}
|
|
184
|
+
let md = `# Positions with tag "${tag}"\n\n`;
|
|
185
|
+
for (const p of pos) {
|
|
186
|
+
md += `- **${p.tokenSymbol}** (${p.type}): $${p.entryValueUsd.toFixed(2)} - ${p.status}\n`;
|
|
187
|
+
}
|
|
188
|
+
return md;
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
positionsCommand
|
|
192
|
+
.command('stats')
|
|
193
|
+
.description('Show position statistics and performance')
|
|
194
|
+
.action(() => {
|
|
195
|
+
const stats = getPositionStats();
|
|
196
|
+
const totalPnl = stats.realizedPnl + stats.unrealizedPnl;
|
|
197
|
+
output(stats, () => {
|
|
198
|
+
let md = `# Position Stats\n\n`;
|
|
199
|
+
md += `Total: ${stats.totalPositions} (${stats.openPositions} open, ${stats.closedPositions} closed)\n`;
|
|
200
|
+
md += `Open value: $${stats.currentOpenValue.toFixed(2)}\n`;
|
|
201
|
+
md += `Unrealized PnL: $${stats.unrealizedPnl.toFixed(2)}\n`;
|
|
202
|
+
md += `Realized PnL: $${stats.realizedPnl.toFixed(2)}\n`;
|
|
203
|
+
md += `Total PnL: $${totalPnl.toFixed(2)}\n`;
|
|
204
|
+
if (stats.closedPositions > 0) {
|
|
205
|
+
md += `\nWin rate: ${stats.winRate.toFixed(1)}% (${stats.winCount}W/${stats.lossCount}L)\n`;
|
|
206
|
+
md += `Avg win: $${stats.avgWin.toFixed(2)} | Avg loss: $${stats.avgLoss.toFixed(2)}\n`;
|
|
207
|
+
if (stats.bestTrade)
|
|
208
|
+
md += `Best: ${stats.bestTrade.symbol} +$${stats.bestTrade.pnl.toFixed(2)}\n`;
|
|
209
|
+
if (stats.worstTrade)
|
|
210
|
+
md += `Worst: ${stats.worstTrade.symbol} $${stats.worstTrade.pnl.toFixed(2)}\n`;
|
|
211
|
+
}
|
|
212
|
+
return md;
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
positionsCommand
|
|
216
|
+
.command('update')
|
|
217
|
+
.description('Update current prices for all open positions')
|
|
218
|
+
.action(async () => {
|
|
219
|
+
try {
|
|
220
|
+
const results = await updatePositionPrices();
|
|
221
|
+
if (results.length === 0) {
|
|
222
|
+
output({ message: 'No open positions to update', updated: 0 }, () => 'No open positions to update.');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const totalUnrealizedPnl = results.reduce((sum, r) => sum + r.unrealizedPnl, 0);
|
|
226
|
+
output({
|
|
227
|
+
updated: results.length,
|
|
228
|
+
totalUnrealizedPnl,
|
|
229
|
+
positions: results,
|
|
230
|
+
}, () => {
|
|
231
|
+
let md = `# Prices Updated\n\n`;
|
|
232
|
+
md += `Updated ${results.length} position(s)\n\n`;
|
|
233
|
+
for (const r of results) {
|
|
234
|
+
const pnlSign = r.unrealizedPnl >= 0 ? '+' : '';
|
|
235
|
+
md += `- **${r.tokenSymbol}**: $${r.currentPrice.toFixed(4)} (entry: $${r.entryPrice.toFixed(4)}, PnL: ${pnlSign}$${r.unrealizedPnl.toFixed(2)})\n`;
|
|
236
|
+
}
|
|
237
|
+
const emoji = totalUnrealizedPnl >= 0 ? '+' : '';
|
|
238
|
+
md += `\n**Total Unrealized PnL:** ${emoji}$${totalUnrealizedPnl.toFixed(2)}\n`;
|
|
239
|
+
return md;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
output({ error: error.message }, () => `Error: ${error.message}`);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
//# sourceMappingURL=positions.js.map
|