bitget-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2022 Tiago Siebler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ # bitget-api
2
+ [![Tests](https://circleci.com/gh/tiagosiebler/bitget-api.svg?style=shield)](https://circleci.com/gh/tiagosiebler/bitget-api)
3
+ [![npm version](https://img.shields.io/npm/v/bitget-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/bitget-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/bitget-api)][1]
4
+ [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/bitget-api)][1]
5
+ [![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api)
6
+
7
+ [1]: https://www.npmjs.com/package/bitget-api
8
+
9
+ WARNING: This package is still early beta, following the designs of my other connectors. If you want to stay informed when this may be ready for testing, please get in touch via telegram.
10
+
11
+ Node.js connector for the bitget APIs and WebSockets, with TypeScript & browser support.
12
+
13
+ ## Installation
14
+ `npm install --save bitget-api`
15
+
16
+ ## Issues & Discussion
17
+ - Issues? Check the [issues tab](https://github.com/tiagosiebler/bitget-api/issues).
18
+ - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
19
+
20
+ ## Documentation
21
+ Most methods accept JS objects. These can be populated using parameters specified by bitget's API documentation.
22
+ - [bitget API Documentation](https://www.bitget.com/docs-v5/en/#rest-api).
23
+
24
+ ## Structure
25
+ This project uses typescript. Resources are stored in 3 key structures:
26
+ - [src](./src) - the whole connector written in typescript
27
+ - [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
28
+ - [dist](./dist) - the packed bundle of the project for use in browser environments.
29
+ - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
30
+
31
+ ---
32
+
33
+ # Usage
34
+ Create API credentials at bitget
35
+ - [bitget my-api](https://www.bitget.com/account/my-api)
36
+
37
+ <!--
38
+ ### REST Inverse
39
+ To use the inverse REST APIs, import the `InverseClient`:
40
+
41
+ ```javascript
42
+ const { InverseClient } = require('bitget-api');
43
+
44
+ const restClientOptions = {
45
+ // override the max size of the request window (in ms)
46
+ recv_window?: number;
47
+
48
+ // how often to sync time drift with bitget servers
49
+ sync_interval_ms?: number | string;
50
+
51
+ // Default: false. Disable above sync mechanism if true.
52
+ disable_time_sync?: boolean;
53
+
54
+ // Default: false. If true, we'll throw errors if any params are undefined
55
+ strict_param_validation?: boolean;
56
+
57
+ // Optionally override API protocol + domain
58
+ // e.g 'https://api.bytick.com'
59
+ baseUrl?: string;
60
+
61
+ // Default: true. whether to try and post-process request exceptions.
62
+ parse_exceptions?: boolean;
63
+ };
64
+
65
+ const API_KEY = 'xxx';
66
+ const PRIVATE_KEY = 'yyy';
67
+ const useLivenet = false;
68
+
69
+ const client = new InverseClient(
70
+ API_KEY,
71
+ PRIVATE_KEY,
72
+
73
+ // optional, uses testnet by default. Set to 'true' to use livenet.
74
+ useLivenet,
75
+
76
+ // restClientOptions,
77
+ // requestLibraryOptions
78
+ );
79
+
80
+ client.getApiKeyInfo()
81
+ .then(result => {
82
+ console.log("apiKey result: ", result);
83
+ })
84
+ .catch(err => {
85
+ console.error("apiKey error: ", err);
86
+ });
87
+
88
+ client.getOrderBook({ symbol: 'BTCUSD' })
89
+ .then(result => {
90
+ console.log("getOrderBook inverse result: ", result);
91
+ })
92
+ .catch(err => {
93
+ console.error("getOrderBook inverse error: ", err);
94
+ });
95
+ ```
96
+
97
+
98
+ See [inverse-client.ts](./src/inverse-client.ts) for further information. -->
99
+
100
+ ## WebSockets
101
+ Inverse, linear & spot WebSockets can be used via a shared `WebsocketClient`. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
102
+
103
+ ```javascript
104
+ const { WebsocketClient } = require('bitget-api');
105
+
106
+ const API_KEY = 'xxx';
107
+ const PRIVATE_KEY = 'yyy';
108
+
109
+ const wsConfig = {
110
+ key: API_KEY,
111
+ secret: PRIVATE_KEY,
112
+
113
+ /*
114
+ The following parameters are optional:
115
+ */
116
+
117
+ // defaults to false == testnet. Set to true for livenet.
118
+ // livenet: true
119
+
120
+ // NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
121
+
122
+ // defaults to inverse:
123
+ // market: 'inverse'
124
+ // market: 'linear'
125
+ // market: 'spot'
126
+
127
+ // how long to wait (in ms) before deciding the connection should be terminated & reconnected
128
+ // pongTimeout: 1000,
129
+
130
+ // how often to check (in ms) that WS connection is still alive
131
+ // pingInterval: 10000,
132
+
133
+ // how long to wait before attempting to reconnect (in ms) after connection is closed
134
+ // reconnectTimeout: 500,
135
+
136
+ // config options sent to RestClient (used for time sync). See RestClient docs.
137
+ // restOptions: { },
138
+
139
+ // config for axios used for HTTP requests. E.g for proxy support
140
+ // requestOptions: { }
141
+
142
+ // override which URL to use for websocket connections
143
+ // wsUrl: 'wss://stream.bytick.com/realtime'
144
+ };
145
+
146
+ const ws = new WebsocketClient(wsConfig);
147
+
148
+ // subscribe to multiple topics at once
149
+ ws.subscribe(['position', 'execution', 'trade']);
150
+
151
+ // and/or subscribe to individual topics on demand
152
+ ws.subscribe('kline.BTCUSD.1m');
153
+
154
+ // Listen to events coming from websockets. This is the primary data source
155
+ ws.on('update', data => {
156
+ console.log('update', data);
157
+ });
158
+
159
+ // Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)
160
+ ws.on('open', ({ wsKey, event }) => {
161
+ console.log('connection open for websocket with ID: ' + wsKey);
162
+ });
163
+
164
+ // Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic)
165
+ ws.on('response', response => {
166
+ console.log('response', response);
167
+ });
168
+
169
+ // Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected.
170
+ ws.on('close', () => {
171
+ console.log('connection closed');
172
+ });
173
+
174
+ // Optional: Listen to raw error events.
175
+ // Note: responses to invalid topics are currently only sent in the "response" event.
176
+ ws.on('error', err => {
177
+ console.error('ERR', err);
178
+ });
179
+ ```
180
+
181
+
182
+ See [websocket-client.ts](./src/websocket-client.ts) for further information.
183
+
184
+ Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient.
185
+
186
+ ---
187
+
188
+ ## Customise Logging
189
+ Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
190
+
191
+ ```javascript
192
+ const { WebsocketClient, DefaultLogger } = require('bitget-api');
193
+
194
+ // Disable all logging on the silly level
195
+ DefaultLogger.silly = () => {};
196
+
197
+ const ws = new WebsocketClient(
198
+ { key: 'xxx', secret: 'yyy' },
199
+ DefaultLogger
200
+ );
201
+ ```
202
+
203
+ ## Browser Usage
204
+ Build a bundle using webpack:
205
+ - `npm install`
206
+ - `npm build`
207
+ - `npm pack`
208
+
209
+ The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
210
+
211
+ ---
212
+
213
+ ## Contributions & Thanks
214
+ ### Donations
215
+ #### tiagosiebler
216
+ Support my efforts to make algo trading accessible to all - register with my referral links:
217
+ - [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
218
+ - [Binance](https://www.binance.com/en/register?ref=20983262)
219
+ - [bitget](https://www.bitget.com/join/18504944)
220
+ - [FTX](https://ftx.com/referrals#a=ftxapigithub)
221
+
222
+ Or buy me a coffee using any of these:
223
+ - BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
224
+ - ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
225
+
226
+ ### Contributions & Pull Requests
227
+ Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('lib/index');
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const HELLO = "HELLO";
package/lib/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // export * from './inverse-client';
3
+ // export * from './inverse-futures-client';
4
+ // export * from './linear-client';
5
+ // export * from './spot-client';
6
+ // export * from './websocket-client';
7
+ // export * from './logger';
8
+ // export * from './types/shared';
9
+ // export * from './types/spot';
10
+ // export * from './util/WsStore';
11
+ // export * from './constants/enum';
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.HELLO = void 0;
14
+ // Package under development
15
+ exports.HELLO = 'HELLO';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;AACpC,4CAA4C;AAC5C,mCAAmC;AACnC,iCAAiC;AACjC,sCAAsC;AACtC,4BAA4B;AAC5B,kCAAkC;AAClC,gCAAgC;AAChC,kCAAkC;AAClC,oCAAoC;;;AAEpC,4BAA4B;AACf,QAAA,KAAK,GAAG,OAAO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "bitget-api",
3
+ "version": "0.0.1",
4
+ "description": "EARLY BETA. Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & integration tests.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/*",
9
+ "index.js"
10
+ ],
11
+ "scripts": {
12
+ "test": "jest",
13
+ "test:watch": "jest --watch",
14
+ "clean": "rm -rf lib dist",
15
+ "build": "tsc",
16
+ "build:clean": "npm run clean && npm run build",
17
+ "build:watch": "npm run clean && tsc --watch",
18
+ "pack": "webpack --config webpack/webpack.config.js",
19
+ "prepublish": "npm run build:clean",
20
+ "betapublish": "npm publish --tag beta"
21
+ },
22
+ "author": "Tiago Siebler (https://github.com/tiagosiebler)",
23
+ "contributors": [],
24
+ "dependencies": {
25
+ "axios": "^0.21.0",
26
+ "isomorphic-ws": "^4.0.1",
27
+ "ws": "^7.4.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/jest": "^26.0.23",
31
+ "@types/node": "^14.14.7",
32
+ "eslint": "^7.10.0",
33
+ "jest": "^27.0.4",
34
+ "source-map-loader": "^2.0.0",
35
+ "ts-jest": "^27.0.3",
36
+ "ts-loader": "^8.0.11",
37
+ "typescript": "^4.0.5",
38
+ "webpack": "^5.4.0",
39
+ "webpack-bundle-analyzer": "^4.1.0",
40
+ "webpack-cli": "^4.2.0"
41
+ },
42
+ "keywords": [
43
+ "bitget",
44
+ "bitget api",
45
+ "okex",
46
+ "okex api",
47
+ "api",
48
+ "websocket",
49
+ "rest",
50
+ "rest api",
51
+ "usdt",
52
+ "trading bots",
53
+ "nodejs",
54
+ "node",
55
+ "trading",
56
+ "cryptocurrency",
57
+ "bitcoin",
58
+ "best"
59
+ ],
60
+ "funding": {
61
+ "type": "individual",
62
+ "url": "https://github.com/sponsors/tiagosiebler"
63
+ },
64
+ "license": "MIT",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "https://github.com/tiagosiebler/bitget-api"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/tiagosiebler/bitget-api/issues"
71
+ },
72
+ "homepage": "https://github.com/tiagosiebler/bitget-api#readme"
73
+ }