|
1 | 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ |
2 | | -import { RestClient } from '../src/index'; |
3 | | -import { OrderRequest } from '../src/types/rest'; |
| 2 | +import { RestClient } from '../src/index.js'; |
| 3 | +import { OrderRequest } from '../src/types/rest/request/trade.js'; |
4 | 4 |
|
5 | 5 | // or |
6 | 6 | // import { SpotClient } from 'okx-api'; |
@@ -110,32 +110,33 @@ function roundDown(value, decimals) { |
110 | 110 |
|
111 | 111 | console.log('result: ', buyResult); |
112 | 112 | return; |
113 | | - // const symbol = 'BTCUSDT_SPBL'; |
114 | | - |
115 | | - // const symbolsResult = await client.getSymbols(); |
116 | | - // const btcRules = symbolsResult.data.find((rule) => rule.symbol === symbol); |
117 | | - // console.log('btc trading rules: ', btcRules); |
118 | | - // if (!btcRules) { |
119 | | - // return console.log('no rules found for trading ' + symbol); |
120 | | - // } |
| 113 | + // example to find minimum allowed size for a symbol and place an order with it |
| 114 | + /* const symbol = 'BTC-USDT-SWAP'; |
| 115 | +
|
| 116 | + const symbolsResult = await client.getInstruments({ |
| 117 | + instType: 'SWAP', |
| 118 | + }); |
| 119 | + const btcRules = symbolsResult.find((rule) => rule.instId === symbol); |
| 120 | + console.log('btc trading rules: ', btcRules); |
| 121 | + if (!btcRules) { |
| 122 | + return console.log('no rules found for trading ' + symbol); |
| 123 | + } |
121 | 124 |
|
122 | | - // const quantityScale = Number(btcRules.quantityScale); |
123 | | - // // const quantityRoundedDown = btcAmount - btcAmount % 0.01 |
124 | | - // const quantity = roundDown(btcAmount, quantityScale); |
| 125 | + const minSize = Number(btcRules.minSz); |
125 | 126 |
|
126 | | - // const order = { |
127 | | - // symbol: symbol, |
128 | | - // side: 'sell', |
129 | | - // force: 'normal', |
130 | | - // orderType: 'market', |
131 | | - // quantity: String(quantity), |
132 | | - // } as const; |
| 127 | + const order = { |
| 128 | + instId: symbol, |
| 129 | + tdMode: 'cross', |
| 130 | + ordType: 'market', |
| 131 | + side: 'sell', |
| 132 | + sz: String(minSize), |
| 133 | + } as const; |
133 | 134 |
|
134 | | - // console.log('submitting order: ', order); |
| 135 | + console.log('submitting order: ', order); |
135 | 136 |
|
136 | | - // const sellResult = await client.submitOrder(order); |
| 137 | + const sellResult = await client.submitOrder(order); |
137 | 138 |
|
138 | | - // console.log('sell result: ', sellResult); |
| 139 | + console.log('sell result: ', sellResult); */ |
139 | 140 | } catch (e) { |
140 | 141 | console.error('request failed: ', e); |
141 | 142 | } |
|
0 commit comments