mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 01:08:07 +00:00
refactor: rename Aster-prefixed universal types to clean names
- AsterOrder → Order - AsterAccountSnapshot → AccountSnapshot - AsterAccountPosition → AccountPosition - AsterAccountAsset → AccountAsset - AsterDepthLevel → DepthLevel - AsterDepth → Depth - AsterTicker → Ticker - AsterKline → Kline These types are the platform-agnostic contract used by all 8 exchanges, not Aster-specific. Renamed across 63 files.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AsterAccountSnapshot } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot } from "../src/exchanges/types";
|
||||
import { validateAccountSnapshotForSymbol } from "../src/utils/strategy";
|
||||
|
||||
function baseSnapshot(positions: AsterAccountSnapshot["positions"]): AsterAccountSnapshot {
|
||||
function baseSnapshot(positions: AccountSnapshot["positions"]): AccountSnapshot {
|
||||
return {
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type {
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
} from "../src/exchanges/types";
|
||||
import { BasisArbEngine } from "../src/strategy/basis-arb-engine";
|
||||
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "aster";
|
||||
private depthHandler: ((depth: AsterDepth) => void) | null = null;
|
||||
private depthHandler: ((depth: Depth) => void) | null = null;
|
||||
|
||||
supportsTrailingStops(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {
|
||||
// not required for this test
|
||||
}
|
||||
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {
|
||||
// not required for this test
|
||||
}
|
||||
|
||||
watchDepth(_symbol: string, cb: (depth: AsterDepth) => void): void {
|
||||
watchDepth(_symbol: string, cb: (depth: Depth) => void): void {
|
||||
this.depthHandler = cb;
|
||||
}
|
||||
|
||||
emitDepth(depth: AsterDepth): void {
|
||||
emitDepth(depth: Depth): void {
|
||||
this.depthHandler?.(depth);
|
||||
}
|
||||
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {
|
||||
// not required for this test
|
||||
}
|
||||
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {
|
||||
// not required for this test
|
||||
}
|
||||
|
||||
createOrder(): Promise<AsterOrder> {
|
||||
createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
const ORIGINAL_FETCH = globalThis.fetch;
|
||||
@@ -12,13 +12,13 @@ class StubAdapter implements ExchangeAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class StubAdapter implements ExchangeAdapter {
|
||||
async cancelOrders(): Promise<void> {}
|
||||
async cancelAllOrders(): Promise<void> {}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return {
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
|
||||
@@ -3,11 +3,11 @@ import { executeCliCommand } from "../src/cli/command-executor";
|
||||
import type { ParsedCliCommand } from "../src/cli/command-types";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type {
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
CreateOrderParams,
|
||||
} from "../src/exchanges/types";
|
||||
|
||||
@@ -22,7 +22,7 @@ class FakeAdapter implements ExchangeAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
watchAccount(cb: (snapshot: AsterAccountSnapshot) => void): void {
|
||||
watchAccount(cb: (snapshot: AccountSnapshot) => void): void {
|
||||
cb({
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
@@ -35,11 +35,11 @@ class FakeAdapter implements ExchangeAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
watchOrders(cb: (orders: AsterOrder[]) => void): void {
|
||||
watchOrders(cb: (orders: Order[]) => void): void {
|
||||
cb([]);
|
||||
}
|
||||
|
||||
watchDepth(_symbol: string, cb: (depth: AsterDepth) => void): void {
|
||||
watchDepth(_symbol: string, cb: (depth: Depth) => void): void {
|
||||
cb({
|
||||
lastUpdateId: 1,
|
||||
bids: [["100", "1"]],
|
||||
@@ -47,7 +47,7 @@ class FakeAdapter implements ExchangeAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
watchTicker(symbol: string, cb: (ticker: AsterTicker) => void): void {
|
||||
watchTicker(symbol: string, cb: (ticker: Ticker) => void): void {
|
||||
cb({
|
||||
symbol,
|
||||
lastPrice: "100",
|
||||
@@ -57,10 +57,10 @@ class FakeAdapter implements ExchangeAdapter {
|
||||
volume: "10",
|
||||
quoteVolume: "1000",
|
||||
eventTime: Date.now(),
|
||||
} as AsterTicker);
|
||||
} as Ticker);
|
||||
}
|
||||
|
||||
watchKlines(_symbol: string, _interval: string, cb: (klines: AsterKline[]) => void): void {
|
||||
watchKlines(_symbol: string, _interval: string, cb: (klines: Kline[]) => void): void {
|
||||
cb([
|
||||
{
|
||||
openTime: 1,
|
||||
@@ -75,7 +75,7 @@ class FakeAdapter implements ExchangeAdapter {
|
||||
]);
|
||||
}
|
||||
|
||||
async createOrder(params: CreateOrderParams): Promise<AsterOrder> {
|
||||
async createOrder(params: CreateOrderParams): Promise<Order> {
|
||||
this.createOrderCalls += 1;
|
||||
return {
|
||||
orderId: "1",
|
||||
|
||||
@@ -2,11 +2,11 @@ import { describe, expect, it } from "vitest";
|
||||
import { DryRunExchangeAdapter } from "../src/exchanges/dry-run-adapter";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type {
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
CreateOrderParams,
|
||||
} from "../src/exchanges/types";
|
||||
|
||||
@@ -18,13 +18,13 @@ class BaseAdapter implements ExchangeAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(_params: CreateOrderParams): Promise<AsterOrder> {
|
||||
async createOrder(_params: CreateOrderParams): Promise<Order> {
|
||||
this.createCalls += 1;
|
||||
throw new Error("should not be called in dry-run");
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import {
|
||||
import { buildAdapterFromEnv } from "../src/exchanges/resolve-from-env";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type {
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterKline,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Kline,
|
||||
Order,
|
||||
Ticker,
|
||||
CreateOrderParams,
|
||||
} from "../src/exchanges/types";
|
||||
|
||||
@@ -78,17 +78,17 @@ class RecorderAdapter implements ExchangeAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(params: CreateOrderParams): Promise<AsterOrder> {
|
||||
async createOrder(params: CreateOrderParams): Promise<Order> {
|
||||
this.lastCreateOrderParams = params;
|
||||
return {
|
||||
orderId: 1,
|
||||
|
||||
+22
-22
@@ -1,10 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type {
|
||||
AsterAccountSnapshot,
|
||||
AsterDepth,
|
||||
AsterOrder,
|
||||
AsterTicker,
|
||||
AccountSnapshot,
|
||||
Depth,
|
||||
Order,
|
||||
Ticker,
|
||||
CreateOrderParams,
|
||||
} from "../src/exchanges/types";
|
||||
import type { GridConfig } from "../src/config";
|
||||
@@ -13,11 +13,11 @@ import { GridEngine } from "../src/strategy/grid-engine";
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "aster";
|
||||
|
||||
private accountHandler: ((snapshot: AsterAccountSnapshot) => void) | null = null;
|
||||
private orderHandler: ((orders: AsterOrder[]) => void) | null = null;
|
||||
private depthHandler: ((depth: AsterDepth) => void) | null = null;
|
||||
private tickerHandler: ((ticker: AsterTicker) => void) | null = null;
|
||||
private currentOrders: AsterOrder[] = [];
|
||||
private accountHandler: ((snapshot: AccountSnapshot) => void) | null = null;
|
||||
private orderHandler: ((orders: Order[]) => void) | null = null;
|
||||
private depthHandler: ((depth: Depth) => void) | null = null;
|
||||
private tickerHandler: ((ticker: Ticker) => void) | null = null;
|
||||
private currentOrders: Order[] = [];
|
||||
|
||||
public createdOrders: CreateOrderParams[] = [];
|
||||
public marketOrders: CreateOrderParams[] = [];
|
||||
@@ -28,19 +28,19 @@ class StubAdapter implements ExchangeAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(cb: (snapshot: AsterAccountSnapshot) => void): void {
|
||||
watchAccount(cb: (snapshot: AccountSnapshot) => void): void {
|
||||
this.accountHandler = cb;
|
||||
}
|
||||
|
||||
watchOrders(cb: (orders: AsterOrder[]) => void): void {
|
||||
watchOrders(cb: (orders: Order[]) => void): void {
|
||||
this.orderHandler = cb;
|
||||
}
|
||||
|
||||
watchDepth(_symbol: string, cb: (depth: AsterDepth) => void): void {
|
||||
watchDepth(_symbol: string, cb: (depth: Depth) => void): void {
|
||||
this.depthHandler = cb;
|
||||
}
|
||||
|
||||
watchTicker(_symbol: string, cb: (ticker: AsterTicker) => void): void {
|
||||
watchTicker(_symbol: string, cb: (ticker: Ticker) => void): void {
|
||||
this.tickerHandler = cb;
|
||||
}
|
||||
|
||||
@@ -48,24 +48,24 @@ class StubAdapter implements ExchangeAdapter {
|
||||
// not used in tests
|
||||
}
|
||||
|
||||
emitAccount(snapshot: AsterAccountSnapshot): void {
|
||||
emitAccount(snapshot: AccountSnapshot): void {
|
||||
this.accountHandler?.(snapshot);
|
||||
}
|
||||
|
||||
emitOrders(orders: AsterOrder[]): void {
|
||||
emitOrders(orders: Order[]): void {
|
||||
this.orderHandler?.(orders);
|
||||
}
|
||||
|
||||
emitDepth(depth: AsterDepth): void {
|
||||
emitDepth(depth: Depth): void {
|
||||
this.depthHandler?.(depth);
|
||||
}
|
||||
|
||||
emitTicker(ticker: AsterTicker): void {
|
||||
emitTicker(ticker: Ticker): void {
|
||||
this.tickerHandler?.(ticker);
|
||||
}
|
||||
|
||||
async createOrder(params: CreateOrderParams): Promise<AsterOrder> {
|
||||
const order: AsterOrder = {
|
||||
async createOrder(params: CreateOrderParams): Promise<Order> {
|
||||
const order: Order = {
|
||||
orderId: `${Date.now()}-${Math.random()}`,
|
||||
clientOrderId: "test",
|
||||
symbol: params.symbol,
|
||||
@@ -107,7 +107,7 @@ class StubAdapter implements ExchangeAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
function createAccountSnapshot(symbol: string, positionAmt: number): AsterAccountSnapshot {
|
||||
function createAccountSnapshot(symbol: string, positionAmt: number): AccountSnapshot {
|
||||
return {
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
@@ -126,7 +126,7 @@ function createAccountSnapshot(symbol: string, positionAmt: number): AsterAccoun
|
||||
},
|
||||
],
|
||||
assets: [],
|
||||
} as unknown as AsterAccountSnapshot;
|
||||
} as unknown as AccountSnapshot;
|
||||
}
|
||||
|
||||
describe("GridEngine", () => {
|
||||
@@ -296,7 +296,7 @@ describe("GridEngine", () => {
|
||||
|
||||
adapter.emitAccount(createAccountSnapshot(baseConfig.symbol, baseConfig.orderSize * 2));
|
||||
|
||||
const reduceOrder: AsterOrder = {
|
||||
const reduceOrder: Order = {
|
||||
orderId: "existing-reduce",
|
||||
clientOrderId: "existing-reduce",
|
||||
symbol: baseConfig.symbol,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { t } from "../src/i18n";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
@@ -11,13 +11,13 @@ class StubAdapter implements ExchangeAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "standx";
|
||||
accountSnapshot: AsterAccountSnapshot | null = null;
|
||||
accountSnapshot: AccountSnapshot | null = null;
|
||||
|
||||
supportsTrailingStops(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class StubAdapter implements ExchangeAdapter {
|
||||
async cancelOrders(): Promise<void> {}
|
||||
async cancelAllOrders(): Promise<void> {}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return this.accountSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "standx";
|
||||
cancelAllCount = 0;
|
||||
openOrders: AsterOrder[] | Error = [];
|
||||
accountSnapshot: AsterAccountSnapshot | null = null;
|
||||
openOrders: Order[] | Error = [];
|
||||
accountSnapshot: AccountSnapshot | null = null;
|
||||
|
||||
supportsTrailingStops(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ class StubAdapter implements ExchangeAdapter {
|
||||
this.openOrders = [];
|
||||
}
|
||||
|
||||
async queryOpenOrders(): Promise<AsterOrder[]> {
|
||||
async queryOpenOrders(): Promise<Order[]> {
|
||||
if (this.openOrders instanceof Error) throw this.openOrders;
|
||||
return this.openOrders;
|
||||
}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return this.accountSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "standx";
|
||||
|
||||
private depthListeners: Array<(depth: AsterDepth) => void> = [];
|
||||
private depthListeners: Array<(depth: Depth) => void> = [];
|
||||
|
||||
supportsTrailingStops(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
watchDepth(_symbol: string, cb: (depth: AsterDepth) => void): void {
|
||||
watchDepth(_symbol: string, cb: (depth: Depth) => void): void {
|
||||
this.depthListeners.push(cb);
|
||||
}
|
||||
|
||||
emitDepth(depth: AsterDepth): void {
|
||||
emitDepth(depth: Depth): void {
|
||||
for (const listener of this.depthListeners) {
|
||||
listener(depth);
|
||||
}
|
||||
}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class StubAdapter implements ExchangeAdapter {
|
||||
async cancelOrders(): Promise<void> {}
|
||||
async cancelAllOrders(): Promise<void> {}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
class StubAdapter implements ExchangeAdapter {
|
||||
id = "standx";
|
||||
|
||||
private depthListeners: Array<(depth: AsterDepth) => void> = [];
|
||||
private depthListeners: Array<(depth: Depth) => void> = [];
|
||||
|
||||
supportsTrailingStops(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
watchDepth(_symbol: string, cb: (depth: AsterDepth) => void): void {
|
||||
watchDepth(_symbol: string, cb: (depth: Depth) => void): void {
|
||||
this.depthListeners.push(cb);
|
||||
}
|
||||
|
||||
emitDepth(depth: AsterDepth): void {
|
||||
emitDepth(depth: Depth): void {
|
||||
for (const listener of this.depthListeners) {
|
||||
listener(depth);
|
||||
}
|
||||
}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class StubAdapter implements ExchangeAdapter {
|
||||
async cancelOrders(): Promise<void> {}
|
||||
async cancelAllOrders(): Promise<void> {}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterAccountSnapshot, AsterDepth, AsterKline, AsterOrder, AsterTicker } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Depth, Kline, Order, Ticker } from "../src/exchanges/types";
|
||||
import { MakerPointsEngine } from "../src/strategy/maker-points-engine";
|
||||
|
||||
class StandxStubAdapter implements ExchangeAdapter {
|
||||
@@ -12,20 +12,20 @@ class StandxStubAdapter implements ExchangeAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
watchAccount(_cb: (snapshot: AsterAccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: AsterOrder[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: AsterDepth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: AsterTicker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: AsterKline[]) => void): void {}
|
||||
watchAccount(_cb: (snapshot: AccountSnapshot) => void): void {}
|
||||
watchOrders(_cb: (orders: Order[]) => void): void {}
|
||||
watchDepth(_symbol: string, _cb: (depth: Depth) => void): void {}
|
||||
watchTicker(_symbol: string, _cb: (ticker: Ticker) => void): void {}
|
||||
watchKlines(_symbol: string, _interval: string, _cb: (klines: Kline[]) => void): void {}
|
||||
|
||||
async createOrder(): Promise<AsterOrder> {
|
||||
async createOrder(): Promise<Order> {
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
async cancelOrder(): Promise<void> {}
|
||||
async cancelOrders(): Promise<void> {}
|
||||
async cancelAllOrders(): Promise<void> {}
|
||||
|
||||
async queryAccountSnapshot(): Promise<AsterAccountSnapshot | null> {
|
||||
async queryAccountSnapshot(): Promise<AccountSnapshot | null> {
|
||||
return {
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
@@ -98,7 +98,7 @@ describe("MakerPointsEngine StandX isolated margin guard", () => {
|
||||
asks: [["101", "1"]],
|
||||
eventTime: Date.now(),
|
||||
symbol: "BTC-USD",
|
||||
} as AsterDepth;
|
||||
} as Depth;
|
||||
(engine as any).tickerSnapshot = {
|
||||
symbol: "BTC-USD",
|
||||
lastPrice: "100",
|
||||
@@ -108,7 +108,7 @@ describe("MakerPointsEngine StandX isolated margin guard", () => {
|
||||
volume: "0",
|
||||
quoteVolume: "0",
|
||||
eventTime: Date.now(),
|
||||
} as AsterTicker;
|
||||
} as Ticker;
|
||||
|
||||
const syncSpy = vi.fn().mockResolvedValue(undefined);
|
||||
(engine as any).syncOrders = syncSpy;
|
||||
@@ -162,7 +162,7 @@ describe("MakerPointsEngine StandX isolated margin guard", () => {
|
||||
asks: [["101", "1"]],
|
||||
eventTime: Date.now(),
|
||||
symbol: "BTC-USD",
|
||||
} as AsterDepth;
|
||||
} as Depth;
|
||||
(engine as any).tickerSnapshot = {
|
||||
symbol: "BTC-USD",
|
||||
lastPrice: "100",
|
||||
@@ -172,7 +172,7 @@ describe("MakerPointsEngine StandX isolated margin guard", () => {
|
||||
volume: "0",
|
||||
quoteVolume: "0",
|
||||
eventTime: Date.now(),
|
||||
} as AsterTicker;
|
||||
} as Ticker;
|
||||
|
||||
const syncSpy = vi.fn().mockResolvedValue(undefined);
|
||||
(engine as any).syncOrders = syncSpy;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi, beforeEach, afterAll } from "vitest";
|
||||
import type { ExchangeAdapter } from "../src/exchanges/adapter";
|
||||
import type { AsterOrder } from "../src/exchanges/types";
|
||||
import type { Order } from "../src/exchanges/types";
|
||||
import type { OrderLockMap, OrderTimerMap, OrderPendingMap } from "../src/core/order-coordinator";
|
||||
import {
|
||||
deduplicateOrders,
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
const originalTradeExchange = process.env.TRADE_EXCHANGE;
|
||||
const originalExchange = process.env.EXCHANGE;
|
||||
|
||||
const baseOrder: AsterOrder = {
|
||||
const baseOrder: Order = {
|
||||
orderId: 1,
|
||||
clientOrderId: "client",
|
||||
symbol: "BTCUSDT",
|
||||
@@ -66,7 +66,7 @@ describe("order-coordinator", () => {
|
||||
const timers: OrderTimerMap = {};
|
||||
const pending: OrderPendingMap = {};
|
||||
const log = vi.fn();
|
||||
const openOrders: AsterOrder[] = [
|
||||
const openOrders: Order[] = [
|
||||
{ ...baseOrder, orderId: 1 },
|
||||
{ ...baseOrder, orderId: 2 },
|
||||
];
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getDepthBetweenPrices } from "../src/utils/price";
|
||||
import type { AsterDepth } from "../src/exchanges/types";
|
||||
import type { Depth } from "../src/exchanges/types";
|
||||
|
||||
describe("getDepthBetweenPrices boundary", () => {
|
||||
it("SELL side excludes quantity exactly at target price", () => {
|
||||
const depth: AsterDepth = {
|
||||
const depth: Depth = {
|
||||
lastUpdateId: 1,
|
||||
bids: [],
|
||||
asks: [
|
||||
@@ -20,7 +20,7 @@ describe("getDepthBetweenPrices boundary", () => {
|
||||
});
|
||||
|
||||
it("BUY side excludes quantity exactly at target price", () => {
|
||||
const depth: AsterDepth = {
|
||||
const depth: Depth = {
|
||||
lastUpdateId: 1,
|
||||
bids: [
|
||||
["69355", "1"],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { computeBollingerBandwidth, getPosition, getSMA } from "../src/utils/strategy";
|
||||
import type { AsterAccountSnapshot, AsterKline } from "../src/exchanges/types";
|
||||
import type { AccountSnapshot, Kline } from "../src/exchanges/types";
|
||||
|
||||
const mockSnapshot = (positions: Array<{ symbol: string; amt: number; entry: number; pnl: number }> = []): AsterAccountSnapshot => ({
|
||||
const mockSnapshot = (positions: Array<{ symbol: string; amt: number; entry: number; pnl: number }> = []): AccountSnapshot => ({
|
||||
canTrade: true,
|
||||
canDeposit: true,
|
||||
canWithdraw: true,
|
||||
@@ -20,7 +20,7 @@ const mockSnapshot = (positions: Array<{ symbol: string; amt: number; entry: num
|
||||
assets: [],
|
||||
});
|
||||
|
||||
const mockKlines = (values: number[]): AsterKline[] =>
|
||||
const mockKlines = (values: number[]): Kline[] =>
|
||||
values.map((value, index) => ({
|
||||
openTime: index,
|
||||
open: String(value),
|
||||
|
||||
Reference in New Issue
Block a user