@vesper85/strategy-sdk 0.1.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/LICENSE +22 -0
- package/README.md +448 -0
- package/dist/clients/hyperliquid-client.d.ts +68 -0
- package/dist/clients/polymarket-client.d.ts +157 -0
- package/dist/context/osiris-context.d.ts +14 -0
- package/dist/engine/event-runner.d.ts +129 -0
- package/dist/engine/strategy-runner.d.ts +65 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +2195 -0
- package/dist/signer/index.d.ts +54 -0
- package/dist/signer/osiris-signer.d.ts +29 -0
- package/dist/signer/privatekey-signer.d.ts +41 -0
- package/dist/signer/types.d.ts +62 -0
- package/dist/state/memory-state.d.ts +17 -0
- package/dist/state/redis-state.d.ts +20 -0
- package/dist/types/event-types.d.ts +102 -0
- package/dist/types/osiris.d.ts +414 -0
- package/dist/types/strategy.d.ts +35 -0
- package/dist/utils/logger.d.ts +15 -0
- package/package.json +76 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OsirisContext, SignerAPI, PolymarketClientOptions } from "../types/osiris";
|
|
2
|
+
export interface OsirisContextConfig {
|
|
3
|
+
strategyId: string;
|
|
4
|
+
market: 'polymarket' | 'hyperliquid';
|
|
5
|
+
userAddress: string;
|
|
6
|
+
signer: SignerAPI;
|
|
7
|
+
/** Options specific to Polymarket trading */
|
|
8
|
+
polymarketOptions?: PolymarketClientOptions;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates an OsirisContext with the appropriate market APIs based on configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function createOsirisContext(config: OsirisContextConfig): OsirisContext;
|
|
14
|
+
//# sourceMappingURL=osiris-context.d.ts.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { CodeStrategy } from "../types/strategy";
|
|
2
|
+
import type { OsirisContext } from "../types/osiris";
|
|
3
|
+
import type { Logger } from "../utils/logger";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the EventRunner
|
|
6
|
+
*/
|
|
7
|
+
export interface EventRunnerConfig {
|
|
8
|
+
/** Logger instance for logging */
|
|
9
|
+
logger: Logger;
|
|
10
|
+
/** WebSocket URL for the event source server */
|
|
11
|
+
eventSourceUrl: string;
|
|
12
|
+
/** Optional strategy ID for logging (defaults to 'unnamed-strategy') */
|
|
13
|
+
strategyId?: string;
|
|
14
|
+
/** Reconnection settings */
|
|
15
|
+
reconnect?: {
|
|
16
|
+
/** Maximum number of reconnection attempts (default: 10) */
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
/** Base delay between reconnection attempts in ms (default: 1000) */
|
|
19
|
+
delayMs?: number;
|
|
20
|
+
/** Maximum delay between reconnection attempts in ms (default: 30000) */
|
|
21
|
+
maxDelayMs?: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Event Runner for event-based strategy execution
|
|
26
|
+
*
|
|
27
|
+
* Connects to an external WebSocket event source and dispatches
|
|
28
|
+
* events to the strategy's onEvent handler.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const runner = createEventRunner(strategy, {
|
|
33
|
+
* strategyId: 'my-strategy',
|
|
34
|
+
* market: 'polymarket',
|
|
35
|
+
* logger: createConsoleLogger(),
|
|
36
|
+
* eventSourceUrl: 'wss://events.example.com/ws',
|
|
37
|
+
* }, context);
|
|
38
|
+
*
|
|
39
|
+
* runner.start();
|
|
40
|
+
* // ... later
|
|
41
|
+
* runner.stop();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class EventRunner {
|
|
45
|
+
private strategy;
|
|
46
|
+
private config;
|
|
47
|
+
private context;
|
|
48
|
+
private ws;
|
|
49
|
+
private isRunning;
|
|
50
|
+
private reconnectAttempts;
|
|
51
|
+
private reconnectTimeout;
|
|
52
|
+
private isIntentionallyClosed;
|
|
53
|
+
private readonly maxReconnectAttempts;
|
|
54
|
+
private readonly baseReconnectDelay;
|
|
55
|
+
private readonly maxReconnectDelay;
|
|
56
|
+
constructor(strategy: CodeStrategy, config: EventRunnerConfig, context: OsirisContext);
|
|
57
|
+
/**
|
|
58
|
+
* Start listening to events
|
|
59
|
+
* Connects to the WebSocket and subscribes to events
|
|
60
|
+
*/
|
|
61
|
+
start(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Stop listening and disconnect from WebSocket
|
|
64
|
+
*/
|
|
65
|
+
stop(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Check if the runner is currently active
|
|
68
|
+
*/
|
|
69
|
+
isActive(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get current connection status
|
|
72
|
+
*/
|
|
73
|
+
getStatus(): {
|
|
74
|
+
running: boolean;
|
|
75
|
+
connected: boolean;
|
|
76
|
+
reconnectAttempts: number;
|
|
77
|
+
subscriptionCount: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Connect to the WebSocket event source
|
|
81
|
+
*/
|
|
82
|
+
private connect;
|
|
83
|
+
/**
|
|
84
|
+
* Attempt to reconnect with exponential backoff
|
|
85
|
+
*/
|
|
86
|
+
private attemptReconnect;
|
|
87
|
+
/**
|
|
88
|
+
* Subscribe to events based on strategy's subscriptions
|
|
89
|
+
*/
|
|
90
|
+
private subscribeToEvents;
|
|
91
|
+
/**
|
|
92
|
+
* Unsubscribe from events before disconnecting
|
|
93
|
+
*/
|
|
94
|
+
private unsubscribeFromEvents;
|
|
95
|
+
/**
|
|
96
|
+
* Handle incoming WebSocket messages
|
|
97
|
+
*/
|
|
98
|
+
private handleMessage;
|
|
99
|
+
/**
|
|
100
|
+
* Validate that a message is a valid StrategyEvent
|
|
101
|
+
*/
|
|
102
|
+
private isValidEvent;
|
|
103
|
+
/**
|
|
104
|
+
* Dispatch an event to the strategy's onEvent handler
|
|
105
|
+
*/
|
|
106
|
+
private dispatchEvent;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create an EventRunner instance for event-based strategy execution
|
|
110
|
+
*
|
|
111
|
+
* @param strategy - The strategy to run (must have subscriptions and onEvent)
|
|
112
|
+
* @param config - Runner configuration
|
|
113
|
+
* @param context - Osiris context with market APIs
|
|
114
|
+
* @returns EventRunner instance
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const runner = createEventRunner(myStrategy, {
|
|
119
|
+
* strategyId: 'price-alert-strategy',
|
|
120
|
+
* market: 'polymarket',
|
|
121
|
+
* logger: createConsoleLogger(),
|
|
122
|
+
* eventSourceUrl: 'wss://events.mybackend.com/ws',
|
|
123
|
+
* }, context);
|
|
124
|
+
*
|
|
125
|
+
* runner.start();
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function createEventRunner(strategy: CodeStrategy, config: EventRunnerConfig, context: OsirisContext): EventRunner;
|
|
129
|
+
//# sourceMappingURL=event-runner.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CodeStrategy } from "../types/strategy";
|
|
2
|
+
import type { OsirisContext } from "../types/osiris";
|
|
3
|
+
import type { Logger } from "../utils/logger";
|
|
4
|
+
export interface StrategyRunnerConfig {
|
|
5
|
+
/** Logger instance for logging */
|
|
6
|
+
logger: Logger;
|
|
7
|
+
/** Optional strategy ID for logging (defaults to 'unnamed-strategy') */
|
|
8
|
+
strategyId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface StrategyEngineConfig extends StrategyRunnerConfig {
|
|
11
|
+
/** Interval between ticks in milliseconds (default: 60000) */
|
|
12
|
+
tickIntervalMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Run a strategy once (one-off execution for tick-based strategies)
|
|
16
|
+
* Returns true if the strategy was triggered, false otherwise
|
|
17
|
+
*
|
|
18
|
+
* @throws Error if strategy doesn't have tick-based methods
|
|
19
|
+
*/
|
|
20
|
+
export declare function runStrategy(strategy: CodeStrategy, config: StrategyRunnerConfig, context: OsirisContext): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a strategy engine that runs a strategy on a tick interval
|
|
23
|
+
* Returns a controller object to start/stop the engine
|
|
24
|
+
*/
|
|
25
|
+
export declare function createStrategyEngine(strategy: CodeStrategy, config: StrategyEngineConfig, context: OsirisContext): StrategyEngine;
|
|
26
|
+
/**
|
|
27
|
+
* Strategy Engine that runs a strategy on a tick interval
|
|
28
|
+
*/
|
|
29
|
+
export declare class StrategyEngine {
|
|
30
|
+
private strategy;
|
|
31
|
+
private config;
|
|
32
|
+
private context;
|
|
33
|
+
private intervalId;
|
|
34
|
+
private isRunning;
|
|
35
|
+
constructor(strategy: CodeStrategy, config: StrategyEngineConfig, context: OsirisContext);
|
|
36
|
+
/**
|
|
37
|
+
* Start the engine with the configured tick interval
|
|
38
|
+
*/
|
|
39
|
+
start(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Stop the engine
|
|
42
|
+
*/
|
|
43
|
+
stop(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if the engine is currently running
|
|
46
|
+
*/
|
|
47
|
+
isActive(): boolean;
|
|
48
|
+
private tick;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a strategy is event-based
|
|
52
|
+
* Event-based strategies have subscriptions and an onEvent handler
|
|
53
|
+
*/
|
|
54
|
+
export declare function isEventBasedStrategy(strategy: CodeStrategy): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a strategy is tick-based
|
|
57
|
+
* Tick-based strategies have shouldTrigger and onTrigger methods
|
|
58
|
+
*/
|
|
59
|
+
export declare function isTickBasedStrategy(strategy: CodeStrategy): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Validate that a strategy has the required methods for its execution mode
|
|
62
|
+
* @throws Error if strategy is invalid
|
|
63
|
+
*/
|
|
64
|
+
export declare function validateStrategy(strategy: CodeStrategy): void;
|
|
65
|
+
//# sourceMappingURL=strategy-runner.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { CodeStrategy, } from './types/strategy';
|
|
2
|
+
export type { OsirisContext, OsirisState, PolymarketAPI, HyperliquidAPI, TechnicalAnalysisAPI, SignerAPI, PolymarketOrderSide, PolymarketLimitOrderParams, PolymarketMarketOrderParams, PolymarketOrderResponse, PolymarketOpenOrder, PolymarketCancelResponse, PolymarketOrderBook, PolymarketOrderBookEntry, PolymarketApprovalResult, PolymarketClientOptions, } from './types/osiris';
|
|
3
|
+
export type { EventType, EventSubscription, EventConditions, StrategyEvent, EventData, EventSourceSubscribeMessage, EventSourceUnsubscribeMessage, EventSourceMessage, } from './types/event-types';
|
|
4
|
+
export { PolymarketClient, } from './clients/polymarket-client';
|
|
5
|
+
export { HyperliquidClient, } from './clients/hyperliquid-client';
|
|
6
|
+
export { MemoryStateManager, } from './state/memory-state';
|
|
7
|
+
export { RedisStateManager, } from './state/redis-state';
|
|
8
|
+
export { createOsirisContext, type OsirisContextConfig, } from './context/osiris-context';
|
|
9
|
+
export { runStrategy, createStrategyEngine, StrategyEngine, isEventBasedStrategy, isTickBasedStrategy, validateStrategy, type StrategyRunnerConfig, type StrategyEngineConfig, } from './engine/strategy-runner';
|
|
10
|
+
export { EventRunner, createEventRunner, type EventRunnerConfig, } from './engine/event-runner';
|
|
11
|
+
export { createConsoleLogger, type Logger, } from './utils/logger';
|
|
12
|
+
export { Signer, OsirisSigner, PrivateKeySigner, type ISigner, type SignerConfig, type OsirisSignerConfig, type PrivateKeySignerConfig, } from './signer';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|