Skip to content

Commit b6d3c98

Browse files
authored
Merge pull request sieblyio#138 from JJ-Cro/master
chore(): update old example with a working one
2 parents d057de6 + 17d9db7 commit b6d3c98

4 files changed

Lines changed: 3212 additions & 3099 deletions

File tree

examples/rest-private-trade.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* 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';
44

55
// or
66
// import { SpotClient } from 'okx-api';
@@ -110,32 +110,33 @@ function roundDown(value, decimals) {
110110

111111
console.log('result: ', buyResult);
112112
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+
}
121124
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);
125126
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;
133134
134-
// console.log('submitting order: ', order);
135+
console.log('submitting order: ', order);
135136
136-
// const sellResult = await client.submitOrder(order);
137+
const sellResult = await client.submitOrder(order);
137138
138-
// console.log('sell result: ', sellResult);
139+
console.log('sell result: ', sellResult); */
139140
} catch (e) {
140141
console.error('request failed: ', e);
141142
}

0 commit comments

Comments
 (0)