generate-private-key helper added

This commit is contained in:
fiftyeightandeight
2023-05-30 13:56:10 +08:00
parent 40c5e88c01
commit 3d67a01a04
4 changed files with 112 additions and 13 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
yarn.lock
.DS_Store
/node_modules
/.cache
package-lock.json

View File

@@ -2,13 +2,22 @@
To run b20-trading-bot, please follow the following steps:
1. [Set up the environment](#set-up-the-environment)
2. [Update the configuration file](#update-the-configuration-file)
3. [Run b20-trading-bot](#run-the-market-making-bot)
2. [Get Stacks address private key](#get-stacks-address-private-key)
3. [Update the configuration file](#update-the-configuration-file)
4. [Run b20-trading-bot](#run-the-market-making-bot)
## Set up the environment
```
> yarn add alex-stxdx-bot
> yarn install
```
## Get Stacks address private key
Bot uses your account to trade and therefore requires your private key to post orders.
```
> ts-node generate-private-key 0 "<24-word secret phrases>"
```
## Update the configuration file
Samples are available as `sample.json` or `sample-coingeckoId.json`.
@@ -39,22 +48,25 @@ See the [example](#example).
```
### Example
see [Market Information]($market-information).
```
{
"stxAddress": "<your Stacks address>",
"stxPrivateKey": "<your Stacks address private key>",
"stxDxMarket": "DB20-USD", // see [Market Information]($market-information)
"stxDxMarketPricePrecision": <decimal precision to determine minimum gap>, // see [Market Information]($market-information)
"stxDxMarketInitialPrice": <fallback price if price source permanently not available>,
"stxDxAsset": "<L2 contract name>", // see [Market Information]($market-information)
"stxDxMarket": "DB20-USD",
"stxDxMarketPricePrecision": 4, // $0.0001 is the minimum increment
"stxDxMarketInitialPrice": 1, // if price source returns 404 error, bot falls back to this
"stxDxAsset": "brc20-db20",
"gapRatio": <multiplier to minimum decimals to separate each bid/ask>,
"totalSize": <total one-side size in $>,
"gridSize": <number of bid/asks on each side>,
"gapRatio": 200, // 200 * 0.0001 = $0.02 apart between each bid and ask
"totalSize": 1000, // bid / ask sizes will target $1,000 on each side
"gridSize": 4, // 4 bids / 4 asks
"repeatIntervalInSeconds": <bid/ask refresh frequency in seconds>,
"coinGeckoId": "<CoinGecko ID>", // see [Market Information]($market-information)
"marketPriceSource": "<CoinGecko or LastTrade>"
"repeatIntervalInSeconds": 60, // the positions will be refreshed every minute
"marketPriceSource": "CoinGecko",
"coinGeckoId": "alex-db20"
}
```
@@ -62,4 +74,11 @@ See the [example](#example).
| Market | stxDxMarket | stxDxMarketPricePrecision | stxDxAsset | coinGeckoId |
| ---- | -------- | -- | ---------- | :---------- |
| $B20 | DB20-USD | 4 | brc20-db20 | alex-db20 |
| OXBT | OXBT-USD | 4 | brc20-oxbt | oxbt |
| LONG | LONG-USD | 4 | brc20-long | long-bitcoin |
| ATMT | ATMT-USD | 8 | brc20-aiptp | aiptp |
| MAXI | MAXI-USD | 3 | brc20-maxi | maxi-ordinals |
| PIZA | PIZA-USD | 3 | brc20-piza | pizabrc |
| SHNT | SHNT-USD | 3 | brc20-shnt | sats-hunters |
| DEXM | DEXM-USD | 3 | brc20-dexm | N/A |

57
generate-private-key.ts Normal file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env ts-node
// These are helper scripts to make development a little bit easier.
import { ChainID, TransactionVersion } from '@stacks/common';
import { Wallet } from '@stacks/keychain';
import {
generateWallet,
restoreWalletAccounts,
getStxAddress,
} from '@stacks/wallet-sdk';
import { StacksMocknet, StacksMainnet } from '@stacks/network';
import { pubKeyfromPrivKey } from '@stacks/transactions';
if (process.argv.length !== 4) {
console.log(`Usage: ts-node generate-private-key "<index>" "<seed phrase>"`);
process.exit(0);
}
const index = Number(process.argv[2]);
generateWallet({
secretKey: process.argv[3],
password: 'test',
}).then(wallet => {
restoreWalletAccounts({
wallet: wallet,
gaiaHubUrl: 'https://hub.blockstack.org',
network: new StacksMainnet(),
}).then(restored => {
console.log('Seed phrase: ' + process.argv[3]);
console.log('private key: ' + restored.accounts[index].stxPrivateKey);
console.log(
'Mainnet address: ' +
getStxAddress({
account: restored.accounts[index],
transactionVersion: TransactionVersion.Mainnet,
}),
);
console.log(
'Testnet address: ' +
getStxAddress({
account: restored.accounts[index],
transactionVersion: TransactionVersion.Testnet,
}),
);
const pubkey = pubKeyfromPrivKey(
restored.accounts[index].stxPrivateKey,
).data;
console.log(
'Public key: ' +
Buffer.from(pubkey, pubkey.byteOffset, pubkey.byteLength).toString(
'hex',
),
);
});
});

18
package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "b20-trading-bot",
"version": "0.0.1",
"description": "simple trading bot for b20",
"main": "index.js",
"repository": "https://github.com/alexgo-io/b20-trading-bot.git",
"author": "fiftyeightandeight <alexd@alexgo.io>",
"license": "MIT",
"dependencies": {
"@stacks/common": "^6.5.2",
"@stacks/keychain": "^4.3.8",
"@stacks/network": "^6.5.4",
"@stacks/transactions": "^6.5.4",
"@stacks/wallet-sdk": "^6.5.4",
"alex-stxdx-bot": "^0.0.9",
"ts-node": "^10.9.1"
}
}