diff --git a/README.md b/README.md index 856f478..b6b0d3f 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,14 @@ [Aster Finance Spot Asset Consolidation](./consolidation.js) -# Aster 现货资产归集脚本示例 - -[Aster 现货资产归集脚本示例](./consolidation.js) +# Aster Api Key -# Aster-Broker API Key 注册 +[Aster Api Key](./aster-api-key-registration.md) -[Aster-Broker API Key 注册](./aster-broker-api-key-registration.md) +# Aster 现货资产归集脚本示例 +[Aster 现货资产归集脚本示例](./consolidation.js) +# Aster 充值提现 +[Aster Deposit and Withdrawal](./aster-deposit-withdrawal.md) diff --git a/aster-broker-api-key-registration.md b/aster-api-key-registration.md similarity index 67% rename from aster-broker-api-key-registration.md rename to aster-api-key-registration.md index ca0b3e3..c01adb6 100644 --- a/aster-broker-api-key-registration.md +++ b/aster-api-key-registration.md @@ -29,7 +29,7 @@ curl --location 'https://www.asterdex.com/bapi/futures/v1/public/future/web3/get ### message: ```text -You are signing into Aster DEX 501182 +You are signing into Astherus 501182 ``` ### result: @@ -38,7 +38,46 @@ You are signing into Aster DEX 501182 0xa4ee6b068060caeac447216b592a918b085642056248e6ff50ba22b50e8884875ead28f06cbcefcbb93d03997f807fd242354d878756f4690f791ae8dbfcde841c ``` -# 3. create api-key +# 3. login + +### request: +```shell +curl -XPOST 'https://www.asterdex.com/bapi/futures/v1/public/future/web3/ae/login' \ + + -H 'content-type: application/json' \ + --data-raw '{ + "signature":"0xafb84ca3bd36131970636a298677be2e1de4ed81b11101e417272d23f0b7f9af174efdf954ae7a63e844c83d16a4ad391e801c6766a422e647832b5c0c8aa1591c", + "sourceAddr":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "chainId":56, + "agentCode": "56789" + }' +``` + +### params: + +| param | type | required | description | +|-------------|------|----------|----------------------------------------| +| signature | string | yes | signature from previous step | +| sourceAddr | string | yes | the address used to sign the message | +| chainId | int | yes | blockchain network id, e.g. 56 for BSC | +| agentCode | string | no | referral code | + +### response: + +```json +{ + "code": "000000", + "message": null, + "messageDetail": null, + "data": { + "token": "D5M8792356G7H8J9K0L1N2B3V4C5X6Z7D5621", + "uid": 12345678 + }, + "success": true +} +``` + +# 4. create api-key ### request: diff --git a/aster-deposit-withdrawal.md b/aster-deposit-withdrawal.md new file mode 100644 index 0000000..e104b60 --- /dev/null +++ b/aster-deposit-withdrawal.md @@ -0,0 +1,356 @@ +# 1. get all deposit assets + +### request: + +```shell +curl 'https://www.asterdex.com/bapi/futures/v1/public/future/aster/deposit/assets?chainIds=56&networks=EVM&accountType=spot' +``` + +### params: +|param | type | required | description | +|-----------|--------|----------|------------------------------------------------------------------------| +| chainIds | string | true | Chain ID, multiple IDs separated by commas | +| networks | string | false | Network type, e.g., EVM, SOLANA, multiple networks separated by commas | +| accountType | string | true | Account type, e.g., spot, perp | + +### response: + +```json +{ + "code": "000000", + "message": null, + "messageDetail": null, + "data": [ + { + "name": "ASTER", + "displayName": "ASTER", + "contractAddress": "0x000ae314e2a2172a039b26378814c252734f556a", + "decimals": 18, + "network": "EVM", + "chainId": 56, + "depositType": "normal", + "rank": 10, + "isNative": false, + "admin": null, + "bank": null, + "tokenVaultAuthority": null, + "tokenVault": null, + "tokenMint": null, + "associatedTokenProgram": null, + "tokenProgram": null, + "systemProgram": null, + "ixSysvar": null, + "priceFeed": null, + "priceFeedProgram": null, + "solVault": null + } + ], + "success": true +} +``` + +# 2. get all withdraw assets + +### request: + +```shell +curl 'https://www.asterdex.com/bapi/futures/v1/public/future/aster/withdraw/assets?chainIds=56&networks=EVM&accountType=spot' +``` + +### params: +|param | type | required | description | +|-----------|--------|----------|------------------------------------------------------------------------| +| chainIds | string | true | Chain ID, multiple IDs separated by commas | +| networks | string | false | Network type, e.g., EVM, SOLANA, multiple networks separated by commas | +| accountType | string | true | Account type, e.g., spot, perp | + +### response: + +```json +{ + "code": "000000", + "message": null, + "messageDetail": null, + "data": [ + { + "name": "ASTER", + "displayName": "ASTER", + "contractAddress": "0x000ae314e2a2172a039b26378814c252734f556a", + "decimals": 18, + "network": "EVM", + "chainId": 56, + "withdrawType": "autoWithdraw", + "rank": 10, + "isNative": false, + "isProfit": true, + "admin": null, + "bank": null, + "tokenVaultAuthority": null, + "tokenVault": null, + "tokenMint": null, + "associatedTokenProgram": null, + "tokenProgram": null, + "systemProgram": null, + "ixSysvar": null, + "priceFeed": null, + "priceFeedProgram": null, + "solVault": null + } + ], + "success": true +} +``` + +# 3. estimate withdraw fee + +### request: + +```shell +curl 'https://www.asterdex.com/bapi/futures/v1/public/future/aster/estimate-withdraw-fee?chainId=56&network=EVM¤cy=ASTER&accountType=spot' +``` + +### params: + +|param | type | required | description | +|------------|--------|----------|------------------------------| +| chainId | int | true | Chain ID | +| network | string | true | Network type, e.g., EVM, SOL | +| currency | string | true | Currency name, e.g., ASTER | +| accountType | string | true | Account type, e.g., spot, perp | + +### response: + +```json +{ + "code": "000000", + "message": null, + "messageDetail": null, + "data": { + "gasPrice": null, + "gasLimit": 200000, + "nativePrice": null, + "tokenPrice": 1.12357820, + "gasCost": 0.0891, + "gasUsdValue": 0.1 + }, + "success": true +} +``` + +- gasCost: Estimated withdrawal fee in token units + +# 4. withdraw signature + +* when you withdraw, you should supply a EIP712 signature. You can get the signature by signing the following message with your wallet. + +### EIP712 Domain + +```json +{ + "name": "Aster", + "version": "1", + "chainId": 56, + "verifyingContract": "0x0000000000000000000000000000000000000000" +} +``` + +|field|desc| +|---|---| +|name|fix string 'Aster'| +|version|fix string '1'| +|chainId|the chainId of withdraw chain| +|verifyingContract|fix address: zero address| + +### EIP712 Types + +```json +{ + "Action": [ + {"name": "type", "type": "string"}, + {"name": "destination", "type": "address"}, + {"name": "destination Chain", "type": "string"}, + {"name": "token", "type": "string"}, + {"name": "amount", "type": "string"}, + {"name": "fee", "type": "string"}, + {"name": "nonce", "type": "uint256"}, + {"name": "aster chain", "type": "string"} + ] +} +``` + +|field | desc | +|---------------|-------------------------------------------------------------------------------------------------------| +|type | fix string 'Withdraw' | +|destination | the receipt address, should be user's register address | +|destination Chain | the chain name of receipt address, you can see the defination of chainName below | +|token| the name of the currency user withdraw, e.g. ASTER, you can get the name from withdraw/asset API | +|amount | the amount user withdraw in token unit, eg. '1.23' | +|fee| the fee user will pay in token unit, eg. '0.01' (you can get the fee from withdraw/estimate-withdraw-fee API) | +|nonce| a unique number, use the current timestamp in milliseconds and multiply '1000' | +|aster chain| fix string 'Mainnet' | + +### chainName definition + +|chainId| chainName | +|---|-----------| +|56| BSC | +|42161| Arbitrum | +|1| ETH | + +# 5. withdraw + +### request: + +```shell +curl -X POST "https://www.asterdex.com/bapi/futures/v1/private/future/aster/user-withdraw" -H "accept: */*" -H "x-gray-env: normal" -H "x-trace-id: fa2a5961b4a346e083f2bb0bffe39e2f" -H "Content-Type: application/json" \ +-d "{ \"accountType\": \"spot\", \"amount\": \"10.2\", \"chainId\": 97, \"currency\": \"USDT\", \"fee\": \"0.01\", \"nonce\": \"1761029928213000\", \"receiver\": \"0x4C5EdB66CC7626a1C92d5178c3E5c45409BcE6D7\", \"userSignature\": \"0xc0299efe235ec194d070163b1f92ebf5d01bd820c1c08fa9730929c7a36172a9001b99203b2f9997aa7d41b7658348704e0515f4c40e76f1892f7a5b0af31daa1c\"}" +``` + +### params: +|param | type | required | description | +|--------------|--------|----------|-----------------------------------------------------------| +| accountType | string | true | Account type, e.g., spot, perp | +| amount | string | true | Withdraw amount in token unit | +| chainId | int | true | Chain ID | +| currency | string | true | Currency name, e.g., ASTER | +| fee | string | true | Withdraw fee in token unit | +| nonce | string | true | Unique number, should be the save in signature | +| receiver | string | true | Withdraw receipt address, should be the save in signature | +| userSignature | string | true | EIP712 signature | + +### response: + +```json +{ + "code": "200", + "message": "success", + "messageDetail": null, + "data": { + "withdrawId": "1234567", + "hash": "0x9a40f0119b670fb6b155744b51981f91c4c4c8a20c333441a63853fe7d055c90" + }, + "success": true +} +``` + +|field | desc | +|-----------|--------------------------------------| +|withdrawId | the withdraw request id, a unique id | +|hash | the digest of user's signature | + +# 6. withdraw by API [futures] + +### request: + +```shell +curl --location --request POST 'https://fapi.asterdex.com/fapi/aster/user-withdraw?chainId=56&asset=USDT&amount=31&fee=0.3&receiver=0x000ae314e2a2172a039b26378814c252734f556a&nonce=1761210000000000&userSignature=0xde4ca529eef20db136eed1daf1d072083431d5279e6d6e219600cf57161c5e6d1232af3c8a8ef37ba8b5963f439ef9cc2b475fe18dcc3732dda9fb93c94a3abd1c&recvWindow=60000×tamp=1761230958410&signature=f5fd60da19be213d58914dd6f46bc400ada610fb916998dfc01dd346bfdad512' \ +--header 'Content-Type: application/json' \ +--header 'X-MBX-APIKEY: Your API KEY' +``` + +### params: +| param | type | required | description | +|---------------|--------|----------|-----------------------------------------------------------| +| amount | string | true | Withdraw amount in token unit | +| chainId | int | true | Chain ID | +| asset | string | true | Currency name, e.g., ASTER | +| fee | string | true | Withdraw fee in token unit | +| nonce | string | true | Unique number, should be the save in signature | +| receiver | string | true | Withdraw receipt address, should be the save in signature | +| userSignature | string | true | EIP712 signature | + +### response: + +```json +{ + "code": "200", + "message": "success", + "messageDetail": null, + "data": { + "withdrawId": "1234567", + "hash": "0x9a40f0119b670fb6b155744b51981f91c4c4c8a20c333441a63853fe7d055c90" + }, + "success": true +} +``` + +|field | desc | +|-----------|--------------------------------------| +|withdrawId | the withdraw request id, a unique id | +|hash | the digest of user's signature | + +# 7. withdraw by API [spot] + +### request: + +```shell +curl --location --request POST 'https://sapi.asterdex.com/api/v1/aster/user-withdraw?chainId=56&asset=ASTER&amount=1&fee=0.095&receiver=0x000ae314e2a2172a039b26378814c252734f556a&nonce=1761222960000000&userSignature=0x39051cc68de0fefb8e823259d3f7014fc787a8008b65d2a89d70defc48c3f91b35a4a819718c22ffcaeb143c8e1735621a0768d7c69e45ad8fbcf9bd315988423b&recvWindow=60000×tamp=1761230958410&signature=f5fd60da19be213d58914dd6f46bc400ada610fb916998dfc01dd346bfdad51' \ +--header 'Content-Type: application/json' \ +--header 'X-MBX-APIKEY: Your API KEY' +``` + +### params: +| param | type | required | description | +|---------------|--------|----------|-----------------------------------------------------------| +| amount | string | true | Withdraw amount in token unit | +| chainId | int | true | Chain ID | +| asset | string | true | Currency name, e.g., ASTER | +| fee | string | true | Withdraw fee in token unit | +| nonce | string | true | Unique number, should be the save in signature | +| receiver | string | true | Withdraw receipt address, should be the save in signature | +| userSignature | string | true | EIP712 signature | + +### response: + +```json +{ + "code": "200", + "message": "success", + "messageDetail": null, + "data": { + "withdrawId": "1234567", + "hash": "0x9a40f0119b670fb6b155744b51981f91c4c4c8a20c333441a63853fe7d055c90" + }, + "success": true +} +``` + +|field | desc | +|-----------|--------------------------------------| +|withdrawId | the withdraw request id, a unique id | +|hash | the digest of user's signature | + +# 8. withdraw by API [futures] + +### request: + +```shell +curl --location --request POST 'https://fapi.asterdex.com/fapi/aster/user-solana-withdraw?chainId=101&asset=USDT&amount=3&fee=0.6&receiver=4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf&recvWindow=60000×tamp=1762440135477&signature=a773a7e83c2fe4581eb2dc0500000faa3138173ba6262316c0d83b3498dea319' \ +--header 'Content-Type: application/json' \ +--header 'X-MBX-APIKEY: Your API KEY' +``` + +### params: +| param | type | required | description | +|---------------|--------|----------|-----------------------------------------------------------| +| amount | string | true | Withdraw amount in token unit | +| chainId | int | true | fix value 101 | +| asset | string | true | Currency name, e.g., USDT | +| fee | string | true | Withdraw fee in token unit | +| receiver | string | true | Withdraw receipt address, should be the save in signature | + +### response: + +```json +{ + "code": "200", + "message": "success", + "messageDetail": null, + "data": { + "withdrawId": "1234567", + "hash": "0x9a40f0119b670fb6b155744b51981f91c4c4c8a20c333441a63853fe7d055c90" + }, + "success": true +} +``` +- hash is not the transaction hash, just a unique value \ No newline at end of file diff --git a/aster-finance-futures-api-v3.md b/aster-finance-futures-api-v3.md index 98ef163..d1e49c1 100644 --- a/aster-finance-futures-api-v3.md +++ b/aster-finance-futures-api-v3.md @@ -857,7 +857,7 @@ Since `MARKET` orders have no price, the mark price is used. {} ``` -``GET /fapi/v1/ping`` +``GET /fapi/v3/ping`` Test connectivity to the Rest API. @@ -877,7 +877,7 @@ NONE } ``` -``GET /fapi/v1/time`` +``GET /fapi/v3/time`` Test connectivity to the Rest API and get the current server time. @@ -908,7 +908,7 @@ NONE "rateLimitType": "ORDERS" } ], - "serverTime": 1565613908500, // Ignore please. If you want to check current server time, please check via "GET /fapi/v1/time" + "serverTime": 1565613908500, // Ignore please. If you want to check current server time, please check via "GET /fapi/v3/time" "assets": [ // assets information { "asset": "BUSD", @@ -1008,7 +1008,7 @@ NONE } ``` -``GET /fapi/v1/exchangeInfo`` +``GET /fapi/v3/exchangeInfo`` Current exchange trading rules and symbol information @@ -1042,7 +1042,7 @@ NONE } ``` -``GET /fapi/v1/depth`` +``GET /fapi/v3/depth`` **Weight:** @@ -1079,7 +1079,7 @@ Adjusted based on the limit: ] ``` -``GET /fapi/v1/trades`` +``GET /fapi/v3/trades`` Get recent market trades @@ -1112,7 +1112,7 @@ Get recent market trades ] ``` -``GET /fapi/v1/historicalTrades`` +``GET /fapi/v3/historicalTrades`` Get older market historical trades. @@ -1147,7 +1147,7 @@ Get older market historical trades. ] ``` -``GET /fapi/v1/aggTrades`` +``GET /fapi/v3/aggTrades`` Get compressed, aggregate market trades. Market trades that fill at the time, from the same order, with the same price will have the quantity aggregated. @@ -1191,7 +1191,7 @@ Get compressed, aggregate market trades. Market trades that fill at the time, fr ] ``` -``GET /fapi/v1/klines`` +``GET /fapi/v3/klines`` Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time. @@ -1241,7 +1241,7 @@ Klines are uniquely identified by their open time. ] ``` -``GET /fapi/v1/indexPriceKlines`` +``GET /fapi/v3/indexPriceKlines`` Kline/candlestick bars for the index price of a pair. @@ -1292,7 +1292,7 @@ Klines are uniquely identified by their open time. ] ``` -``GET /fapi/v1/markPriceKlines`` +``GET /fapi/v3/markPriceKlines`` Kline/candlestick bars for the mark price of a symbol. @@ -1354,7 +1354,7 @@ Klines are uniquely identified by their open time. ] ``` -``GET /fapi/v1/premiumIndex`` +``GET /fapi/v3/premiumIndex`` Mark Price and Funding Rate @@ -1386,7 +1386,7 @@ Mark Price and Funding Rate ] ``` -``GET /fapi/v1/fundingRate`` +``GET /fapi/v3/fundingRate`` **Weight:** 1 @@ -1456,7 +1456,7 @@ Mark Price and Funding Rate ] ``` -``GET /fapi/v1/ticker/24hr`` +``GET /fapi/v3/ticker/24hr`` 24 hour rolling window price change statistics. **Careful** when accessing this with no symbol. @@ -1497,7 +1497,7 @@ Mark Price and Funding Rate ] ``` -``GET /fapi/v1/ticker/price`` +``GET /fapi/v3/ticker/price`` Latest price for a symbol or symbols. @@ -1543,7 +1543,7 @@ Latest price for a symbol or symbols. ] ``` -``GET /fapi/v1/ticker/bookTicker`` +``GET /fapi/v3/ticker/bookTicker`` Best price/qty on the order book for a symbol or symbols. @@ -2181,7 +2181,7 @@ Bids and asks, pushed every 250 milliseconds, 500 milliseconds, 100 milliseconds 1. Open a stream to **wss://fstream.asterdex.com/stream?streams=btcusdt@depth**. 2. Buffer the events you receive from the stream. For same price, latest received update covers the previous one. -3. Get a depth snapshot from **https://fapi.asterdex.com/fapi/v1/depth?symbol=BTCUSDT&limit=1000** . +3. Get a depth snapshot from **https://fapi.asterdex.com/fapi/v3/depth?symbol=BTCUSDT&limit=1000** . 4. Drop any event where `u` is < `lastUpdateId` in the snapshot. 5. The first processed event should have `U` <= `lastUpdateId` **AND** `u` >= `lastUpdateId` 6. While listening to the stream, each new event's `pu` should be equal to the previous event's `u`, otherwise initialize the process from step 3. @@ -2206,7 +2206,7 @@ Considering the possible data latency from RESTful endpoints during an extremely } ``` -``POST /fapi/v1/positionSide/dual (HMAC SHA256)`` +``POST /fapi/v3/positionSide/dual (HMAC SHA256)`` Change user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol*** @@ -2231,7 +2231,7 @@ Change user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol*** } ``` -``GET /fapi/v1/positionSide/dual (HMAC SHA256)`` +``GET /fapi/v3/positionSide/dual (HMAC SHA256)`` Get user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol*** @@ -2256,7 +2256,7 @@ Get user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol*** } ``` -``POST /fapi/v1/multiAssetsMargin (HMAC SHA256)`` +``POST /fapi/v3/multiAssetsMargin (HMAC SHA256)`` Change user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on ***Every symbol*** @@ -2281,7 +2281,7 @@ Change user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on ***E } ``` -``GET /fapi/v1/multiAssetsMargin (HMAC SHA256)`` +``GET /fapi/v3/multiAssetsMargin (HMAC SHA256)`` Get user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on ***Every symbol*** @@ -2327,7 +2327,7 @@ Get user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on ***Ever } ``` -``POST /fapi/v1/order (HMAC SHA256)`` +``POST /fapi/v3/order (HMAC SHA256)`` Send in a new order. @@ -2374,7 +2374,7 @@ Additional mandatory parameters based on `type`: * If parameter`priceProtect`is sent as true: * when price reaches the `stopPrice` ,the difference rate between "MARK_PRICE" and "CONTRACT_PRICE" cannot be larger than the "triggerProtect" of the symbol - * "triggerProtect" of a symbol can be got from `GET /fapi/v1/exchangeInfo` + * "triggerProtect" of a symbol can be got from `GET /fapi/v3/exchangeInfo` * `STOP`, `STOP_MARKET`: * BUY: latest price ("MARK_PRICE" or "CONTRACT_PRICE") >= `stopPrice` @@ -2440,7 +2440,7 @@ Additional mandatory parameters based on `type`: ] ``` -``POST /fapi/v1/batchOrders (HMAC SHA256)`` +``POST /fapi/v3/batchOrders (HMAC SHA256)`` **Weight:** 5 @@ -2545,7 +2545,7 @@ Notes: } ``` -``GET /fapi/v1/order (HMAC SHA256)`` +``GET /fapi/v3/order (HMAC SHA256)`` Check an order's status. @@ -2602,7 +2602,7 @@ Notes: } ``` -``DELETE /fapi/v1/order (HMAC SHA256)`` +``DELETE /fapi/v3/order (HMAC SHA256)`` Cancel an active order. @@ -2632,7 +2632,7 @@ Either `orderId` or `origClientOrderId` must be sent. } ``` -``DELETE /fapi/v1/allOpenOrders (HMAC SHA256)`` +``DELETE /fapi/v3/allOpenOrders (HMAC SHA256)`` **Weight:** 1 @@ -2682,7 +2682,7 @@ Either `orderId` or `origClientOrderId` must be sent. ] ``` -``DELETE /fapi/v1/batchOrders (HMAC SHA256)`` +``DELETE /fapi/v3/batchOrders (HMAC SHA256)`` **Weight:** 1 @@ -2712,7 +2712,7 @@ Either `orderIdList` or `origClientOrderIdList ` must be sent. Cancel all open orders of the specified symbol at the end of the specified countdown. -``POST /fapi/v1/countdownCancelAll (HMAC SHA256)`` +``POST /fapi/v3/countdownCancelAll (HMAC SHA256)`` **Weight:** 10 @@ -2765,7 +2765,7 @@ Cancel all open orders of the specified symbol at the end of the specified count } ``` -``GET /fapi/v1/openOrder (HMAC SHA256)`` +``GET /fapi/v3/openOrder (HMAC SHA256)`` **Weight:** 1 @@ -2816,7 +2816,7 @@ Cancel all open orders of the specified symbol at the end of the specified count ] ``` -``GET /fapi/v1/openOrders (HMAC SHA256)`` +``GET /fapi/v3/openOrders (HMAC SHA256)`` Get all open orders on a symbol. **Careful** when accessing this with no symbol. @@ -2867,7 +2867,7 @@ Get all open orders on a symbol. **Careful** when accessing this with no symbol. ] ``` -``GET /fapi/v1/allOrders (HMAC SHA256)`` +``GET /fapi/v3/allOrders (HMAC SHA256)`` Get all account orders; active, canceled, or filled. @@ -3032,7 +3032,7 @@ Get current account information. } ``` -``POST /fapi/v1/leverage (HMAC SHA256)`` +``POST /fapi/v3/leverage (HMAC SHA256)`` Change user's initial leverage of specific symbol market. @@ -3059,7 +3059,7 @@ Change user's initial leverage of specific symbol market. } ``` -``POST /fapi/v1/marginType (HMAC SHA256)`` +``POST /fapi/v3/marginType (HMAC SHA256)`` **Weight:** 1 @@ -3086,7 +3086,7 @@ Change user's initial leverage of specific symbol market. } ``` -``POST /fapi/v1/positionMargin (HMAC SHA256)`` +``POST /fapi/v3/positionMargin (HMAC SHA256)`` **Weight:** 1 @@ -3129,7 +3129,7 @@ Change user's initial leverage of specific symbol market. ] ``` -``GET /fapi/v1/positionMargin/history (HMAC SHA256)`` +``GET /fapi/v3/positionMargin/history (HMAC SHA256)`` **Weight:** 1 @@ -3252,7 +3252,7 @@ Please use with user data stream `ACCOUNT_UPDATE` to meet your timeliness and ac ] ``` -``GET /fapi/v1/userTrades (HMAC SHA256)`` +``GET /fapi/v3/userTrades (HMAC SHA256)`` Get trades for a specific account and symbol. @@ -3304,7 +3304,7 @@ Get trades for a specific account and symbol. ] ``` -``GET /fapi/v1/income (HMAC SHA256)`` +``GET /fapi/v3/income (HMAC SHA256)`` **Weight:** 30 @@ -3366,7 +3366,7 @@ Get trades for a specific account and symbol. } ``` -``GET /fapi/v1/leverageBracket`` +``GET /fapi/v3/leverageBracket`` **Weight:** 1 @@ -3407,7 +3407,7 @@ Get trades for a specific account and symbol. ] ``` -``GET /fapi/v1/adlQuantile`` +``GET /fapi/v3/adlQuantile`` **Weight:** 5 @@ -3480,7 +3480,7 @@ Get trades for a specific account and symbol. ] ``` -``GET /fapi/v1/forceOrders`` +``GET /fapi/v3/forceOrders`` **Weight:** 20 with symbol, 50 without symbol @@ -3511,7 +3511,7 @@ Get trades for a specific account and symbol. } ``` -``GET /fapi/v1/commissionRate (HMAC SHA256)`` +``GET /fapi/v3/commissionRate (HMAC SHA256)`` **Weight:** 20 @@ -3546,7 +3546,7 @@ Get trades for a specific account and symbol. } ``` -``POST /fapi/v1/listenKey`` +``POST /fapi/v3/listenKey`` Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. If the account has an active `listenKey`, that `listenKey` will be returned and its validity will be extended for 60 minutes. @@ -3565,7 +3565,7 @@ None {} ``` -``PUT /fapi/v1/listenKey`` +``PUT /fapi/v3/listenKey`` Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 60 minutes. @@ -3584,7 +3584,7 @@ None {} ``` -``DELETE /fapi/v1/listenKey`` +``DELETE /fapi/v3/listenKey`` Close out a user data stream. diff --git a/demo/create-apikey-for-others.js b/demo/create-apikey-for-others.js new file mode 100644 index 0000000..6f836dc --- /dev/null +++ b/demo/create-apikey-for-others.js @@ -0,0 +1,131 @@ +const ethers = require('ethers'); +const crypto = require('crypto'); +const axios = require('axios'); + + +//需要生成apikey的账户信息 +const new_address_config = [ + { + private_key: "*", + address: '*', + }, + { + private_key: "*", + address: '*', + } +] + +//主账户的地址 apikey api_secret +const api_key = '*' +const api_secret = '*' + + +//下面的参数无需修改 +const host = 'https://sapi.asterdex.com' + +var new_address_apikey = '' +var new_address_apiSecret = '' +var use_new_apikey = false + +const spot_get_nonce = { 'url': '/api/v1/getNonce', 'method': 'POST', 'params': { 'userOperationType': 'CREATE_API_KEY' } } +const spot_create_apikey = { 'url': '/api/v1/createApiKey', 'method': 'POST', 'params': { 'userOperationType': 'CREATE_API_KEY' } } + +async function getUrl(my_dict) { + content = '' + for (let key in my_dict) { + content = content + key + '=' + my_dict[key] + '&' + } + content += 'recvWindow=5000×tamp=' + Date.now() + + return content + +} + +async function sign_v1(secretKey, message) { + const hmac = crypto.createHmac('sha256', secretKey) + .update(message) + .digest('hex'); + return hmac +} + +async function sendRequest(url, method) { + headers = {} + key = api_key + if (use_new_apikey == true) { + key = new_address_apikey + } + if (method == 'POST') { + headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-MBX-APIKEY': key, + 'User-Agent': 'Node.js HTTP Client' + } + } + try { + const response = await axios({ + method: method, + url: url, + headers: headers + + }); + + return response.data; + } catch (error) { + console.error('Error:', error.response?.data || error.message); + } + + return '' +} + +async function send_v1(path, method, my_dict) { + content = await getUrl(my_dict) + secret = api_secret + if (use_new_apikey == true) { + secret = new_address_apiSecret + } + signature = await sign_v1(secret, content) + path = path + '?' + content + '&signature=' + signature + return await sendRequest(host + path, method) +} + + +async function send(config, addParams) { + path = config['url'] + method = config['method'] + my_dict = { ...config['params'], ...addParams } + return await send_v1(path, method, my_dict) +} + +async function sign(private_key, message) { + wallet = new ethers.Wallet(private_key); + const signature = await wallet.signMessage(message); + return signature +} + +async function main() { + i = 0 + for (const config of new_address_config) { + console.log('开始为账户创建apikey:', config.address); + //获取创建apikey的nonce + let nonce = await send(spot_get_nonce, {'address': config.address}) + + //给新地址创建api_key api_secret + message = 'You are signing into Astherus ${nonce}'.replace('${nonce}', nonce) + userSignature = await sign(config.private_key,message) + + //创建apikey时的描述信息 注意同一账户的desc不能重复 + var key_desc = Date.now() +'_' + i + i = i + 1 + let new_api = await send(spot_create_apikey, { 'userSignature': userSignature,'address': config.address,'desc': key_desc }) + new_address_apikey = new_api['apiKey'] + new_address_apiSecret = new_api['apiSecret'] + + console.log('new address: ',config.address) + console.log('new_address_apikey:', new_address_apikey) + console.log('new_address_apiSecret:', new_address_apiSecret) + } +} + + +main() + diff --git a/demo/create-apikey-front.js b/demo/create-apikey-front.js new file mode 100644 index 0000000..487b11d --- /dev/null +++ b/demo/create-apikey-front.js @@ -0,0 +1,84 @@ +const ethers = require('ethers'); +const crypto = require('crypto'); +const axios = require('axios'); + +const { Wallet } = require('ethers'); + +//下面的参数无需修改 +const host = 'https://www.asterdex.com/bapi/futures/v1' +const get_nonce = { 'url': '/public/future/web3/get-nonce', 'method': 'POST', 'params': { } } +const create_apikey = { 'url': '/public/future/web3/broker-create-api-key', 'method': 'POST', 'params': { 'network': '56','type':'CREATE_API_KEY','sourceCode':'ae','ip':'' } } +const ae_login = { 'url': '/public/future/web3/ae/login', 'method': 'POST', 'params': { 'chainId': '56' } } + +async function sendRequest(url, method,body) { + headers = {} + url = host+url + if (method == 'POST') { + headers = { + 'Content-Type': 'application/json', + 'clientType':'web' + } + } + try { + const response = await axios({ + method: method, + data: body, + url: url, + headers: headers + + }); + + return response.data; + } catch (error) { + console.error('Error:', error.response?.data || error.message); + } + + return '' +} + + +async function send(config, addParams) { + path = config['url'] + method = config['method'] + my_dict = { ...config['params'], ...addParams } + return await sendRequest(path, method, my_dict) +} + +async function sign(private_key, message) { + wallet = new ethers.Wallet(private_key); + const signature = await wallet.signMessage(message); + return signature +} + +async function main() { + const wallet = Wallet.createRandom(); + + console.log("Address:", wallet.address); + console.log("Private Key:", wallet.privateKey); + + let login_nonce_res = await send(get_nonce, {'type':'LOGIN','sourceAddr':wallet.address}) + let nonce = login_nonce_res['data']['nonce'] + console.log(nonce) + //地址登陆 header必传 'clientType':'web' + let message = 'You are signing into Astherus ${nonce}'.replace('${nonce}', nonce) + let user_signature = await sign( wallet.privateKey,message) + console.log(user_signature) + let ae_login_res = await send(ae_login, {'signature':user_signature,'sourceAddr':wallet.address,'agentCode':'69Ae1D'}) + console.log(ae_login_res) + + let apikey_nonce_res = await send(get_nonce, {'type':'CREATE_API_KEY','sourceAddr':wallet.address}) + nonce = apikey_nonce_res['data']['nonce'] + console.log(nonce) + //给新地址创建api_key api_secret + message = 'You are signing into Astherus ${nonce}'.replace('${nonce}', nonce) + user_signature = await sign( wallet.privateKey,message) + console.log(user_signature) + let create_api_key_res = await send(create_apikey, {'signature':user_signature,'desc':'12','sourceAddr':wallet.address}) + console.log(create_api_key_res) + +} + +main() + + +