@gbozee/ultimate 0.0.2-7 → 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 +19 -0
- package/dist/index.js +44 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -225,6 +225,16 @@ export type ExchangeType = {
|
|
|
225
225
|
export declare class AppDatabase {
|
|
226
226
|
private pb;
|
|
227
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>;
|
|
228
238
|
getProxyForAccount(account: ExchangeType): Promise<HttpsProxyAgent<`http://${string}`> | SocksProxyAgent>;
|
|
229
239
|
get_exchange_db_instance(account: ExchangeType): Promise<ExchangeAccount & {
|
|
230
240
|
expand?: {
|
|
@@ -388,6 +398,15 @@ declare class ExchangeAccount$1 {
|
|
|
388
398
|
exchange: BaseExchange;
|
|
389
399
|
app_db: AppDatabase;
|
|
390
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>;
|
|
391
410
|
getActiveAccount(symbol: string, full?: boolean): Promise<Account | {
|
|
392
411
|
liquidation: {
|
|
393
412
|
long: number;
|
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) {
|
|
@@ -34972,9 +34997,27 @@ class ExchangeAccount {
|
|
|
34972
34997
|
this.exchange = options.exchange;
|
|
34973
34998
|
this.app_db = options.app_db;
|
|
34974
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
|
+
}
|
|
34975
35015
|
async getActiveAccount(symbol, full) {
|
|
34976
35016
|
const symbol_config = await this.app_db.getSymbolConfigFromDB(symbol);
|
|
34977
|
-
const
|
|
35017
|
+
const live_exchange_instance = await this.getLiveExchangeInstance({
|
|
35018
|
+
symbol
|
|
35019
|
+
});
|
|
35020
|
+
const raw_active_account = live_exchange_instance.data;
|
|
34978
35021
|
const _all = get_active_accounts({
|
|
34979
35022
|
active_account: raw_active_account,
|
|
34980
35023
|
symbol_config
|