@megatao/sdk 1.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/.env.example +37 -0
- package/CHANGELOG.md +19 -0
- package/README.md +199 -0
- package/bin/alf +4 -0
- package/cli/README.md +198 -0
- package/cli/TEST_MANUAL.md +577 -0
- package/cli/commands/account.ts +545 -0
- package/cli/commands/funding.ts +481 -0
- package/cli/commands/liquidation.ts +523 -0
- package/cli/commands/market.ts +590 -0
- package/cli/commands/orders.ts +395 -0
- package/cli/commands/position.ts +1085 -0
- package/cli/commands/shared/positionUtils.ts +239 -0
- package/cli/commands/trading.ts +483 -0
- package/cli/commands/utils.ts +281 -0
- package/cli/commands/vault.ts +522 -0
- package/cli/index.ts +169 -0
- package/cli/interactive.ts +530 -0
- package/cli/utils/client.ts +457 -0
- package/cli/utils/config.ts +226 -0
- package/cli/utils/display.ts +258 -0
- package/cli/utils/index.ts +10 -0
- package/cli/utils/prompts.ts +364 -0
- package/config.example.json +23 -0
- package/dist/AlphaFuturesClient.d.ts +36 -0
- package/dist/AlphaFuturesClient.d.ts.map +1 -0
- package/dist/AlphaFuturesClient.js +116 -0
- package/dist/AlphaFuturesClient.js.map +1 -0
- package/dist/abi/Alpha.json +5987 -0
- package/dist/abi/abis.d.ts +319 -0
- package/dist/abi/abis.d.ts.map +1 -0
- package/dist/abi/abis.js +128 -0
- package/dist/abi/abis.js.map +1 -0
- package/dist/abi/index.d.ts +11 -0
- package/dist/abi/index.d.ts.map +1 -0
- package/dist/abi/index.js +15 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/config/contracts.config.d.ts +70 -0
- package/dist/config/contracts.config.d.ts.map +1 -0
- package/dist/config/contracts.config.js +137 -0
- package/dist/config/contracts.config.js.map +1 -0
- package/dist/config/environments/alpha.config.d.ts +17 -0
- package/dist/config/environments/alpha.config.d.ts.map +1 -0
- package/dist/config/environments/alpha.config.js +140 -0
- package/dist/config/environments/alpha.config.js.map +1 -0
- package/dist/config/environments/beta.config.d.ts +16 -0
- package/dist/config/environments/beta.config.d.ts.map +1 -0
- package/dist/config/environments/beta.config.js +131 -0
- package/dist/config/environments/beta.config.js.map +1 -0
- package/dist/config/environments/dev.config.d.ts +13 -0
- package/dist/config/environments/dev.config.d.ts.map +1 -0
- package/dist/config/environments/dev.config.js +123 -0
- package/dist/config/environments/dev.config.js.map +1 -0
- package/dist/config/environments/index.d.ts +48 -0
- package/dist/config/environments/index.d.ts.map +1 -0
- package/dist/config/environments/index.js +81 -0
- package/dist/config/environments/index.js.map +1 -0
- package/dist/config/environments/localhost.config.d.ts +16 -0
- package/dist/config/environments/localhost.config.d.ts.map +1 -0
- package/dist/config/environments/localhost.config.js +152 -0
- package/dist/config/environments/localhost.config.js.map +1 -0
- package/dist/config/environments/prod.config.d.ts +20 -0
- package/dist/config/environments/prod.config.d.ts.map +1 -0
- package/dist/config/environments/prod.config.js +143 -0
- package/dist/config/environments/prod.config.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +41 -0
- package/dist/config/index.js.map +1 -0
- package/dist/constants/assets.d.ts +76 -0
- package/dist/constants/assets.d.ts.map +1 -0
- package/dist/constants/assets.js +277 -0
- package/dist/constants/assets.js.map +1 -0
- package/dist/constants/contracts.d.ts +41 -0
- package/dist/constants/contracts.d.ts.map +1 -0
- package/dist/constants/contracts.js +57 -0
- package/dist/constants/contracts.js.map +1 -0
- package/dist/constants/index.d.ts +36 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +75 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/networks.d.ts +32 -0
- package/dist/constants/networks.d.ts.map +1 -0
- package/dist/constants/networks.js +174 -0
- package/dist/constants/networks.js.map +1 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +21 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/viem/AlphaViem.d.ts +518 -0
- package/dist/contracts/viem/AlphaViem.d.ts.map +1 -0
- package/dist/contracts/viem/AlphaViem.js +1287 -0
- package/dist/contracts/viem/AlphaViem.js.map +1 -0
- package/dist/contracts/viem/PriceOracleViem.d.ts +71 -0
- package/dist/contracts/viem/PriceOracleViem.d.ts.map +1 -0
- package/dist/contracts/viem/PriceOracleViem.js +212 -0
- package/dist/contracts/viem/PriceOracleViem.js.map +1 -0
- package/dist/contracts/viem/index.d.ts +9 -0
- package/dist/contracts/viem/index.d.ts.map +1 -0
- package/dist/contracts/viem/index.js +17 -0
- package/dist/contracts/viem/index.js.map +1 -0
- package/dist/errors/index.d.ts +44 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +83 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/types/alpha.d.ts +299 -0
- package/dist/types/alpha.d.ts.map +1 -0
- package/dist/types/alpha.js +6 -0
- package/dist/types/alpha.js.map +1 -0
- package/dist/types/client.d.ts +24 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +13 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/contracts.d.ts +48 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +6 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/funding.d.ts +27 -0
- package/dist/types/funding.d.ts.map +1 -0
- package/dist/types/funding.js +6 -0
- package/dist/types/funding.js.map +1 -0
- package/dist/types/index.d.ts +92 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +47 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/liquidation.d.ts +20 -0
- package/dist/types/liquidation.d.ts.map +1 -0
- package/dist/types/liquidation.js +6 -0
- package/dist/types/liquidation.js.map +1 -0
- package/dist/types/margin.d.ts +29 -0
- package/dist/types/margin.d.ts.map +1 -0
- package/dist/types/margin.js +6 -0
- package/dist/types/margin.js.map +1 -0
- package/dist/types/oracle.d.ts +21 -0
- package/dist/types/oracle.d.ts.map +1 -0
- package/dist/types/oracle.js +6 -0
- package/dist/types/oracle.js.map +1 -0
- package/dist/types/positions.d.ts +43 -0
- package/dist/types/positions.d.ts.map +1 -0
- package/dist/types/positions.js +13 -0
- package/dist/types/positions.js.map +1 -0
- package/dist/utils/calculations.d.ts +84 -0
- package/dist/utils/calculations.d.ts.map +1 -0
- package/dist/utils/calculations.js +155 -0
- package/dist/utils/calculations.js.map +1 -0
- package/dist/utils/errors.d.ts +24 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +129 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +40 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +73 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/format.d.ts +40 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +86 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/network.d.ts +52 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +192 -0
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/positionCalculations.d.ts +145 -0
- package/dist/utils/positionCalculations.d.ts.map +1 -0
- package/dist/utils/positionCalculations.js +278 -0
- package/dist/utils/positionCalculations.js.map +1 -0
- package/dist/utils/validation.d.ts +28 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +68 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/README.md +40 -0
- package/docs/api/API.md +831 -0
- package/docs/guides/GETTING_STARTED.md +316 -0
- package/docs/guides/TRADING_GUIDE.md +677 -0
- package/docs/integration/INTEGRATION_GUIDE.md +1679 -0
- package/docs/integration/VIEM_INTEGRATION.md +294 -0
- package/docs/reference/CLI_QUICK_REFERENCE.md +197 -0
- package/docs/reference/TROUBLESHOOTING.md +922 -0
- package/package.json +113 -0
- package/src/AlphaFuturesClient.ts +158 -0
- package/src/abi/.gitkeep +1 -0
- package/src/abi/Alpha.json +5987 -0
- package/src/abi/README.md +99 -0
- package/src/abi/abis.ts +131 -0
- package/src/abi/index.ts +13 -0
- package/src/config/contracts.config.ts +186 -0
- package/src/config/environments/alpha.config.ts +139 -0
- package/src/config/environments/beta.config.ts +130 -0
- package/src/config/environments/dev.config.ts +122 -0
- package/src/config/environments/index.ts +87 -0
- package/src/config/environments/localhost.config.ts +153 -0
- package/src/config/environments/prod.config.ts +142 -0
- package/src/config/index.ts +29 -0
- package/src/constants/assets.ts +299 -0
- package/src/constants/contracts.ts +64 -0
- package/src/constants/index.ts +69 -0
- package/src/constants/networks.ts +182 -0
- package/src/contracts/index.ts +5 -0
- package/src/contracts/viem/AlphaViem.ts +1615 -0
- package/src/contracts/viem/PriceOracleViem.ts +272 -0
- package/src/contracts/viem/index.ts +11 -0
- package/src/errors/index.ts +87 -0
- package/src/index.ts +59 -0
- package/src/types/VIEM_TYPES_README.md +70 -0
- package/src/types/alpha.ts +358 -0
- package/src/types/client.ts +27 -0
- package/src/types/contracts.ts +74 -0
- package/src/types/funding.ts +31 -0
- package/src/types/index.ts +108 -0
- package/src/types/liquidation.ts +23 -0
- package/src/types/margin.ts +34 -0
- package/src/types/oracle.ts +24 -0
- package/src/types/positions.ts +48 -0
- package/src/utils/calculations.ts +175 -0
- package/src/utils/errors.ts +147 -0
- package/src/utils/events.ts +98 -0
- package/src/utils/format.ts +84 -0
- package/src/utils/index.ts +10 -0
- package/src/utils/network.ts +212 -0
- package/src/utils/positionCalculations.ts +317 -0
- package/src/utils/validation.ts +76 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# Getting Started with Alpha Futures SDK
|
|
2
|
+
|
|
3
|
+
This guide will help you get up and running with the Alpha Futures SDK and CLI in just a few minutes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js 16.0.0 or higher
|
|
8
|
+
- npm or yarn package manager
|
|
9
|
+
- An Ethereum wallet with TAO tokens for trading
|
|
10
|
+
- Access to an Ethereum RPC endpoint
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### Option 1: Global Installation (Recommended for CLI usage)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @alpha-futures/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Option 2: Project Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @alpha-futures/sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Option 3: Run without Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx @alpha-futures/sdk --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Initial Setup
|
|
33
|
+
|
|
34
|
+
### 1. Create Configuration File
|
|
35
|
+
|
|
36
|
+
Copy the example configuration file:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cp config.example.json config.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Edit `config.json` with your settings:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"network": "mainnet",
|
|
47
|
+
"rpcUrl": "https://your-rpc-url.com"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. Set Up Environment Variables
|
|
52
|
+
|
|
53
|
+
Copy the example environment file:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
cp .env.example .env
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Edit `.env` with your private key:
|
|
60
|
+
|
|
61
|
+
```env
|
|
62
|
+
PRIVATE_KEY=your_private_key_here
|
|
63
|
+
NETWORK=mainnet
|
|
64
|
+
RPC_URL=https://your-rpc-url.com
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Security Note**: Never commit `.env` files to version control!
|
|
68
|
+
|
|
69
|
+
### 3. Test Your Setup
|
|
70
|
+
|
|
71
|
+
Run the CLI to verify installation:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
alpha-futures --version
|
|
75
|
+
alpha-futures account info
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Your First Trade
|
|
79
|
+
|
|
80
|
+
### Using the Interactive CLI
|
|
81
|
+
|
|
82
|
+
1. Launch the interactive interface:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
alpha-futures interactive
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
2. Select "Open Position" from the menu
|
|
89
|
+
|
|
90
|
+
3. Follow the prompts to:
|
|
91
|
+
- Choose an asset (e.g., ALPHA)
|
|
92
|
+
- Enter position size
|
|
93
|
+
- Select leverage (1-10x)
|
|
94
|
+
- Choose direction (long/short)
|
|
95
|
+
|
|
96
|
+
### Using Command Line
|
|
97
|
+
|
|
98
|
+
Open a long position with 3x leverage:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
alpha-futures position open --asset ALPHA --size 1000 --leverage 3 --long
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Using the SDK
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { AlphaFuturesClient } from '@alpha-futures/sdk';
|
|
108
|
+
|
|
109
|
+
async function openFirstPosition() {
|
|
110
|
+
// Initialize client
|
|
111
|
+
const client = new AlphaFuturesClient({
|
|
112
|
+
network: 'mainnet',
|
|
113
|
+
privateKey: process.env.PRIVATE_KEY
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Check account balance
|
|
117
|
+
const margin = await client.margin.getMarginAccount();
|
|
118
|
+
console.log('Available margin:', margin.availableMargin);
|
|
119
|
+
|
|
120
|
+
// Open a position
|
|
121
|
+
const position = await client.positions.openPosition({
|
|
122
|
+
asset: 'ALPHA',
|
|
123
|
+
size: 1000,
|
|
124
|
+
leverage: 3,
|
|
125
|
+
isLong: true
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
console.log('Position opened:', position.id);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
openFirstPosition().catch(console.error);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Common Operations
|
|
135
|
+
|
|
136
|
+
### Check Your Positions
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# List all positions
|
|
140
|
+
alpha-futures position list
|
|
141
|
+
|
|
142
|
+
# Get specific position details
|
|
143
|
+
alpha-futures position info 0x00000000000000000000000000000001
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Monitor Market Data
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Check current prices
|
|
150
|
+
alpha-futures market prices
|
|
151
|
+
|
|
152
|
+
# View funding rates
|
|
153
|
+
alpha-futures market funding-rates
|
|
154
|
+
|
|
155
|
+
# See market statistics
|
|
156
|
+
alpha-futures market stats
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Manage Your Account
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Check balance
|
|
163
|
+
alpha-futures account balance
|
|
164
|
+
|
|
165
|
+
# Deposit more margin
|
|
166
|
+
alpha-futures account deposit --amount 500
|
|
167
|
+
|
|
168
|
+
# Withdraw profits
|
|
169
|
+
alpha-futures account withdraw --amount 200
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Best Practices
|
|
173
|
+
|
|
174
|
+
### 1. Start Small
|
|
175
|
+
|
|
176
|
+
- Begin with small position sizes to understand the platform
|
|
177
|
+
- Use lower leverage (2-3x) initially
|
|
178
|
+
- Monitor funding rates before opening positions
|
|
179
|
+
|
|
180
|
+
### 2. Risk Management
|
|
181
|
+
|
|
182
|
+
- Always maintain sufficient margin (>50% recommended)
|
|
183
|
+
- Set stop-loss levels mentally or through monitoring
|
|
184
|
+
- Diversify across multiple positions
|
|
185
|
+
|
|
186
|
+
### 3. Monitor Positions
|
|
187
|
+
|
|
188
|
+
- Check funding payments regularly
|
|
189
|
+
- Watch for liquidation warnings
|
|
190
|
+
- Keep track of unrealized P&L
|
|
191
|
+
|
|
192
|
+
### 4. Use the Interactive CLI
|
|
193
|
+
|
|
194
|
+
The interactive CLI provides:
|
|
195
|
+
- Visual feedback and confirmations
|
|
196
|
+
- Input validation
|
|
197
|
+
- Real-time price updates
|
|
198
|
+
- Transaction status tracking
|
|
199
|
+
|
|
200
|
+
## Troubleshooting
|
|
201
|
+
|
|
202
|
+
### Common Issues
|
|
203
|
+
|
|
204
|
+
1. **"Insufficient margin" error**
|
|
205
|
+
- Check your account balance: `alpha-futures account balance`
|
|
206
|
+
- Deposit more TAO: `alpha-futures account deposit --amount 1000`
|
|
207
|
+
|
|
208
|
+
2. **"Cannot connect to network"**
|
|
209
|
+
- Verify your RPC URL is correct
|
|
210
|
+
- Check your internet connection
|
|
211
|
+
- Try a different RPC endpoint
|
|
212
|
+
|
|
213
|
+
3. **"Invalid private key"**
|
|
214
|
+
- Ensure your private key is correctly formatted
|
|
215
|
+
- Don't include '0x' prefix in .env file
|
|
216
|
+
- Check for extra spaces or newlines
|
|
217
|
+
|
|
218
|
+
4. **"Gas estimation failed"**
|
|
219
|
+
- Increase gas limit in settings
|
|
220
|
+
- Check if you have enough ETH for gas
|
|
221
|
+
- Try again during lower network congestion
|
|
222
|
+
|
|
223
|
+
### Debug Mode
|
|
224
|
+
|
|
225
|
+
Enable debug logging for more information:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
DEBUG=true alpha-futures position list
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Next Steps
|
|
232
|
+
|
|
233
|
+
1. **Explore Advanced Features**
|
|
234
|
+
- Learn about limit orders
|
|
235
|
+
- Understand funding rate arbitrage
|
|
236
|
+
- Explore batch operations
|
|
237
|
+
|
|
238
|
+
2. **Integrate the SDK**
|
|
239
|
+
- Build trading bots
|
|
240
|
+
- Create position monitors
|
|
241
|
+
- Develop custom strategies
|
|
242
|
+
|
|
243
|
+
3. **Join the Community**
|
|
244
|
+
- Discord: [https://discord.gg/alphafutures](https://discord.gg/alphafutures)
|
|
245
|
+
- Follow updates on Twitter
|
|
246
|
+
- Contribute to the SDK on GitHub
|
|
247
|
+
|
|
248
|
+
## Example Scripts
|
|
249
|
+
|
|
250
|
+
### Position Monitor
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
// monitor.ts
|
|
254
|
+
import { AlphaFuturesClient } from '@alpha-futures/sdk';
|
|
255
|
+
|
|
256
|
+
const client = new AlphaFuturesClient({
|
|
257
|
+
network: 'mainnet',
|
|
258
|
+
privateKey: process.env.PRIVATE_KEY
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
async function monitorPositions() {
|
|
262
|
+
const positions = await client.positions.getAllPositions();
|
|
263
|
+
|
|
264
|
+
for (const position of positions) {
|
|
265
|
+
const pnl = await client.positions.getUnrealizedPnL(position.id);
|
|
266
|
+
const marginRatio = await client.positions.getMarginRatio(position.id);
|
|
267
|
+
|
|
268
|
+
console.log(`Position ${position.id}:`);
|
|
269
|
+
console.log(` P&L: ${pnl > 0 ? '+' : ''}${pnl.toFixed(2)} TAO`);
|
|
270
|
+
console.log(` Margin Ratio: ${marginRatio.toFixed(2)}%`);
|
|
271
|
+
|
|
272
|
+
if (marginRatio < 25) {
|
|
273
|
+
console.warn(' ⚠️ Low margin - consider adding margin!');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Run every 60 seconds
|
|
279
|
+
setInterval(monitorPositions, 60000);
|
|
280
|
+
monitorPositions();
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Auto-Funding Collector
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// funding-collector.ts
|
|
287
|
+
import { AlphaFuturesClient } from '@alpha-futures/sdk';
|
|
288
|
+
|
|
289
|
+
const client = new AlphaFuturesClient({
|
|
290
|
+
network: 'mainnet',
|
|
291
|
+
privateKey: process.env.PRIVATE_KEY
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
async function collectFunding() {
|
|
295
|
+
const positions = await client.positions.getAllPositions();
|
|
296
|
+
|
|
297
|
+
for (const position of positions) {
|
|
298
|
+
const funding = await client.funding.getAccruedFunding(position.id);
|
|
299
|
+
|
|
300
|
+
if (funding > 0) {
|
|
301
|
+
await client.funding.collectFunding(position.id);
|
|
302
|
+
console.log(`Collected ${funding.toFixed(4)} TAO from position ${position.id}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Run every 8 hours
|
|
308
|
+
setInterval(collectFunding, 8 * 60 * 60 * 1000);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Need Help?
|
|
312
|
+
|
|
313
|
+
- Read the full documentation: [README.md](../README.md)
|
|
314
|
+
- Check our FAQ: [https://docs.alphafutures.io/faq](https://docs.alphafutures.io/faq)
|
|
315
|
+
- Ask in Discord: [https://discord.gg/alphafutures](https://discord.gg/alphafutures)
|
|
316
|
+
- Report issues: [GitHub Issues](https://github.com/alpha-futures/sdk/issues)
|