-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest-future-bracket-order.ts
More file actions
75 lines (65 loc) · 1.94 KB
/
rest-future-bracket-order.ts
File metadata and controls
75 lines (65 loc) · 1.94 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {
USDMClient,
NewFuturesOrderParams
} from '../src/index';
const key = process.env.APIKEY || 'APIKEY';
const secret = process.env.APISECRET || 'APISECRET';
const client = new USDMClient({
api_key: key,
api_secret: secret,
beautifyResponses: true
});
const symbol = 'ETHUSDT';
// submit a 1:1 bracket market buy order with market entry order
(async () => {
try {
// TODO: check balance and do other validations
const assetPrices = await client.getMarkPrice({
symbol: "ETHUSDT"
})
const markPrice: number = Number(assetPrices.markPrice)
const stopLossPrice = Number(markPrice * 99.9 / 100).toFixed(2)
const takeProfitPrice = Number(markPrice * 100.1 / 100).toFixed(2)
// create three orders
// 1. entry order (GTC),
// 2. take profit order (GTE_GTC),
// 3. stop loss order (GTE_GTC)
const entryOrder: NewFuturesOrderParams<string> = {
positionSide: "BOTH",
quantity: "0.01",
reduceOnly: "false",
side: "BUY",
symbol: "ETHUSDT",
type: "MARKET",
};
const takeProfitOrder: NewFuturesOrderParams<string> = {
positionSide: "BOTH",
priceProtect: "TRUE",
quantity: "0.01",
side: "SELL",
stopPrice: takeProfitPrice,
symbol: "ETHUSDT",
timeInForce: "GTE_GTC",
type: "TAKE_PROFIT_MARKET",
workingType: "MARK_PRICE",
closePosition: "true"
};
const stopLossOrder: NewFuturesOrderParams<string> = {
positionSide: "BOTH",
priceProtect: "TRUE",
quantity: "0.01",
side: "SELL",
stopPrice: stopLossPrice,
symbol: "ETHUSDT",
timeInForce: "GTE_GTC",
type: "STOP_MARKET",
workingType: "MARK_PRICE",
closePosition: "true"
};
const openedOrder = await client.submitMultipleOrders([entryOrder, takeProfitOrder, stopLossOrder])
.catch(e => console.log(e?.body || e));
console.log(openedOrder);
} catch (e) {
console.log(e);
}
})();