Last active
January 10, 2023 22:13
-
-
Save vk496/91c49a302aec615b51abac9af3b71f36 to your computer and use it in GitHub Desktop.
Trading212 portable buyer
This file contains 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
{ | |
"name": "t212buy", | |
"version": "1.0.0", | |
"description": "", | |
"main": "t212buy.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "@vk496", | |
"license": "GPLv3", | |
"dependencies": { | |
"trading212": "github:vk496/node-trading212#permanent-token", | |
"yargs": "^17.6.2" | |
} | |
} |
This file contains 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
const trading212Handler = require('trading212'); // https://github.com/vk496/node-trading212/tree/permanent-token | |
const yargs = require('yargs'); | |
const { hideBin } = require('yargs/helpers') | |
global.ARGS = yargs(hideBin(process.argv)) | |
.option('target', { | |
alias: 't', | |
description: 'Target market', | |
choices: ['demo', 'live'], | |
demandOption: true | |
}) | |
.option('login', { | |
alias: 'l', | |
description: 'Get these values from your browser cookie at [target].trading212.com (F12 -> Application -> Storage -> Cookies). LOGIN_TOKEN', | |
type: 'string', | |
demandOption: true | |
}) | |
.option('dUUID', { | |
alias: 'd', | |
description: 'Get these values from your browser cookie at [target].trading212.com (F12 -> Application -> Storage -> Cookies). First one, with random names. WITHOUT QUOTES', | |
type: 'string', | |
demandOption: true | |
}) | |
.option('bucket', { | |
alias: 'b', | |
description: 'Bucket name to buy', | |
type: 'string', | |
demandOption: true | |
}) | |
.option('amount', { | |
alias: 'a', | |
description: 'Amount to buy', | |
type: 'number', | |
demandOption: true | |
}) | |
.help() | |
.alias('help', 'h').argv; | |
const trading212 = new trading212Handler(global.ARGS.target, global.ARGS.login, global.ARGS.dUUID); | |
trading212 | |
.on('platform-subscribed', async () => { | |
// trading212.getBuckets(); | |
trading212.getBucketId(global.ARGS.bucket, bucketID => { | |
trading212.fundBucket(bucketID, global.ARGS.amount, "BY_TARGETS"); | |
}) | |
}) | |
.on('bucket-funded', (output) => { | |
console.log('Funded!:', output) | |
trading212.close() | |
console.log("Bye Bye") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make it as standalone binary with https://github.com/vercel/pkg