-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-batch-orders.ts
More file actions
56 lines (50 loc) · 1.73 KB
/
Copy path05-batch-orders.ts
File metadata and controls
56 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* 05 — Batch create / edit / delete orders
*
* Delta India batch endpoints take `product_id` at the top level and a flat
* `orders[]` payload — they reject `product_id` per child order.
*
* Authenticated. Run: npx tsx examples/05-batch-orders.ts
*/
import { DeltaClient, num } from '../src/index.js';
async function main() {
const client = new DeltaClient({
testnet: true,
apiKey: process.env.DELTA_API_KEY,
apiSecret: process.env.DELTA_API_SECRET,
});
try {
const product = await client.products.getBySymbol('BTCUSD');
const ticker = await client.products.ticker('BTCUSD');
const mark = num(ticker.mark_price);
// Place a 3-rung ladder of buy limits below mark
const created = await client.orders.batchCreate({
product_id: product.id,
orders: [
{ size: '1', side: 'buy', order_type: 'limit_order', limit_price: (mark * 0.97).toFixed(0) },
{ size: '1', side: 'buy', order_type: 'limit_order', limit_price: (mark * 0.95).toFixed(0) },
{ size: '1', side: 'buy', order_type: 'limit_order', limit_price: (mark * 0.93).toFixed(0) },
],
});
console.log(`Created ${created.length} orders`);
// Edit all three rungs at once (move them tighter)
await client.orders.batchEdit({
product_id: product.id,
orders: created.map((o, i) => ({
id: o.id,
product_id: product.id,
limit_price: (mark * (0.98 - 0.01 * i)).toFixed(0),
})),
});
console.log('Edited ladder');
// Cancel them all
await client.orders.batchDelete({
product_id: product.id,
orders: created.map((o) => ({ id: o.id })),
});
console.log('Cancelled ladder');
} finally {
client.destroy();
}
}
main().catch(console.error);