Skip to content

Commit

Permalink
fix(okx): use dynamic withdraw fee (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 authored Nov 10, 2024
1 parent d3ac8c9 commit db4401a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/vendor-okx/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,8 @@ export class OkxClient {
* 限速:6 次/s
*
* 限速规则:UserID
*
* https://www.okx.com/docs-v5/zh/#funding-account-rest-api-get-currencies
*/
getAssetCurrencies = (params?: {
ccy?: string;
Expand Down
18 changes: 16 additions & 2 deletions apps/vendor-okx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ const usdtSwapProducts$ = swapInstruments$.pipe(
shareReplay(1),
);

const resOfAssetCurrencies = defer(() => client.getAssetCurrencies()).pipe(
repeat({ delay: 3600_000 }),
retry({ delay: 10_000 }),
shareReplay(1),
);

resOfAssetCurrencies.subscribe(); // make it hot

const marginInstruments$ = defer(() => client.getInstruments({ instType: 'MARGIN' })).pipe(
repeat({ delay: 3600_000 }),
retry({ delay: 10_000 }),
Expand Down Expand Up @@ -535,11 +543,17 @@ defer(async () => {
) {
return { state: 'ERROR', message: 'Amount too small' };
}
const res = await firstValueFrom(resOfAssetCurrencies);
const theRes = res.data?.find((x) => x.ccy === 'USDT' && x.chain === 'USDT-TRC20');
const _fee = theRes?.minFee;
if (!_fee) return { state: 'ERROR', message: 'Currency Info not found, cannot get fee' };
const fee = +_fee;
const amt = Math.floor(order.current_amount - fee);
const transferResult = await client.postAssetWithdrawal({
amt: `${order.current_amount! - 1}`,
amt: `${amt}`,
ccy: 'USDT',
chain: 'USDT-TRC20',
fee: '1',
fee: `${fee}`,
dest: '4', // 链上提币
toAddr: order.current_rx_address!,
});
Expand Down
10 changes: 10 additions & 0 deletions common/changes/@yuants/vendor-okx/2024-11-10-03-56.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/vendor-okx",
"comment": "use dynamic withdraw fee",
"type": "patch"
}
],
"packageName": "@yuants/vendor-okx"
}

0 comments on commit db4401a

Please sign in to comment.