Merge branch 'master' into testsUpdate

This commit is contained in:
Jerko J
2024-09-30 17:53:32 +02:00
committed by GitHub
15 changed files with 755 additions and 425 deletions

89
.github/workflows/templates-readme.yml vendored Normal file
View File

@@ -0,0 +1,89 @@
name: Update README.md templates
on:
workflow_dispatch:
permissions:
contents: write # Grant write permissions to the contents
env:
FILE_NAME: README.md
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/
cache: 'npm'
- name: Install
run: npm ci --ignore-scripts
- name: Get the current date and time
id: datetime
run: echo "BRANCH_NAME=$(date +'actions_templates_%Y_%m_%d_%H%M%S')" >> $GITHUB_ENV
- name: Create update-template.sh script
run: |
cat << 'EOF' > update-template.sh
#!/bin/bash
TEMPLATE_VALUE=$(curl -s $TEMPLATE_URL)
perl -0777 -i -pe "
my \$tag = quotemeta('<!-- template_${TEMPLATE_TAG} -->');
my \$end_tag = quotemeta('<!-- template_${TEMPLATE_TAG}_end -->');
my \$replacement = '${TEMPLATE_VALUE}';
# Match the tag, then any amount of whitespace (including newlines), then the replacement, then any amount of whitespace, then the end tag.
s/(\$tag)(\s*)(.*?)(\s*)(\$end_tag)/\$1\n\$replacement\n\$5/s;
" "$FILE_NAME"
EOF
chmod +x update-template.sh
cat update-template.sh
- name: Fetch and update RELATED PROJECTS template
run: ./update-template.sh
env:
TEMPLATE_URL: https://raw.githubusercontent.com/wiki/tiagosiebler/awesome-crypto-examples/Related-projects.md
TEMPLATE_TAG: related_projects
- name: Fetch and update CONTRIBUTIONS template
run: ./update-template.sh
env:
TEMPLATE_URL: https://raw.githubusercontent.com/wiki/tiagosiebler/awesome-crypto-examples/Contributions-%26-Thanks.md
TEMPLATE_TAG: contributions
- name: Fetch and update STAR HISTORY template
run: ./update-template.sh
env:
TEMPLATE_URL: https://raw.githubusercontent.com/wiki/tiagosiebler/awesome-crypto-examples/Star-History.md
TEMPLATE_TAG: star_history
- name: Check for changes before running linter
run: git diff
- name: Check for changes | PR URL HERE
id: commitIfChanged
run: |
npx prettier -w README.md
if git diff --quiet; then
echo "No changes to commit"
exit 0
fi
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b ${{ env.BRANCH_NAME }}
git add $FILE_NAME
git commit -m 'chore(): ${{ env.FILE_NAME }} template sections'
git push origin ${{ env.BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -43,22 +43,27 @@ Node.js & JavaScript SDK for the Bybit REST APIs and WebSockets:
- Issues? Check the [issues tab](https://github.com/tiagosiebler/bybit-api/issues).
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
<!-- template_related_projects -->
## Related projects
Check out my related JavaScript/TypeScript/Node.js projects:
- Try my REST API & WebSocket SDKs:
- [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
- [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
- [Binance Node.js SDK](https://www.npmjs.com/package/binance)
- [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
- [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
- [Kucoin-api Node.js SDK](https://www.npmjs.com/package/kucoin-api)
- [Coinbase-api Node.js SDK](https://www.npmjs.com/package/coinbase-api)
- [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
- Try my misc utilities:
- [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
- [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
- Check out my examples:
- [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
<!-- template_related_projects_end -->
## Documentation
@@ -419,11 +424,9 @@ The bundle can be found in `dist/`. Altough usage should be largely consistent,
---
## Contributions & Thanks
<!-- template_contributions -->
### Donations
#### tiagosiebler
### Contributions & Thanks
Have my projects helped you? Share the love, there are many ways you can show your thanks:
@@ -433,7 +436,14 @@ Have my projects helped you? Share the love, there are many ways you can show yo
- Or buy me all the coffee:
- ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
For more ways to give thanks & support my efforts, visit [Contributions & Thanks](https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Contributions-&-Thanks)!
<!---
old ones:
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
- BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`
- ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`
- USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa
-->
<!-- template_contributions_end -->
#### pixtron
@@ -447,6 +457,10 @@ An early generation of this library was started by @pixtron. If this library hel
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
<!-- template_star_history -->
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=tiagosiebler/bybit-api,tiagosiebler/binance,tiagosiebler/orderbooks,tiagosiebler/okx-api,tiagosiebler/bitget-api,tiagosiebler/awesome-crypto-examples,tiagosiebler/bitmart-api,tiagosiebler/gateio-api&type=Date)](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/binance&tiagosiebler/orderbooks&tiagosiebler/okx-api&tiagosiebler/bitget-api&tiagosiebler/awesome-crypto-examples&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&Date)
[![Star History Chart](https://api.star-history.com/svg?repos=tiagosiebler/bybit-api,tiagosiebler/okx-api,tiagosiebler/binance,tiagosiebler/bitget-api,tiagosiebler/bitmart-api,tiagosiebler/gateio-api,tiagosiebler/kucoin-api,tiagosiebler/coinbase-api,tiagosiebler/orderbooks,tiagosiebler/accountstate,tiagosiebler/awesome-crypto-examples&type=Date)](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/okx-api&tiagosiebler/binance&tiagosiebler/bitget-api&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&tiagosiebler/kucoin-api&tiagosiebler/coinbase-api&tiagosiebler/orderbooks&tiagosiebler/accountstate&tiagosiebler/awesome-crypto-examples&Date)
<!-- template_star_history_end -->

View File

@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.getClassicTransactionLogs({
limit: 1,
symbol: 'BTCUSD',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -7,7 +7,12 @@ const client = new RestClientV5({
});
client
.getAllCoinsBalance({ accountType: 'FUND', coin: 'USDC' })
.getCoinBalance({
accountType: 'UNIFIED',
coin: 'USDT',
toAccountType: 'FUND',
withLtvTransferSafeAmount: 1,
})
.then((response) => {
console.log(response);
})

View File

@@ -3,7 +3,7 @@ const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
// linear
client
.getInstrumentsInfo({
category: 'linear',
@@ -15,3 +15,29 @@ client
.catch((error) => {
console.error(error);
});
// option
client
.getInstrumentsInfo({
category: 'option',
symbol: 'ETH-3JAN23-1250-P',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
// spot
client
.getInstrumentsInfo({
category: 'spot',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -4,6 +4,7 @@ const client = new RestClientV5({
testnet: true,
});
// inverse
client
.getTickers({
category: 'inverse',
@@ -15,3 +16,31 @@ client
.catch((error) => {
console.error(error);
});
// option
client
.getTickers({
category: 'option',
symbol: 'BTC-30DEC22-18000-C',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
// spot
client
.getTickers({
category: 'spot',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -7,7 +7,7 @@ const client = new RestClientV5({
});
client
.deleteSubApiKey()
.getAffiliateUserInfo({ uid: '1513500' })
.then((response) => {
console.log(response);
})

View File

@@ -0,0 +1,57 @@
import { RestClientV5 } from '../src/index';
// or
// import { RestClientV5 } from 'bybit-api';
/**
* The first parameter of the REST client allows you to pass any configuration parameters supported by the SDK.
*
* These include API keys, if you wish to use private endpoints, but also expose other features such as
* setting a custom base URL (e.g. for Turkish users).
*
* Refer to the API documentation for a complete list of domains: https://bybit-exchange.github.io/docs/v5/guide#authentication
*/
const client = new RestClientV5({
/**
* You can pass a completely custom base URL,
* e.g. if you're trying to use a domain that hasn't been added yet (please let us know)
*/
// baseUrl: 'https://api5.bybit.com',
//
//
/**
*
* There are also predefined API regions, which you can easily use with the "apiRegion" property:
*
*/
//
//
// default: routes to api.bybit.com
// apiRegion: 'default',
//
//
// bytick: routes to api.bytick.com
// apiRegion: 'bytick',
//
//
// NL: routes to api.bybit.nl (for Netherland users)
// apiRegion: 'NL',
//
//
// HK: routes to api.byhkbit.com (for Hong Kong users)
// apiRegion: 'HK',
//
//
// TK: routes to api.bybit-tr.com (for Turkey users)
// apiRegion: 'TK',
});
(async () => {
try {
const time1 = await client.getServerTime();
console.log('time res: ', { time1 });
} catch (e) {
console.error('request failed: ', e);
}
})();

862
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "bybit-api",
"version": "3.10.15",
"version": "3.10.18",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@@ -1248,6 +1248,10 @@ export class RestClientV5 extends BaseRestClient {
* Use this endpoint to enable a subaccount to take part in a universal transfer.
* It is a one-time switch which, once thrown, enables a subaccount permanently.
* If not set, your subaccount cannot use universal transfers.
*
* @deprecated - You no longer need to configure transferable sub UIDs.
* Now, all sub UIDs are automatically enabled for universal transfer.
*
*/
enableUniversalTransferForSubUIDs(
subMemberIds: string[],
@@ -2031,6 +2035,7 @@ export class RestClientV5 extends BaseRestClient {
/**
* Get Margin Coin Info
* @deprecated
*/
getInstitutionalLendingMarginCoinInfo(
productId?: string,
@@ -2072,6 +2077,7 @@ export class RestClientV5 extends BaseRestClient {
/**
* Get LTV
* @deprecated
*/
getInstitutionalLendingLTV(): Promise<
APIResponseV3WithTime<{ ltvInfo: any[] }>

View File

@@ -36,10 +36,13 @@ export interface GetAllCoinsBalanceParamsV5 {
export interface GetAccountCoinBalanceParamsV5 {
memberId?: string;
toMemberId?: string;
accountType: AccountTypeV5;
coin: string;
toAccountType?: AccountTypeV5;
withBonus?: number;
withTransferSafeAmount?: 0 | 1;
withLtvTransferSafeAmount?: 0 | 1;
}
export interface GetInternalTransferParamsV5 {

View File

@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import https from 'https';
import {
APIID,
@@ -137,6 +138,16 @@ export default abstract class BaseRestClient {
},
};
// If enabled, configure a https agent with keepAlive enabled
if (this.options.keepAlive) {
// For more advanced configuration, raise an issue on GitHub or use the "networkOptions"
// parameter to define a custom httpsAgent with the desired properties
this.globalRequestOptions.httpsAgent = new https.Agent({
keepAlive: true,
keepAliveMsecs: this.options.keepAliveMsecs,
});
}
this.baseUrl = getRestBaseUrl(!!this.options.testnet, restOptions);
this.key = this.options.key;
this.secret = this.options.secret;

View File

@@ -29,6 +29,19 @@ export interface RestClientOptions {
*/
enable_time_sync?: boolean;
/**
* Enable keep alive for REST API requests (via axios).
* See: https://github.com/tiagosiebler/bybit-api/issues/368
*/
keepAlive?: boolean;
/**
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
* Only relevant if keepAlive is set to true.
* Default: 1000 (defaults comes from https agent)
*/
keepAliveMsecs?: number;
/** How often to sync time drift with bybit servers */
sync_interval_ms?: number | string;
@@ -51,6 +64,8 @@ export interface RestClientOptions {
**/
baseUrl?: string;
apiRegion?: 'default' | 'bytick' | 'NL' | 'HK' | 'TK';
/** Default: true. whether to try and post-process request exceptions. */
parse_exceptions?: boolean;
@@ -100,7 +115,13 @@ export function getRestBaseUrl(
restClientOptions: RestClientOptions,
): string {
const exchangeBaseUrls = {
livenet: 'https://api.bybit.com',
livenet: {
default: 'https://api.bybit.com',
bytick: 'https://api.bytick.com',
NL: 'https://api.bybit.nl',
HK: 'https://api.byhkbit.com',
TK: 'https://api.bybit-tr.com',
},
testnet: 'https://api-testnet.bybit.com',
demoLivenet: 'https://api-demo.bybit.com',
};
@@ -117,7 +138,19 @@ export function getRestBaseUrl(
return exchangeBaseUrls.testnet;
}
return exchangeBaseUrls.livenet;
if (restClientOptions.apiRegion) {
const regionalBaseURL =
exchangeBaseUrls.livenet[restClientOptions.apiRegion];
if (!regionalBaseURL) {
throw new Error(
`No base URL found for region "${restClientOptions.apiRegion}". Check that your "apiRegion" value is valid.`,
);
}
return regionalBaseURL;
}
return exchangeBaseUrls.livenet.default;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any