Merge pull request #19 from tiagosiebler/plan

v1.1.2, feat(#16): add missing plan types for futures client
This commit is contained in:
Tiago
2023-08-29 11:19:06 +01:00
committed by GitHub
8 changed files with 55 additions and 19 deletions

View File

@@ -160,13 +160,43 @@ In rare situations, you may want to see the raw HTTP requets being built as well
## Browser Usage ## Browser Usage
### Import
This is the "modern" way, allowing the package to be directly imported into frontend projects with full typescript support.
1. Install these dependencies
```sh
npm install crypto-browserify stream-browserify
```
2. Add this to your `tsconfig.json`
```json
{
"compilerOptions": {
"paths": {
"crypto": [
"./node_modules/crypto-browserify"
],
"stream": [
"./node_modules/stream-browserify"
]
}
```
3. Declare this in the global context of your application (ex: in polyfills for angular)
```js
(window as any).global = window;
```
### Webpack
This is the "old" way of using this package on webpages. This will build a minified js bundle that can be pulled in using a script tag on a website.
Build a bundle using webpack: Build a bundle using webpack:
- `npm install` - `npm install`
- `npm build` - `npm build`
- `npm pack` - `npm pack`
The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO. The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO - contributions welcome.
--- ---
@@ -184,11 +214,6 @@ Support my efforts to make algo trading accessible to all - register with my ref
- [OKX](https://www.okx.com/join/18504944) - [OKX](https://www.okx.com/join/18504944)
- [FTX](https://ftx.com/referrals#a=ftxapigithub) - [FTX](https://ftx.com/referrals#a=ftxapigithub)
Or buy me a coffee using any of these:
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
- ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
### Contributions & Pull Requests ### Contributions & Pull Requests
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items. Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bitget-api", "name": "bitget-api",
"version": "1.0.3", "version": "1.1.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bitget-api", "name": "bitget-api",
"version": "1.0.3", "version": "1.1.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.27.2", "axios": "^0.27.2",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bitget-api", "name": "bitget-api",
"version": "1.1.1", "version": "1.1.2",
"description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.", "description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
@@ -42,8 +42,6 @@
"keywords": [ "keywords": [
"bitget", "bitget",
"bitget api", "bitget api",
"okex",
"okex api",
"api", "api",
"websocket", "websocket",
"rest", "rest",

View File

@@ -1,5 +1,6 @@
export const API_ERROR_CODE = { export const API_ERROR_CODE = {
SUCCESS: '00000', SUCCESS: '00000',
NO_ORDER_TO_CANCEL: '22001',
INCORRECT_PERMISSIONS: '40014', INCORRECT_PERMISSIONS: '40014',
ACCOUNT_NOT_COPY_TRADER: '40017', ACCOUNT_NOT_COPY_TRADER: '40017',
FUTURES_POSITION_DIRECTION_EMPTY: '40017', FUTURES_POSITION_DIRECTION_EMPTY: '40017',
@@ -17,4 +18,6 @@ export const API_ERROR_CODE = {
ORDER_NOT_FOUND: '43001', ORDER_NOT_FOUND: '43001',
FUTURES_ORDER_TPSL_NOT_FOUND: '43020', FUTURES_ORDER_TPSL_NOT_FOUND: '43020',
PLAN_ORDER_NOT_FOUND: '43025', PLAN_ORDER_NOT_FOUND: '43025',
QTY_LESS_THAN_MINIMUM_SPOT: '45110',
PASSPHRASE_CANNOT_BE_EMPTY: '400172',
} as const; } as const;

View File

@@ -128,7 +128,14 @@ export interface ModifyFuturesPlanOrderTPSL {
presetStopLossPrice?: string; presetStopLossPrice?: string;
} }
export type FuturesPlanType = 'profit_plan' | 'loss_plan' | 'moving_plan'; export type FuturesPlanType =
| 'profit_plan'
| 'loss_plan'
| 'normal_plan'
| 'pos_profit'
| 'pos_loss'
| 'moving_plan'
| 'track_plan';
export interface NewFuturesPlanStopOrder { export interface NewFuturesPlanStopOrder {
symbol: string; symbol: string;

View File

@@ -118,7 +118,7 @@ describe('Private Broker REST API POST Endpoints', () => {
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
code: '40017', code: API_ERROR_CODE.PASSPHRASE_CANNOT_BE_EMPTY,
}); });
} }
}); });

View File

@@ -84,7 +84,6 @@ describe('Private Futures REST API POST Endpoints', () => {
data: {}, data: {},
}); });
} catch (e) { } catch (e) {
// console.log(`submitOrder() exception: `, e.body);
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
// seems to be the new "insufficient balance" error, informed bitget on 7th feb // seems to be the new "insufficient balance" error, informed bitget on 7th feb
code: API_ERROR_CODE.QTY_GREATER_THAN_MAX_OPEN, code: API_ERROR_CODE.QTY_GREATER_THAN_MAX_OPEN,
@@ -150,8 +149,9 @@ describe('Private Futures REST API POST Endpoints', () => {
data: {}, data: {},
}); });
} catch (e) { } catch (e) {
console.error('cancelAllOrders: ', e); expect(e.body).toMatchObject({
expect(e).toBeNull(); code: API_ERROR_CODE.NO_ORDER_TO_CANCEL,
});
} }
}); });
@@ -253,6 +253,7 @@ describe('Private Futures REST API POST Endpoints', () => {
holdSide: 'long', holdSide: 'long',
planType: 'profit_plan', planType: 'profit_plan',
triggerPrice: '50', triggerPrice: '50',
triggerType: 'market_price',
}), }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
@@ -260,7 +261,7 @@ describe('Private Futures REST API POST Endpoints', () => {
}); });
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_POSITION_DIRECTION_EMPTY, code: API_ERROR_CODE.FUTURES_INSUFFICIENT_POSITION_NO_TPSL,
}); });
} }
}); });

View File

@@ -165,7 +165,7 @@ describe('Private Spot REST API POST Endpoints', () => {
}); });
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
code: API_ERROR_CODE.QTY_LESS_THAN_MINIMUM, code: API_ERROR_CODE.QTY_LESS_THAN_MINIMUM_SPOT,
}); });
} }
}); });
@@ -185,10 +185,12 @@ describe('Private Spot REST API POST Endpoints', () => {
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: { data: {
resultList: expect.any(Array), resultList: expect.any(Array),
failure: [{ errorCode: API_ERROR_CODE.QTY_LESS_THAN_MINIMUM }], failure: [{ errorCode: API_ERROR_CODE.QTY_LESS_THAN_MINIMUM_SPOT }],
}, },
}); });
} catch (e) { } catch (e) {
// console.log(`fn() exception: `, e.body);
expect(e).toBeNull(); expect(e).toBeNull();
} }
}); });