@gbozee/ultimate 0.0.2-3 → 0.0.2-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/index.d.ts +6 -6
- package/dist/index.js +65 -25
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -246,16 +246,16 @@ export declare class AppDatabase {
|
|
|
246
246
|
config: ScheduledTrade;
|
|
247
247
|
};
|
|
248
248
|
})[]>;
|
|
249
|
-
update_db_position(position: any, payload: any): Promise<RecordModel>;
|
|
249
|
+
update_db_position(position: any, payload: any): Promise<import("pocketbase").RecordModel>;
|
|
250
250
|
getSymbolConfigFromDB(symbol: string): Promise<SymbolConfig>;
|
|
251
251
|
getRunningInstanceFromDB(account: ExchangeType, symbol: string, options?: {
|
|
252
252
|
delay?: number;
|
|
253
253
|
}): Promise<TradeBlockTracking>;
|
|
254
|
-
updateRunningInstance(id: string, running: boolean): Promise<RecordModel>;
|
|
254
|
+
updateRunningInstance(id: string, running: boolean): Promise<import("pocketbase").RecordModel>;
|
|
255
255
|
getOrders(account: ExchangeType, options: {
|
|
256
256
|
symbol: string;
|
|
257
257
|
kind: "long" | "short";
|
|
258
|
-
}): Promise<RecordModel[]>;
|
|
258
|
+
}): Promise<import("pocketbase").RecordModel[]>;
|
|
259
259
|
deleteAndRecreateOrders(account: ExchangeType, options: {
|
|
260
260
|
symbol: string;
|
|
261
261
|
kind: "long" | "short";
|
|
@@ -268,7 +268,7 @@ export declare class AppDatabase {
|
|
|
268
268
|
stop: number;
|
|
269
269
|
order_id: string;
|
|
270
270
|
triggerPrice?: number;
|
|
271
|
-
}>): Promise<RecordModel[]>;
|
|
271
|
+
}>): Promise<import("pocketbase").RecordModel[]>;
|
|
272
272
|
cancelOrders(payload: {
|
|
273
273
|
cancelExchangeOrders: (payload: {
|
|
274
274
|
symbol: string;
|
|
@@ -307,12 +307,12 @@ export declare class AppDatabase {
|
|
|
307
307
|
symbol: string;
|
|
308
308
|
kind: "long" | "short";
|
|
309
309
|
account: ExchangeType;
|
|
310
|
-
}): Promise<RecordModel>;
|
|
310
|
+
}): Promise<import("pocketbase").RecordModel>;
|
|
311
311
|
getPositionStrategy(account: ExchangeType): Promise<{
|
|
312
312
|
strategy_instance: Strategy;
|
|
313
313
|
focus_account: ExchangeAccount;
|
|
314
314
|
}>;
|
|
315
|
-
createOrUpdateWindingDownMarket(symbol: string): Promise<RecordModel>;
|
|
315
|
+
createOrUpdateWindingDownMarket(symbol: string): Promise<import("pocketbase").RecordModel>;
|
|
316
316
|
getWindingDownMarkets(): Promise<WindingDownMarket[]>;
|
|
317
317
|
getBullishMarkets(options?: {
|
|
318
318
|
new_markets: Array<{
|
package/dist/index.js
CHANGED
|
@@ -31921,9 +31921,11 @@ class AppDatabase {
|
|
|
31921
31921
|
return null;
|
|
31922
31922
|
}
|
|
31923
31923
|
async createOrUpdateWindingDownMarket(symbol) {
|
|
31924
|
-
const existing_winding_down_market = await this.pb.collection("winding_down_markets").
|
|
31925
|
-
|
|
31926
|
-
|
|
31924
|
+
const existing_winding_down_market = await this.pb.collection("winding_down_markets").getFullList({
|
|
31925
|
+
filter: `symbol:lower="${symbol.toLowerCase()}"`
|
|
31926
|
+
});
|
|
31927
|
+
if (existing_winding_down_market.length > 0) {
|
|
31928
|
+
return existing_winding_down_market[0];
|
|
31927
31929
|
}
|
|
31928
31930
|
return await this.pb.collection("winding_down_markets").create({ symbol });
|
|
31929
31931
|
}
|
|
@@ -31951,37 +31953,62 @@ class AppDatabase {
|
|
|
31951
31953
|
const currentBullishSymbols = new Set(currentBullish.map((m) => m.symbol));
|
|
31952
31954
|
const moved_to_winding = [];
|
|
31953
31955
|
const recordsToDeleteFromBullish = [];
|
|
31954
|
-
|
|
31956
|
+
let windDownCreatedCount = 0;
|
|
31957
|
+
let currentWindingDown = [];
|
|
31958
|
+
let currentWindingDownSymbols = new Set;
|
|
31959
|
+
try {
|
|
31960
|
+
currentWindingDown = await this.getWindingDownMarkets();
|
|
31961
|
+
currentWindingDownSymbols = new Set(currentWindingDown.map((m) => m.symbol));
|
|
31962
|
+
console.log(`Found ${currentWindingDown.length} existing winding down markets.`);
|
|
31963
|
+
} catch (error) {
|
|
31964
|
+
console.error("Error fetching current winding down markets:", error);
|
|
31965
|
+
}
|
|
31966
|
+
console.log("Processing markets to potentially move to winding down...");
|
|
31955
31967
|
for (const market of currentBullish) {
|
|
31956
31968
|
if (!newMarketSymbols.has(market.symbol)) {
|
|
31957
|
-
console.log(`
|
|
31969
|
+
console.log(`Processing ${market.symbol} for winding down.`);
|
|
31958
31970
|
recordsToDeleteFromBullish.push(market.id);
|
|
31959
|
-
|
|
31971
|
+
try {
|
|
31972
|
+
const windingDownRecord = await this.createOrUpdateWindingDownMarket(market.symbol);
|
|
31973
|
+
if (windingDownRecord) {
|
|
31974
|
+
moved_to_winding.push(windingDownRecord);
|
|
31975
|
+
windDownCreatedCount++;
|
|
31976
|
+
}
|
|
31977
|
+
} catch (windDownError) {
|
|
31978
|
+
console.error(`Error creating/updating winding down market for ${market.symbol} sequentially:`, windDownError);
|
|
31979
|
+
}
|
|
31960
31980
|
}
|
|
31961
31981
|
}
|
|
31962
|
-
|
|
31963
|
-
|
|
31964
|
-
|
|
31965
|
-
|
|
31966
|
-
|
|
31967
|
-
|
|
31968
|
-
|
|
31969
|
-
|
|
31970
|
-
}
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
} catch (error) {
|
|
31974
|
-
console.error("Error moving markets to winding down:", error);
|
|
31982
|
+
console.log(`Finished processing potential winding down markets. ${windDownCreatedCount} processed.`);
|
|
31983
|
+
let deletedCount = 0;
|
|
31984
|
+
if (recordsToDeleteFromBullish.length > 0) {
|
|
31985
|
+
console.log(`Attempting to delete ${recordsToDeleteFromBullish.length} records sequentially from bullish_markets.`);
|
|
31986
|
+
for (const id of recordsToDeleteFromBullish) {
|
|
31987
|
+
try {
|
|
31988
|
+
await this.pb.collection("bullish_markets").delete(id);
|
|
31989
|
+
deletedCount++;
|
|
31990
|
+
} catch (deleteError) {
|
|
31991
|
+
console.error(`Error deleting bullish market record ${id} sequentially:`, deleteError);
|
|
31992
|
+
}
|
|
31975
31993
|
}
|
|
31994
|
+
console.log(`Finished sequential deletion. Successfully deleted ${deletedCount} of ${recordsToDeleteFromBullish.length} records.`);
|
|
31976
31995
|
}
|
|
31977
|
-
const totalPercent = new_markets.reduce((sum, market) => sum + (market.percent || 0), 0);
|
|
31978
31996
|
let updatedCount = 0;
|
|
31979
|
-
|
|
31980
|
-
|
|
31997
|
+
let createdMarkets = [];
|
|
31998
|
+
const recordsToDeleteFromWindingDown = [];
|
|
31999
|
+
if (totalRisk <= 0) {
|
|
31981
32000
|
console.warn("Total percent movement is zero or negative. Cannot allocate risk.");
|
|
31982
32001
|
} else {
|
|
31983
32002
|
for (const newMarket of new_markets) {
|
|
31984
|
-
const calculatedRisk = newMarket.percent /
|
|
32003
|
+
const calculatedRisk = newMarket.percent / totalRisk * totalRisk;
|
|
32004
|
+
if (currentWindingDownSymbols.has(newMarket.symbol)) {
|
|
32005
|
+
console.log(`Marking ${newMarket.symbol} for removal from winding down markets as it is now bullish.`);
|
|
32006
|
+
const windingDownRecord = currentWindingDown.find((w) => w.symbol === newMarket.symbol);
|
|
32007
|
+
if (windingDownRecord) {
|
|
32008
|
+
recordsToDeleteFromWindingDown.push(windingDownRecord.id);
|
|
32009
|
+
currentWindingDownSymbols.delete(newMarket.symbol);
|
|
32010
|
+
}
|
|
32011
|
+
}
|
|
31985
32012
|
const existingMarket = currentBullish.find((m) => m.symbol === newMarket.symbol);
|
|
31986
32013
|
if (existingMarket && !recordsToDeleteFromBullish.includes(existingMarket.id)) {
|
|
31987
32014
|
if (existingMarket.risk !== calculatedRisk) {
|
|
@@ -32009,8 +32036,21 @@ class AppDatabase {
|
|
|
32009
32036
|
}
|
|
32010
32037
|
}
|
|
32011
32038
|
}
|
|
32012
|
-
|
|
32013
|
-
|
|
32039
|
+
let windingDownDeletedCount = 0;
|
|
32040
|
+
if (recordsToDeleteFromWindingDown.length > 0) {
|
|
32041
|
+
console.log(`Attempting to delete ${recordsToDeleteFromWindingDown.length} records sequentially from winding_down_markets.`);
|
|
32042
|
+
for (const id of recordsToDeleteFromWindingDown) {
|
|
32043
|
+
try {
|
|
32044
|
+
await this.pb.collection("winding_down_markets").delete(id);
|
|
32045
|
+
windingDownDeletedCount++;
|
|
32046
|
+
} catch (deleteError) {
|
|
32047
|
+
console.error(`Error deleting winding down market record ${id} sequentially:`, deleteError);
|
|
32048
|
+
}
|
|
32049
|
+
}
|
|
32050
|
+
console.log(`Finished sequential deletion from winding down. Successfully deleted ${windingDownDeletedCount} of ${recordsToDeleteFromWindingDown.length} records.`);
|
|
32051
|
+
}
|
|
32052
|
+
console.log(`Successfully updated ${updatedCount} bullish markets sequentially.`);
|
|
32053
|
+
console.log(`Successfully created ${createdMarkets.length} bullish markets sequentially.`);
|
|
32014
32054
|
const updated_bullish = await this.pb.collection("bullish_markets").getFullList();
|
|
32015
32055
|
return { updated_bullish, moved_to_winding };
|
|
32016
32056
|
}
|