-
-
Notifications
You must be signed in to change notification settings - Fork 288
feat(v3.0.0): Introduce Binance WebSocket API, introduce multiplex WebSocket client, bump dependencies, remove some deprecated endpoints #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 129 commits
Commits
Show all changes
171 commits
Select commit
Hold shift + click to select a range
b946518
chore(): bump axios, jest, ts-jest and typescript versions
tiagosiebler 508dc39
chore(): bump axios, jest, ts-jest and typescript versions
tiagosiebler 632bfed
chore(): remove unnecssary tsconfig src, update example
tiagosiebler dcc299b
feat(): upgrade WsStore to latest generation. Refactor DefaultLogger.…
tiagosiebler 9b46c1a
Merge branch 'master' into wsapi
tiagosiebler 7be6bf2
feat(): prepare wskey url map
tiagosiebler 40614f7
Merge branch 'master' into wsapi
tiagosiebler 6fc641a
feat(): improve event handling for multiplex public ws
tiagosiebler 0d2c924
feat(): fix eventType extraction for new multiplex streams
tiagosiebler 610900c
feat(): migrate subscribeTo util methods to new client. Fix ws endpoi…
tiagosiebler e657741
feat(): improve emittable preparation and handling, fix beautifier bu…
tiagosiebler 722a0e1
feat(): rebrand old ws client, refactoring, fix plumbing workflows fo…
tiagosiebler bb3130f
feat(): refactor rest client cache out of ws client
tiagosiebler 1af8dd5
feat(): complete user data workflows for spot markets
tiagosiebler 3fa5145
Merge branch 'master' into wsapi
tiagosiebler 88502d8
chore(): tidying in ws client
tiagosiebler 92525d3
feat(): migrate subscribeTo methods for other existing user data streams
tiagosiebler a29225f
feat(): test and update futures and margin user data streams
tiagosiebler 53d9431
feat(): workflow & stability improvements for stream heartbeats & rec…
tiagosiebler 9362492
feat(): extract listen key management & handling into utility class
tiagosiebler ea6a63c
Merge branch 'master' into wsapi
tiagosiebler d4ea51c
feat(): integrate ed25519 auth, test wsapi workflows for spot & futur…
tiagosiebler 730fcc2
chore(v3.0.0-beta.0): publish first beta
tiagosiebler fe08fa6
chore(): fix return type wrapper
tiagosiebler 2036070
fix(): type resolver for ws order req
tiagosiebler 0b78f2b
feat(): add ws api example
tiagosiebler 2d873ac
chore(): add ed25519 example
tiagosiebler 8eeafec
feat(): added Spot Market Types
JJ-Cro 5f05323
feat(): added all spot wsapi operations except trading
JJ-Cro 9e0b24d
feat(): finished spot trading wsapi types
JJ-Cro 5cacd89
feat(): added futures market wsapi operatiosn
JJ-Cro 33a5a89
feat(): added wsapi futures trading endpoints
JJ-Cro 48bb8fe
feat(): finished usdm futures wsapi aditions
JJ-Cro 47e3c58
feat(): removed apiKey, signature, made recvwindow and timestamp opti…
JJ-Cro 0795c9d
Merge pull request #530 from JJ-Cro/wsapi-types
tiagosiebler 66e7bfd
chore(): minor updates
tiagosiebler 514372c
Merge branch 'master' into wsapi
tiagosiebler 14cb4ca
chore(): add rest-like wrapper
tiagosiebler 4939b2a
Merge branch 'master' into wsapi
tiagosiebler 90ec5b5
feat(): flesh out wsapi client
tiagosiebler a4f8f25
feat(): improve rounding example, add rounding fns as export, improve…
tiagosiebler aaed088
chore(): remove unnecessary async
tiagosiebler 9d8624a
feat(): add ws api client example
tiagosiebler f7a2ac6
feat(): add coinm ws api domains, tidying around testnet workflows, d…
tiagosiebler 42983f3
chore(): expand wskey types
tiagosiebler 3a7b276
fix(): handle potentially undefined param
tiagosiebler b679af1
feat(): added all spot and usdm wsapi endpoints
JJ-Cro 1a3046a
feat(): added coinm, cleaned types and functions for wsapi.
JJ-Cro 24c8b6d
fix(): moved back to interfaces from inline types
JJ-Cro 62f7197
fix(): moved back to interfaces from inline types for wsapi
JJ-Cro 27a8df2
chore(): updated import
JJ-Cro f7d71c9
Merge pull request #534 from JJ-Cro/WsApiEndpoints
tiagosiebler 940d48e
feat(): fix testnet suffix handling for wsapi, update type resolution…
tiagosiebler d5d6461
chore(): linter fixes
tiagosiebler 6281622
chore(): update ws api error handling
tiagosiebler 7a6831b
feat(): enforce testnet wskey if useTestnet, add basic resub user dat…
tiagosiebler 3e506d2
chore(): reduce noisy log, add minimal example
tiagosiebler 06ccb62
chore(): cleaning & text fix
tiagosiebler db6d64d
chore(): fix repo url npm warning
tiagosiebler f061970
feat(): integrate new listen key workflow, integrate new user data st…
tiagosiebler bd167e4
chore(): remove keepalive plumbing for wsapi listen key
tiagosiebler 01da34a
feat(): add user data utility method to close dedicated connection. c…
tiagosiebler a110cb5
feat(): finish testnet workflows for REST and WS
tiagosiebler 60046ab
feat(): minimal response enrichment mechanism
tiagosiebler d3d4659
feat(): improve sign workflows & rsa detection. Use node crypto by de…
tiagosiebler 9b388e6
feat(v3.0.0-beta.5): default to node crypto for sign, clean up sign w…
tiagosiebler 26b13c1
chore(): add simple testnet examples
tiagosiebler dec6be2
feat(): readme updates
tiagosiebler 3c69d3e
feat(): add missing futures ws book ticker properties
tiagosiebler 2b926d8
feat(): add http keep alive support
tiagosiebler 9f75933
chore(): simple rest example
tiagosiebler 6601e81
chore(): remove deprecated endpoints with typos in function name
tiagosiebler 9f95af6
feat(): disable heartbeats by default if ping/pong frames are not ava…
tiagosiebler 914a86f
feat(): simple example on how to unsubscribe from ws topics
tiagosiebler 68c829d
feat(): readme updates with new clients
tiagosiebler 9f2d776
chore(): readme updates
tiagosiebler 05bd08f
chore(): misc test fix
tiagosiebler 63b22f7
chore(): prevent listen key conflict in tests
tiagosiebler f7a79ae
chore(): refine candles example
tiagosiebler c59e7ed
chore(): misc cleaning
tiagosiebler da26413
feat(): update examples, update testnet links, escape new lines for s…
tiagosiebler 9bebf47
chore(): misc cleaning
tiagosiebler 40233d4
feat(): breaking change, rename `useTestnet` to `testnet` for consist…
tiagosiebler f59ed00
feat(): add TOC
tiagosiebler 97fef8d
feat(): updated examples, moved to separate directories
JJ-Cro daf67d3
chore(): accidental push
JJ-Cro 997cd6b
chore(): wrong change
JJ-Cro bab2c0e
Merge pull request #539 from JJ-Cro/wsapiJerko2
tiagosiebler af61652
chore(): move examples
tiagosiebler a83fc1e
chore(): move examples
tiagosiebler b906f17
feat(): wsapi request/response type refactoring & consistency
tiagosiebler 6a4a418
feat(): wsapi & user data docs
tiagosiebler 69c020e
Merge branch 'master' into wsapi
tiagosiebler 5fb152c
feat(): improve user data docs + example
tiagosiebler e853d3b
feat(v3.0.0-beta.6): publish beta release
tiagosiebler 38c3982
feat(3.0.0-beta.7): enable custom sign fn for REST clients
tiagosiebler 145dc74
feat(3.0.0-beta.8): fix custom sign hook, update examples
tiagosiebler 3ffd3b9
Merge branch 'master' into wsapi
tiagosiebler a75ea69
feat(v3.0.0-beta.9): pull in changes from #541
tiagosiebler 1046bb0
fix(): isWsPartialBookDepthEventFormatted type guard event recognition
tiagosiebler 7b914df
feat(): wrap emit in error handler, emit array events as before, fix …
tiagosiebler ca95fa7
chore(): testing type guards
tiagosiebler 848e2dd
chore(): disable test topic
tiagosiebler a8ccd5f
chore(): checked all ws public topics for type guards
JJ-Cro 9f2b187
chore(): tidy example again
tiagosiebler 9677208
Merge branch 'master' into wsapi
tiagosiebler 2348669
Merge branch 'wsapi' into wsapiTypeGuards
tiagosiebler 96be9c4
Merge pull request #544 from JJ-Cro/wsapiTypeGuards
tiagosiebler 21fb8e4
fix(): type guards for new multiplex subs
tiagosiebler f531179
feat(): implement per ws command sign, handle timestamp offset from a…
tiagosiebler 0813aa0
feat(): add amend keep priority wsapi, breaking change: rename amend/…
tiagosiebler 877f09d
feat(): fix user data type guards for new workflows
tiagosiebler 01fed1d
feat(): peg original request to resolved ws api response
tiagosiebler 6df4624
Merge branch 'master' into wsapi
tiagosiebler f42e2b7
chore(): skip fussy test for deprecated listen key workflow
tiagosiebler f8641bc
feat(v3.0.0-beta.10): publish next beta with timestamp & type guard f…
tiagosiebler 2582e00
chore(): clean example
tiagosiebler ff26b78
chore(): update readme
tiagosiebler 505abb0
chore(): rename file
tiagosiebler 04c2e78
chore(): rename readme
tiagosiebler 0cbbae9
chore(): update user data readme
tiagosiebler 369a46d
chore(): fix file case issue
tiagosiebler 377107c
chore(): put readme back
tiagosiebler 8ade34e
chore(): update example
tiagosiebler 16a2d0a
chore(): update example, chore(): don't warn missing beautifier key b…
tiagosiebler 25d9cdd
chore(): fix webpack config
tiagosiebler a48a5eb
chore(): minor fixes
tiagosiebler e037062
chore(): cleaning
tiagosiebler c416c92
chore(): improve example
tiagosiebler 08e6cb3
chore(): use single quotes for env doc, chore(): comment out type gua…
tiagosiebler 3ecccfa
fix(#551): resolve wsMarket with assumption on wsKey
tiagosiebler a012ab5
chore(): add link to binance docs
tiagosiebler 4f8d01a
chore(): improve ws event parsing behaviour
tiagosiebler 7afc2e5
feat(v3.0.0-beta.11): fix top-level parsing/handling/enrichment for i…
tiagosiebler e69fe25
chore(): fix test
tiagosiebler 6ec5fa2
feat(): added all examples for ws-api client for every single functio…
JJ-Cro 038138f
chore(): misc cleaning
tiagosiebler 8940f52
chore(): clean comment
tiagosiebler 14a5dc0
Merge branch 'wsapi' into wsapi_example
tiagosiebler 75ce110
chore(): update generic
JJ-Cro b28e567
Merge branch 'wsapi_example' of https://github.com/JJ-Cro/binance int…
JJ-Cro 128f574
Merge pull request #553 from JJ-Cro/wsapi_example
tiagosiebler 68142be
feat(#554): add conditional order event to beautifier
tiagosiebler 55b22e9
feat(#554): add liability change event to beautifier
tiagosiebler 767c48f
feat(v3.0.0-beta.12): add missing beautifier events, misc cleaning
tiagosiebler fc8d822
chore(): update note on ws request sign. chore(): update sample link
tiagosiebler 94a75ff
feat(): added apidoc examples and endpoint map to wsapi branch
JJ-Cro e1b089e
Merge pull request #556 from JJ-Cro/wsapi5
tiagosiebler e647d48
chore(): add clarification to listen key methods
tiagosiebler 9201e8c
add WsMessageMarkPriceUpdateEventRaw
aweiu 32f652d
Merge pull request #557 from aweiu/patch-1
tiagosiebler 030e6a4
feat(v3.0.0-beta.13): add methods to unsubscribe user data streams (c…
tiagosiebler 56ba6d7
fix(#558): remove invalid new spot order wsapi parameters
tiagosiebler 76ddd6f
fix(#560): post-close handler should purge topic state after intentio…
tiagosiebler f3a0252
feat(v3.0.0-beta.14): fix ws api spot order type & post ws-close stat…
tiagosiebler 92bcb94
fix(v3.0.0-beta.15): urlencode sign parameter to fix conflict with ed…
tiagosiebler c15a9c8
chore(): check/throw on missing credentials for wsapi auth
tiagosiebler 7538f86
feat(v3.0.0-beta.16): add flag for public wsapi commands that do not …
tiagosiebler b14e3dc
feat(): marked all public futures WSAPI methods with optional auth
JJ-Cro 97cfbd8
Merge pull request #561 from JJ-Cro/updateOptionalWSAPIFutures
tiagosiebler 2a04ed2
Merge branch 'master' into wsapi
tiagosiebler eeb4274
feat(v3.0.0-beta.17): improve handling around non-authenticated ws ap…
tiagosiebler 3f8b32e
Merge branch 'master' into wsapi
tiagosiebler 27254b7
feat(v3.0.0): Introduce Binance WebSocket API, introduce multiplex We…
tiagosiebler da57d59
Merge branch 'master' into wsapi
tiagosiebler fdf1424
fix(): prevent the keep alive flag from completely overwriting an exi…
tiagosiebler 438a3c5
feat(): add test to validate advanced https agent configuration isn't…
tiagosiebler 64059ad
chore(): update test matcher
tiagosiebler a1d2dac
chore(): added endpoint map
JJ-Cro 732c9ba
chore(): improve pinning test
tiagosiebler 0ba48ee
Merge pull request #565 from JJ-Cro/wsapiFinalRegex
tiagosiebler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,95 @@ | ||
| # Binance API - Examples | ||
|
|
||
| This folder contains ready to go examples demonstrating various aspects of this API implementation, written in typescript. | ||
| This folder contains ready to go examples demonstrating various aspects of this API implementation, written in TypeScript (but they are compatible with pure JavaScript projects). | ||
|
|
||
| Found something difficult to implement? Contribute to these examples and help others! | ||
|
|
||
| ## Getting started | ||
|
|
||
| - Clone the project (or install the module in your own project `npm install binance`). | ||
| - Edit the sample as needed (some samples require edits, e.g APi keys or import statements). | ||
| - Execute the sample using ts-node: `ts-node examples/rest-spot-public.ts`. | ||
| - Clone the project (or download it as a zip, or install the module in your own project `npm install binance`). | ||
| - Edit the sample as needed (some samples require edits, e.g API keys or import statements to import from npm, not src). | ||
| - Execute the sample using tsx: `tsx examples/REST/rest-spot-public.ts`. | ||
|
|
||
| Samples that API credentials using `process.env.APIKEY` can be spawned with environment variables. Unix/macOS example: | ||
| Samples that refer to API credentials using `process.env.API_KEY_COM` can be spawned with environment variables. Unix/macOS example: | ||
| ``` | ||
| APIKEY="apikeypastedhere" APISECRET="apisecretpastedhere" ts-node examples/ws-userdata.ts | ||
| APIKEY="apikeypastedhere" APISECRET="apisecretpastedhere" tsx examples/WebSockets/ws-userdata-listenkey.ts | ||
| ``` | ||
|
|
||
| Or edit the example directly to hardcode your API keys. | ||
|
|
||
| ## REST USDM Examples | ||
| ### WebSockets | ||
|
|
||
| All examples relating to WebSockets can be found in the [examples/WebSockets](./WebSockets/) folder. High level summary of available examples: | ||
|
|
||
| #### Consumers | ||
|
|
||
| These are purely for receiving data from Binance's WebSockets (market data, account updates, etc). | ||
|
|
||
| ##### Market Data | ||
|
|
||
| These examples demonstrate subscribing to & receiving market data from Binance's WebSockets: | ||
|
|
||
| - ws-public.ts | ||
| - Demonstration on general usage of the WebSocket client to subscribe to / unsubscribe from one or more market data topics. | ||
| - ws-public-spot-orderbook.ts | ||
| - Subscribing to orderbook events for multiple symbols in spot markets. | ||
| - ws-public-spot-trades.ts | ||
| - Subscribing to raw trades for multiple symbols in spot markets. | ||
| - ws-unsubscribe.ts | ||
| - Subscribing to a list of topics, and then unsubscribing from a few topics in that list. | ||
| - ws-public-usdm-funding.ts | ||
| - Simple example subscribing to a general topic, and how to process incoming events to only extract funding rates from those events. | ||
|
|
||
| ##### Account Data | ||
|
|
||
| These examples demonstrate receiving account update events from Binance's WebSockets: | ||
|
|
||
| - ws-userdata-listenkey.ts | ||
| - Demonstration on subscribing to various user data streams (spot, margin, futures), | ||
| - Handling incoming user data events | ||
| - Using provided type guards to determine which product group the user data event is for (spot, margin, futures, etc). | ||
| - ws-userdata-listenKey-testnet.ts | ||
| - Similar to above, but on testnet. | ||
| - ws-userdata-connection-safety.ts | ||
| - Demonstration on extra safety around the first user data stream connection. | ||
| - Note: this is overkill in most situations... | ||
|
|
||
| ##### WebSocket API | ||
|
|
||
| These examples demonstrate how to send commands using Binance's WebSocket API (e.g. submitting orders). Very similar to the REST API, but using a persisted WebSocket connection instead of HTTP requests. | ||
|
|
||
| - ws-api-client.ts | ||
| - Demonstration of using Binance's WebSocket API in Node.js/JavaScript/TypeScript, using the WebsocketAPIClient. | ||
| - This WebsocketAPIClient is very similar to a REST client, with one method per available command (endpoint) and fully typed requests & responses. | ||
| - Routing is automatically handled via the WebsocketClient, including authentication and connection persistence. Just call the functions you need - the SDK does the rest. | ||
| - From a usage perspective, it feels like a REST API - you can await responses just like a HTTP request. | ||
| - ws-api-raw-promises.ts | ||
| - More verbose usage of the WebSocket API using the `sendWSAPIRequest()` method. | ||
| - The `WebsocketAPIClient` uses this method too, so in most cases it is simple to just use the `WebsocketAPIClient` instead. | ||
| - ws-userdata-wsapi.ts | ||
| - The listenKey workflow for the user data stream is deprecated (in spot markets). | ||
| - This example demonstrates how to subscribe to the user data stream in spot markets, without a listen key, using the WebSocket API. | ||
|
|
||
| ##### Misc Workflows | ||
|
|
||
| These are miscellaneous examples that cover one or more of the above categories: | ||
|
|
||
| - ws-close.ts | ||
| - Closing the (old listen-key driven) user data stream. | ||
| - Unsubscribing from various topics. | ||
| - ws-proxy-socks.ts | ||
| - Using WebSockets over a SOCKS proxy. | ||
| - deprecated-ws-public.ts | ||
|
|
||
|
|
||
| ### REST APIs | ||
|
|
||
| All examples relating to REST APIs can be found in the [examples/REST](./REST/) folder. Most examples are named around functionality & product group. Any examples with "private" involve API calls relating to your account (such as changing settings or submitting orders, etc), | ||
|
|
||
| High level summary for some of the available examples, but check the folder for a complete list: | ||
|
|
||
| #### REST USDM Examples | ||
|
|
||
| - `rest-future-bracket-order.ts` Creates three order, entry, TP, SL and submit them all at once using `submitMultipleOrders` | ||
| - `rest-usdm-order.ts` Creates single entry, using `submitNewOrder` | ||
| - `rest-usdm-order-sl.ts` Modify current Stop Loss order(HedgeMode only) | ||
| - `rest-usdm-order-sl.ts` Modify current Stop Loss order(HedgeMode only) | ||
6 changes: 3 additions & 3 deletions
6
examples/rest-future-bracket-order.ts → examples/REST/rest-future-bracket-order.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/rest-portfoliomargin-private.ts → ...ples/REST/rest-portfoliomargin-private.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/rest-portfoliomargin-public.ts → examples/REST/rest-portfoliomargin-public.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/rest-spot-private-autoinvest.ts → ...ples/REST/rest-spot-private-autoinvest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/rest-spot-private-misc.ts → examples/REST/rest-spot-private-misc.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
examples/rest-usdm-order.ts → examples/REST/rest-usdm-order.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
examples/rest-usdm-private-get.ts → examples/REST/rest-usdm-private-get.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { USDMClient } from '../../src'; | ||
|
|
||
| const client = new USDMClient({ | ||
| testnet: true, | ||
| // keepAlive: true, | ||
| // ... any other params, | ||
| }); | ||
|
|
||
| client | ||
| .getRecentTrades({ | ||
| symbol: 'BTCUSDT', | ||
| limit: 2, | ||
| }) | ||
| .then((r) => console.log('results: ', r)) | ||
| .catch((e) => console.error('exception: ', e)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { USDMClient } from '../../src/index'; | ||
|
|
||
| // or | ||
| // import { USDMClient } from 'binance'; | ||
|
|
||
| const key = process.env.API_KEY_COM || 'APIKEY'; | ||
| const secret = process.env.API_SECRET_COM || 'APISECRET'; | ||
|
|
||
| const client = new USDMClient({ | ||
| api_secret: secret, | ||
| api_key: key, | ||
| beautifyResponses: true, | ||
| /** | ||
| * Note: testnet is NOT a good place to test strategy performance. | ||
| * | ||
| * For more information and guidance, refer to: | ||
| * https://github.com/tiagosiebler/awesome-crypto-examples/wiki/CEX-Testnets | ||
| */ | ||
| testnet: true, | ||
| }); | ||
|
|
||
| async function start() { | ||
| try { | ||
| // To open a short position - if you don't have a position yet, and your account is set to one-way mode, just place a sell order to open a short position | ||
| const result = await client.submitNewOrder({ | ||
| side: 'SELL', | ||
| symbol: 'BTCUSDT', | ||
| type: 'MARKET', | ||
| quantity: 0.001, | ||
| // newOrderRespType: 'FULL', | ||
| }); | ||
|
|
||
| console.log('market sell result: ', result); | ||
| } catch (e) { | ||
| console.error('market sell failed: ', e); | ||
| } | ||
| } | ||
|
|
||
| start(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.