@gbozee/ultimate 0.0.2-5 → 0.0.2-9
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 +53 -0
- package/dist/index.js +135 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,10 @@ export interface BaseExchange {
|
|
|
117
117
|
price_places?: string;
|
|
118
118
|
decimal_places?: string;
|
|
119
119
|
}): Promise<any>;
|
|
120
|
+
setLeverage(payload: {
|
|
121
|
+
symbol: string;
|
|
122
|
+
leverage: number;
|
|
123
|
+
}): Promise<any>;
|
|
120
124
|
}
|
|
121
125
|
export interface BaseSystemFields {
|
|
122
126
|
id: string;
|
|
@@ -221,6 +225,16 @@ export type ExchangeType = {
|
|
|
221
225
|
export declare class AppDatabase {
|
|
222
226
|
private pb;
|
|
223
227
|
constructor(pb: PocketBase);
|
|
228
|
+
createOrUpdateLiveExchangeInstance(payload: {
|
|
229
|
+
account: ExchangeType;
|
|
230
|
+
symbol: string;
|
|
231
|
+
data?: any;
|
|
232
|
+
}): Promise<import("pocketbase").RecordModel>;
|
|
233
|
+
getLiveExchangeInstance(payload: {
|
|
234
|
+
account: ExchangeType;
|
|
235
|
+
symbol: string;
|
|
236
|
+
data?: any;
|
|
237
|
+
}): Promise<import("pocketbase").RecordModel>;
|
|
224
238
|
getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
|
|
225
239
|
get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
|
|
226
240
|
expand?: {
|
|
@@ -324,6 +338,21 @@ export declare class AppDatabase {
|
|
|
324
338
|
updated_bullish: BullishMarket[];
|
|
325
339
|
moved_to_winding: WindingDownMarket[];
|
|
326
340
|
}>;
|
|
341
|
+
updateSymbolConfigs(payload?: {
|
|
342
|
+
configs: Array<{
|
|
343
|
+
symbol: string;
|
|
344
|
+
support: number;
|
|
345
|
+
leverage: number;
|
|
346
|
+
min_size: number;
|
|
347
|
+
resistance: number;
|
|
348
|
+
price_places: string;
|
|
349
|
+
decimal_places: string;
|
|
350
|
+
}>;
|
|
351
|
+
}): Promise<{
|
|
352
|
+
updated: number;
|
|
353
|
+
created: number;
|
|
354
|
+
} | SymbolConfig[]>;
|
|
355
|
+
unwindSymbolFromDB(symbol: string): Promise<void>;
|
|
327
356
|
}
|
|
328
357
|
export interface CodeNode {
|
|
329
358
|
minimum_pnl: number;
|
|
@@ -369,6 +398,15 @@ declare class ExchangeAccount$1 {
|
|
|
369
398
|
exchange: BaseExchange;
|
|
370
399
|
app_db: AppDatabase;
|
|
371
400
|
});
|
|
401
|
+
/**
|
|
402
|
+
*In order to avoid rate limiting issues, we cache the live exchange
|
|
403
|
+
details for each symbol for an account in the database with an option
|
|
404
|
+
to refresh.
|
|
405
|
+
*/
|
|
406
|
+
getLiveExchangeInstance(payload: {
|
|
407
|
+
symbol: string;
|
|
408
|
+
refresh?: boolean;
|
|
409
|
+
}): Promise<import("pocketbase").RecordModel>;
|
|
372
410
|
getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
|
|
373
411
|
liquidation: {
|
|
374
412
|
long: number;
|
|
@@ -383,6 +421,7 @@ declare class ExchangeAccount$1 {
|
|
|
383
421
|
kind?: "long" | "short";
|
|
384
422
|
update?: boolean;
|
|
385
423
|
as_view?: boolean;
|
|
424
|
+
leverage?: number;
|
|
386
425
|
}): Promise<(PositionsView & {
|
|
387
426
|
expand?: {
|
|
388
427
|
config: ScheduledTrade;
|
|
@@ -632,6 +671,20 @@ declare class App {
|
|
|
632
671
|
moved_to_winding: WindingDownMarket[];
|
|
633
672
|
}>;
|
|
634
673
|
getWindingDownMarkets(): Promise<WindingDownMarket[]>;
|
|
674
|
+
updateSymbolConfigs(payload: {
|
|
675
|
+
configs: {
|
|
676
|
+
symbol: string;
|
|
677
|
+
support: number;
|
|
678
|
+
leverage: number;
|
|
679
|
+
min_size: number;
|
|
680
|
+
resistance: number;
|
|
681
|
+
price_places: string;
|
|
682
|
+
decimal_places: string;
|
|
683
|
+
}[];
|
|
684
|
+
}): Promise<{
|
|
685
|
+
updated: number;
|
|
686
|
+
created: number;
|
|
687
|
+
} | SymbolConfig[]>;
|
|
635
688
|
}
|
|
636
689
|
export declare function initApp(payload: {
|
|
637
690
|
db: {
|
package/dist/index.js
CHANGED
|
@@ -31646,6 +31646,31 @@ class AppDatabase {
|
|
|
31646
31646
|
constructor(pb) {
|
|
31647
31647
|
this.pb = pb;
|
|
31648
31648
|
}
|
|
31649
|
+
async createOrUpdateLiveExchangeInstance(payload) {
|
|
31650
|
+
const result = await this.getLiveExchangeInstance(payload);
|
|
31651
|
+
if (result) {
|
|
31652
|
+
return await this.pb.collection("live_exchange_details").update(result.id, {
|
|
31653
|
+
data: payload.data
|
|
31654
|
+
});
|
|
31655
|
+
} else {
|
|
31656
|
+
const exchange_account = await this.get_exchange_db_instance(payload.account);
|
|
31657
|
+
return await this.pb.collection("live_exchange_details").create({
|
|
31658
|
+
symbol: payload.symbol,
|
|
31659
|
+
account: exchange_account.id,
|
|
31660
|
+
data: payload.data
|
|
31661
|
+
});
|
|
31662
|
+
}
|
|
31663
|
+
}
|
|
31664
|
+
async getLiveExchangeInstance(payload) {
|
|
31665
|
+
const result = await this.pb.collection("live_exchange_details").getFullList({
|
|
31666
|
+
filter: `account.owner:lower="${payload.account.owner.toLowerCase()}" && account.exchange:lower="${payload.account.exchange.toLowerCase()}" && symbol:lower="${payload.symbol.toLowerCase()}"`,
|
|
31667
|
+
expand: "account"
|
|
31668
|
+
});
|
|
31669
|
+
if (result.length > 0) {
|
|
31670
|
+
return result[0];
|
|
31671
|
+
}
|
|
31672
|
+
return null;
|
|
31673
|
+
}
|
|
31649
31674
|
async getProxyForAccount(account) {
|
|
31650
31675
|
const result = await this.get_exchange_db_instance(account);
|
|
31651
31676
|
if (result?.expand?.proxy) {
|
|
@@ -32054,6 +32079,80 @@ class AppDatabase {
|
|
|
32054
32079
|
const updated_bullish = await this.pb.collection("bullish_markets").getFullList();
|
|
32055
32080
|
return { updated_bullish, moved_to_winding };
|
|
32056
32081
|
}
|
|
32082
|
+
async updateSymbolConfigs(payload) {
|
|
32083
|
+
if (!payload || !payload.configs) {
|
|
32084
|
+
console.log("No payload provided. Fetching all symbol configs...");
|
|
32085
|
+
try {
|
|
32086
|
+
const allConfigs = await this.pb.collection("symbol_configs").getFullList();
|
|
32087
|
+
console.log(`Found ${allConfigs.length} symbol configs.`);
|
|
32088
|
+
return allConfigs;
|
|
32089
|
+
} catch (error) {
|
|
32090
|
+
console.error("Error fetching all symbol configs:", error);
|
|
32091
|
+
throw error;
|
|
32092
|
+
}
|
|
32093
|
+
}
|
|
32094
|
+
console.log(`Processing ${payload.configs.length} symbol config updates/creates...`);
|
|
32095
|
+
let existingConfigsMap = new Map;
|
|
32096
|
+
try {
|
|
32097
|
+
const existingConfigsList = await this.pb.collection("symbol_configs").getFullList();
|
|
32098
|
+
existingConfigsMap = new Map(existingConfigsList.map((c) => [c.symbol.toLowerCase(), c]));
|
|
32099
|
+
console.log(`Found ${existingConfigsMap.size} existing symbol configs in DB.`);
|
|
32100
|
+
} catch (error) {
|
|
32101
|
+
console.error("Error fetching existing symbol configs:", error);
|
|
32102
|
+
}
|
|
32103
|
+
let updatedCount = 0;
|
|
32104
|
+
let createdCount = 0;
|
|
32105
|
+
for (const config of payload.configs) {
|
|
32106
|
+
const lowerCaseSymbol = config.symbol.toLowerCase();
|
|
32107
|
+
const existingConfig = existingConfigsMap.get(lowerCaseSymbol);
|
|
32108
|
+
const dataToUpsert = {
|
|
32109
|
+
symbol: config.symbol,
|
|
32110
|
+
support: config.support,
|
|
32111
|
+
resistance: config.resistance,
|
|
32112
|
+
leverage: config.leverage,
|
|
32113
|
+
min_size: config.min_size,
|
|
32114
|
+
price_places: config.price_places,
|
|
32115
|
+
decimal_places: config.decimal_places
|
|
32116
|
+
};
|
|
32117
|
+
if (existingConfig) {
|
|
32118
|
+
try {
|
|
32119
|
+
if (Object.keys(dataToUpsert).some((key) => dataToUpsert[key] !== existingConfig[key])) {
|
|
32120
|
+
console.log(`Updating symbol config for: ${config.symbol}`);
|
|
32121
|
+
await this.pb.collection("symbol_configs").update(existingConfig.id, dataToUpsert);
|
|
32122
|
+
updatedCount++;
|
|
32123
|
+
} else {
|
|
32124
|
+
console.log(`No changes detected for symbol config: ${config.symbol}. Skipping update.`);
|
|
32125
|
+
}
|
|
32126
|
+
} catch (updateError) {
|
|
32127
|
+
console.error(`Error updating symbol config for ${config.symbol}:`, updateError);
|
|
32128
|
+
}
|
|
32129
|
+
} else {
|
|
32130
|
+
try {
|
|
32131
|
+
console.log(`Creating new symbol config for: ${config.symbol}`);
|
|
32132
|
+
await this.pb.collection("symbol_configs").create(dataToUpsert);
|
|
32133
|
+
createdCount++;
|
|
32134
|
+
} catch (createError) {
|
|
32135
|
+
console.error(`Error creating symbol config for ${config.symbol}:`, createError);
|
|
32136
|
+
}
|
|
32137
|
+
}
|
|
32138
|
+
}
|
|
32139
|
+
console.log(`Finished processing symbol configs. Updated: ${updatedCount}, Created: ${createdCount}`);
|
|
32140
|
+
return { updated: updatedCount, created: createdCount };
|
|
32141
|
+
}
|
|
32142
|
+
async unwindSymbolFromDB(symbol) {
|
|
32143
|
+
const symbol_configs = await this.pb.collection("symbol_configs").getFullList({
|
|
32144
|
+
filter: `symbol:lower="${symbol.toLowerCase()}"`
|
|
32145
|
+
});
|
|
32146
|
+
if (symbol_configs.length > 0) {
|
|
32147
|
+
await this.pb.collection("symbol_configs").delete(symbol_configs[0].id);
|
|
32148
|
+
}
|
|
32149
|
+
const found_unwinding_market = await this.pb.collection("unwinding_markets").getFullList({
|
|
32150
|
+
filter: `symbol:lower="${symbol.toLowerCase()}"`
|
|
32151
|
+
});
|
|
32152
|
+
if (found_unwinding_market.length > 0) {
|
|
32153
|
+
await this.pb.collection("unwinding_markets").delete(found_unwinding_market[0].id);
|
|
32154
|
+
}
|
|
32155
|
+
}
|
|
32057
32156
|
}
|
|
32058
32157
|
|
|
32059
32158
|
// src/exchanges/binance.ts
|
|
@@ -33624,6 +33723,9 @@ class BinanceExchange {
|
|
|
33624
33723
|
decimal_places: payload.decimal_places
|
|
33625
33724
|
});
|
|
33626
33725
|
}
|
|
33726
|
+
async setLeverage(payload) {
|
|
33727
|
+
return await this.client.setLeverage(payload);
|
|
33728
|
+
}
|
|
33627
33729
|
}
|
|
33628
33730
|
|
|
33629
33731
|
// src/exchanges/bybit.ts
|
|
@@ -34228,6 +34330,14 @@ class BybitExchange {
|
|
|
34228
34330
|
decimal_places: payload.decimal_places
|
|
34229
34331
|
});
|
|
34230
34332
|
}
|
|
34333
|
+
async setLeverage(payload) {
|
|
34334
|
+
return await this.client.setLeverage({
|
|
34335
|
+
category: "linear",
|
|
34336
|
+
symbol: payload.symbol,
|
|
34337
|
+
buyLeverage: payload.leverage.toString(),
|
|
34338
|
+
sellLeverage: payload.leverage.toString()
|
|
34339
|
+
});
|
|
34340
|
+
}
|
|
34231
34341
|
}
|
|
34232
34342
|
|
|
34233
34343
|
// src/helpers/accounts.ts
|
|
@@ -34887,9 +34997,27 @@ class ExchangeAccount {
|
|
|
34887
34997
|
this.exchange = options.exchange;
|
|
34888
34998
|
this.app_db = options.app_db;
|
|
34889
34999
|
}
|
|
35000
|
+
async getLiveExchangeInstance(payload) {
|
|
35001
|
+
const result = await this.app_db.getLiveExchangeInstance({
|
|
35002
|
+
account: this.instance,
|
|
35003
|
+
symbol: payload.symbol
|
|
35004
|
+
});
|
|
35005
|
+
if (payload.refresh || !result) {
|
|
35006
|
+
const data = await this.exchange.getExchangeAccountInfo(this.instance, payload.symbol);
|
|
35007
|
+
return await this.app_db.createOrUpdateLiveExchangeInstance({
|
|
35008
|
+
account: this.instance,
|
|
35009
|
+
symbol: payload.symbol,
|
|
35010
|
+
data
|
|
35011
|
+
});
|
|
35012
|
+
}
|
|
35013
|
+
return result;
|
|
35014
|
+
}
|
|
34890
35015
|
async getActiveAccount(symbol, full) {
|
|
34891
35016
|
const symbol_config = await this.app_db.getSymbolConfigFromDB(symbol);
|
|
34892
|
-
const
|
|
35017
|
+
const live_exchange_instance = await this.getLiveExchangeInstance({
|
|
35018
|
+
symbol
|
|
35019
|
+
});
|
|
35020
|
+
const raw_active_account = live_exchange_instance.data;
|
|
34893
35021
|
const _all = get_active_accounts({
|
|
34894
35022
|
active_account: raw_active_account,
|
|
34895
35023
|
symbol_config
|
|
@@ -34913,6 +35041,9 @@ class ExchangeAccount {
|
|
|
34913
35041
|
return db_positions2;
|
|
34914
35042
|
}
|
|
34915
35043
|
const active_account = await this.getActiveAccount(symbol);
|
|
35044
|
+
if (options.leverage) {
|
|
35045
|
+
await this.exchange.setLeverage({ symbol, leverage: options.leverage });
|
|
35046
|
+
}
|
|
34916
35047
|
const db_positions = await this.app_db.createOrUpdatePositions(this.instance, {
|
|
34917
35048
|
symbol,
|
|
34918
35049
|
long_position: active_account.position.long,
|
|
@@ -35566,6 +35697,9 @@ class App {
|
|
|
35566
35697
|
async getWindingDownMarkets() {
|
|
35567
35698
|
return await this.app_db.getWindingDownMarkets();
|
|
35568
35699
|
}
|
|
35700
|
+
async updateSymbolConfigs(payload) {
|
|
35701
|
+
return await this.app_db.updateSymbolConfigs(payload);
|
|
35702
|
+
}
|
|
35569
35703
|
}
|
|
35570
35704
|
async function initApp(payload) {
|
|
35571
35705
|
const pb = await initPocketBaseClient(payload.db);
|